Clone wiki

xUnit++ / RunningTests

Running Tests

xUnit++ comes with a command line test runner that inspects your test library for tests and executes them. (Actually, it just causes your test library to execute itself.) By default, it will execute all tests in your test library concurrently, with no time limit applied.


The options are fairly self-explanatory:

-v --verboseVerbose mode: include successful test timing
-l --listDo not run tests, just list the ones that pass the filters
-s --suite <SUITE>+Suite(s) of tests to run (regex match)
-n --name <TEST>+Test(s) to run (regex match)
-i --include <NAME=[VALUE]>+Include tests with matching <name=value> attribute(s)
-e --exclude <NAME=[VALUE]>+Exclude tests with matching <name=value> attribute(s)
-t --timelimit <milliseconds>Set the default test time limit
-x --xml <FILENAME>Output Xunit-style XML file
-c --concurrent <max tests>Set maximum number of concurrent tests
-o --sortSort test output by suite, then by name
-g --groupGroup tests under suite
--no-shadowDisable shadow copying the test binaries

Inclusive attributes are applied with an OR operation. Exclusive attributes are applied with an AND operation. When an attribute VALUE is ommitted, any test with a matching attribute name NAME is matched.

Sorting and grouping test output causes test results to be cached until after all tests have completed. Normally, test results are printed as soon as the test is complete.

Example Output

Given the following file:

#include "xUnit++/xUnit++.h"

SUITE("Suite of tests")

FACT("A silent test") {}
FACT("Another test") {}

FACT("A successful test!")
    Log.Debug << "here's a log message";

FACT("Fact with some logging output and failures")
    Log.Debug << "My debugging message: " << 0xFF << " is 0xFF.";
    Log.Debug(LI) << "This message knows its line number";
    Log.Info << "My info message.";
    Log.Warn << "A warning!";

    Check.Contains("xyz", "a");
    Check.Equal(0, 1) << 0 << " is never equal to " << 1 << ".";

    Assert.Equal(0, 1) << "Really. Never.";

FACT("Fact that throws an exception")
    throw std::runtime_error("A runtime error!");

ATTRIBUTES(("Skip", "Skipping this test for now."))

FACT("A skipped test")



You will get this nicely formatted, easy-to-read output:
Example output

Visual Studio Test Adapter

You can install the xUnit++ Visual Studio Test Adapter. This will automatically discover and run your tests for you using the built-in Text Execution Window.