Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Adding additional test parameter

offa edited this page Apr 29, 2016 · 3 revisions

A guide to add additional test parameters to the test execution (using CppUTest).

1. Requirements

A ready-to-use C/C++ project with CppUTest configured and a test main (eg. TestMain.cpp).

2. Adding test parameters

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.

Clone this wiki locally