β˜‘οΈŽ Test suite with Coverage πŸ†•

Tests for libraries and executables are easily setup with mulle-sde. In both cases just run:

mulle-sde test init

and a basic test setup should be setup in the test folder.

Executable Test + Coverage

There are two simple principles behind mulle-sde tests.

They are:

  • a non-zero exit code means a failed test (unless a <testname>.errors file is present)
  • if a file <testname>.stdout is present, then the output of the test must match the contents of this file exactly

Setting up a test

To build the executable for testing:

mulle-sde test craft

Each test for an executable is a file named <testname>.args. Conversely each test for a C library is named <testname>.c, for an Objective-C library <testname>.m and so on.

So a test named hello.args file is found in the 10-first folder, so this will be the demo test we will run (it will fail):

mulle-sde test run

Rerun it with mulle-sde test rerun --serial, it will fail again. Provide the proper output in the .stdout and now all tests will pass.

Creating coverage information

When all tests pass, you can create coverage information:

mulle-sde test coverage

This will rebuild the project with coverage information and then all tests are run again. For a β€œhello world” executable, the output will look like this:

------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: /tmp/bbb/src
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
main.c                                         3       3   100%
------------------------------------------------------------------------------
TOTAL                                          3       3   100%
------------------------------------------------------------------------------

You can also get HTML output, check the usage of the coverage command for more info.

Final Words

mulle-test provides much more information how to setup and check tests.