Advanced Usages
Organizing Your Tests with Labels
For better organization, always label your test classes and functions using the TESTED_TARGETS
and TAGS
macros. These labels help identify the scope and nature of each test, simplifying filtering and debugging.
Adding Targets to Track Tested Functions
Use the TESTED_TARGETS
macro to note which functions or classes are being tested. This enables you to selectively run tests targeting specific functions, improving your workflow when debugging or modifying code.
TESTED_TARGETS(Nanoseconds Microseconds Milliseconds Seconds Minutes Hours Days Weeks Amount)
class TimeAmountsTest : public el::UnitTest {
public:
// ...
TESTED_TARGETS(Nanoseconds)
void testNanoseconds() {
// ...
}
};
Purpose of Targets: Targets specify which functionality is tested by a class or function.
Selective Execution: Later, you can run only the tests targeting a specific function using command-line options.
Example: Marking Long-Running Tests
Tags can also be used to classify certain tests as long-running or resource-intensive. Combine TAGS
with SKIP_BY_DEFAULT()
to exclude such tests from default execution:
TAGS(LongRun)
SKIP_BY_DEFAULT()
void testLongComputation() {
// ...
}
This setup skips the test during regular runs but allows it to be explicitly enabled with a command-line option:
./unittest/unittest +tag:LongRun
This approach ensures efficient testing workflows by skipping unnecessary tests while retaining the flexibility to run them when needed.