Skip to content
Snippets Groups Projects
To learn more about this project, read the wiki.
README.md 1.29 KiB

Basic Testing Suite in C

THIS IS NOT A DIRECTORY OF TESTS. Rather, it is a library of test utility functions that you can use to write unit tests.

The functions in this library help handles the result of every test whether it be a success, failure, or segfault, and keeps running until all tests have been executed. It then gives a summary of the test results.

To use, just write your tests using functions that return ints to indicate failure. 1 means failure. 0 means success.

Then in your main function for your tests, pass these functions to the test() function along with a name you want included in the test report.

int main() {
    TEST(test_func);
    TEST(another_func);
    ...

When writing your test_func, you can use the test_assert method to perform basic assertions. If any assertion fails, then test_func will fail right away. If you have multiple assertions in a single test_func, the output will tell you specifically which assertion failed.

Then at the end of your main function, call the test_summary() function, and return its return value from your main function.

int main() {
    ...
    return test_summary();
}

An example of creating a test/ directory in your project is done in this folder. To run the unit tests in your project, run

make test