Unit Tests are usually organised into scenarios that test the specific behaviour of a software component. Such scenarios are usually implemented in separate executables. Each scenario is decomposed into test suites, i.e., a group of related tests verifying that the software component correctly services the current scenario. Test suites are themselves composed of at least one test case.
With TTS, this decomposition (scenario/suite/test) is supported by various macros.
Let's dive into the details of how TTS manages and reports tests.
Test cases are functions performing repeatable, minimal operations able to unambiguously capture a function or class behaviour and assess its correctness. In TTS, a test case can be defined either as:
In both cases, the test case is defined with a unique string description. Additionally, good testing practices recommend using fine-grained test cases to simplify test management.
Notice the #define TTS_MAIN line. This is used to notify TTS that the current translation unit will contain the TTS main entry point. You can use TTS in multiple translation units, but only one of them must have the TTS_MAIN macro enabled.
The unit test reports the total number of tests performed, the number of passing tests, the number of failing tests and the number of invalid tests. In this case, unsurprisingly, our empty test is reported as invalid, as we consider an empty test case as erroneous in itself. TTS enforces an Empty Suite Is An Error rule that applies at the test case level: any test case with no actual testing will be considered as a failure and reported as an invalid test.
Most of the TTS components are available as macros that perform usual test operations and report their successes or failures to the test suite manager directly from within a test case. Let's amend our initial test by adding a single call to TTS_EXPECT :
One may notice that no other information is displayed. This is the default behaviour. You can now use the various TTS testing macros to design your own unit tests.