Type: std::vector<std::string>
Class: fcf::NTest::Fixture
Package: fcfTest
File:
test.hpp
( link_to_the_declaration_in_the_file )
Available from version: 1.2.1
A list of group names to which this fixture applies.
The groups property defines the scope of the fixture at the 'Group' level.
When specifying names, you can use the wildcard character "*" (or an empty vector or an empty string that will be replaced by "*" when appended) to match all parts in a particular hierarchy, or specify multiple part names to select a particular subset.
Example: Filtering by Group
Demonstrating how to use the groups property to apply a fixture only to specific groups within a part.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <cmath>
// Fixture added by the macro
FCF_TEST_BEFORE_DEFINE("Math", "Sin", "*", fcf::NTest::FL_GROUP) {
fcf::NTest::log() << "Running Math/Sin group setup..." << std::endl;
// Create user data for the test
fcf::NTest::state().data("math-sin-const", fcf::NTest::SharedPtrAny::make<float>(3.1416));
}
// Fixture handler function added manually
void manualMathCosBeforeFixture(){
fcf::NTest::log() << "Running Math/Cos group setup..." << std::endl;
// Create user data for the test
fcf::NTest::state().data("math-cos-const", fcf::NTest::SharedPtrAny::make<float>(3.1416));
}
FCF_TEST_DEFINE("Math", "Sin", "simple test") {
// Get and check user data created by the fixture
float* sinConstPtr = fcf::NTest::state().data("math-sin-const").cast<float>();
FCF_TEST(std::abs(*sinConstPtr - 3.14) < 0.1, *sinConstPtr);
}
FCF_TEST_DEFINE("Math", "Cos", "simple test") {
// Get and check user data created by the fixture
float* cosConstPtr = fcf::NTest::state().data("math-cos-const").cast<float>();
FCF_TEST(std::abs(*cosConstPtr - 3.14) < 0.1, *cosConstPtr);
}
int main(int a_argc, char* a_argv[]) {
// Manually adding a fixture
fcf::NTest::Fixture fixture;
fixture.parts.push_back("Math");
fixture.groups.push_back("Cos");
fixture.tests.push_back("*");
fixture.before = true;
fixture.level = fcf::NTest::FL_GROUP;
fixture.fixtureFunction = manualMathCosBeforeFixture;
fixture.file = __FILE__;
fixture.line = 12;
fcf::NTest::storage().appendFixture(fixture);
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
> Running Math/Cos group setup...
Performing the test: "Math" -> "Cos" -> "simple test" ...
[SUCCESS] Test completed successfully (0.000`001`550 sec)
> Running Math/Sin group setup...
Performing the test: "Math" -> "Sin" -> "simple test" ...
[SUCCESS] Test completed successfully (0.000`000`856 sec)
[SUCCESS] All tests were completed.
Tests: 2 passed, 0 failed, 0 skipped, 2 total
Duration: 0.000`002`406 sec