Wiki

Clone wiki

xUnit++ / SuitesAndAttributes

Suites

Suites are a broad method of grouping your tests. All tests within a SUITE block are contained within the same C++ namespace, and can be selected based on the name of the suite using the standard test runner.

SUITE("Some Suite")
{

FACT("Some Fact")
{
}

}

Attributes

Attributes are a much more fine-grained method of grouping tests. Every test (whether within a suite or not) can be decorated with up to eight key-value pair attributes, by wrapping the test(s) in an ATTRIBUTES block:

ATTRIBUTES(("Category", "Server"))
{

FACT("Fact 1")
{
    // test some work that apparently fits in a "Server" category
}

FACT("Fact 2")
{
    // test some work that apparently fits in a "Server" category
}

}

Skipping Tests

There is one special attribute, "Skip" (capitalization required). Any tests with "Skip" as an attribute key will be ignored at run time and the attribute value will be printed as the reason for skipping the test.

ATTRIBUTES(("Skip", "Takes way too long to complete. Need to refactor"))
{

TIMED_FACT("Test name", 0)
{
    // do some long-running work that makes the test process take too long:
    std::this_thread::sleep_for(std::chrono::seconds(10));
}

}

// If the "Skip" attribute is the only attribute, then the SKIP macro can be used as a short-cut.
SKIP("Another test to skip")
{

FACT("Do nothing")
{
}

}

Importantly, skipped tests will never be instantiated, so no long-running fixture or theory setup will be run.

Updated