Type: std::vector<std::string>
Class: fcf::NTest::Options::Selector
Package: fcfTest
File: test.hpp
Available from version: 1.1.12
A list of group names to include in the test selection.
The groups property is a collection of strings used to filter the execution of tests based on their second hierarchical level (the 'Group' level).
When configuring a fcf::NTest::Options::Selector, the following rules apply to the contents of this vector:
- If the vector is empty, no filtering by group is applied (all groups within the selected parts will be included).
- If it contains specific names, only tests belonging to those groups will be executed.
- The special string "*" or an empty string "" within the vector acts as a wildcard, selecting all elements at this level.
- Multiple names in the vector are treated using the OR logic (e.g., if you provide {"GroupA", "GroupB"}, tests from either GroupA or GroupB will run).
Example: Filtering tests by specific groups
Demonstrating how to use the 'groups' vector to select only tests belonging to specific logical groups within the project.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <vector>
#include <string>
// --- Test Suite Setup ---
// Test in 'Math' part, 'Arithmetic' group
FCF_TEST_DEFINE("Math", "Arithmetic", "Addition") {
FCF_TEST(1 + 1 == 2);
}
// Test in 'Math' part, 'Geometry' group
FCF_TEST_DEFINE("Math", "Geometry", "CircleArea") {
FCF_TEST(true);
}
// Test in 'Physics' part, 'Mechanics' group
FCF_TEST_DEFINE("Physics", "Mechanics", "Gravity") {
FCF_TEST(9.8 > 0);
}
int main(int a_argc, char* a_argv[]) {
// 1. Create an instance of fcf::NTest::Options
fcf::NTest::Options options;
// 2. Create a fcf::NTest::Options::Selector
fcf::NTest::Options::Selector selector;
// 3. Set the part to 'Math' to narrow down the scope
selector.parts.push_back("Math");
// 4. Populate the groups vector
// We only want to run tests from the 'Arithmetic' group within the 'Math' part
selector.groups.push_back("Arithmetic");
// 5. Add the selector to the options
options.selectors.push_back(selector);
// 6. Run the tests
bool error = false;
fcf::NTest::run(options, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "Math" -> "Arithmetic" -> "Addition" ...
[SUCCESS] Test completed successfully (0.000`000`247 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`000`247 sec
The test runner successfully filtered the tests to only include those in the 'Arithmetic' group within the 'Math' part, skipping the 'Geometry' group.