logo

Extending the minunit framework

Runnning all the tests

You certainly noticed that minunit exits in the first error. This is not essential, but I prefer to have my UT framework running all the tests, even in case of error: sometimes the list of failing testcases gives you a clever hint to the problem.
We can change that and add a counter for the failing tests.

New macros to enhance the failure reports

In its base version, minunit does not display the expected and actual values, just a description message. This may lead to add printf() statements to display the actual values each time we face a failing test. We will extend the assertion macros to display more useful information. The stringify preprocessor directive will allow us to display the variable names as well. We will also use the __FILE__ and __LINE__ directive to show the error location.

Setup, Teardown and Automatic creation of the test suites

C does not come with any form of reflexion so we'll rely on an external lil' script to build our test suites. This script parses the output of the nm command to extract all the tes cases (prefixed with "test_") and generate a suite for each test source file.
If setup() and teardown() functions are present, they'll be called before and after each testcase.
Then Makefile trickery allows having all this fully automated at compile time.

Using Codings standards ensures that all the test functions begin with "test_".

Parametrized test cases

To remove duplication in our testcases, we want to be able to parametrize our test cases.
This may not work with our test suite generator. One way to work around this is to make the parametrized testcases static, but this will prevent us from using setup() and teardown().


rf.eerf@sartnap:otliam - v0.02