My goal was to create simple unit testing framework, possibly one header only. It should support most of usual unit testing features: tests (of course), various assertions, suites, fixtures. Also I wanted it to be as less verbose as possible in test declaration. Probably just to write TEST(test_name) { ... } to be sufficient.
The simplest unit testing could be done using just assert macros, like this:
At some point, function will grow too big to comprehend. Probably it should be divided into separated tests:
That way all tests invocations stored in one place. Disadvantages remain: function must be explicitly defined which involves lot of includes, extern defines etc. It would be nice if test runner could invoke function without even knowing its name. One way to do it is to use pointer to function. They could be stored in pointer list, which also simplifies invokation.
It would be a lot easier to add new test if appending it to the list were as closer to function declaration as possible. But in global scope, outside of all function such statement couldn’t be executed. Only definitions and declarations. So one way to get around it is to add function to the list in some variable declaration:
Almost what I wanted. Except it would be nice also see some pretty output like test name. And it could be wrapped in macro: