std::set<
fcf::NTest::Test>
tests()
const
Class: fcf::NTest::State
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Returns a set of all currently selected tests.
The tests method provides access to the collection of tests that have been selected for the current execution run.
When the test runner is active, this method returns a std::set containing the fcf::NTest::Test objects that satisfy the current filtering criteria (parts, groups, or specific test names) defined in the fcf::NTest::Options.
Result
std::set<fcf::NTest::Test>
- A set containing the fcf::NTest::Test objects that are part of the current test selection.
Example: Retrieving the selected tests set
Demonstrating how to retrieve the set of tests that the runner is currently scheduled to execute.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE("StateDemo", "Inspection", "GetSelectedTests") {
// 1. Access the global state
fcf::NTest::State& currentState = fcf::NTest::state();
// 2. Retrieve the set of tests selected by the runner
std::set<fcf::NTest::Test> selectedTests = currentState.tests();
// 3. Output the number of tests in the selection
fcf::NTest::log() << "Number of tests to be executed: " << selectedTests.size() << std::endl;
// 4. Iterate through the selection and print names
for (const fcf::NTest::Test& test : selectedTests) {
fcf::NTest::log() << " - " << test.test << std::endl;
}
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
// Run the tests. The selection is determined by command line arguments.
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "StateDemo" -> "Inspection" -> "GetSelectedTests" ...
> Number of tests to be executed: 1
> - GetSelectedTests
[SUCCESS] Test completed successfully (0.000`010`167 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`010`167 sec
Note that if no filters are applied via command line, this set will contain all registered tests in the system.