-
Notifications
You must be signed in to change notification settings - Fork 4
Adding additional test parameter
A guide to add additional test parameters to the test execution (using CppUTest).
A ready-to-use C/C++ project with CppUTest configured and a test main (eg. TestMain.cpp).
The parameters (actually they are command line arguments) are put into a vector and passed to the test runner.
In a proper test main, there are already arguments: One enables the verbose output (-v) and (optional) a second one adds some color (-c).
TestMain.cpp
#include <CppUTest/CommandLineTestRunner.h>
#include <vector>
int main(int argc, char** argv)
{
std::vector<const char*> args(argv, argv + argc);
args.push_back("-v"); // Verbose output (mandatory!)
args.push_back("-c"); // Colored outupt (optional)
return CommandLineTestRunner::RunAllTests(args.size(), &args[0]);
}Further arguments are added the same way.
As an example a filter which runs only those test groups who's name matches the given group name, is configured. The argument form is: -sg <Group Name>. So a filter, executing only groups of ExampleGroup is -sg ExampleGroup.
The updated code:
// ...
std::vector<const char*> args(argv, argv + argc);
args.push_back("-v"); // Verbose output (mandatory!)
args.push_back("-c"); // Colored outupt (optional)
// Group filter
args.push_back("-sg");
args.push_back("ExampleGroup");
return CommandLineTestRunner::RunAllTests(args.size(), &args[0]);
// ...Important: The filter consists of two arguments - -sg and the name. Therefore they are added separately.