FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

tests from class fcf::NTest::Fixture

Property: tests

Type: std::vector<std::string>

Class: fcf::NTest::Fixture

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

A list of specific test names to which this fixture applies.

The tests property allows for the most granular control over fixture execution. It specifies a list of exact test identifiers that should trigger the setup and teardown logic.

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: Targeting Specific Tests

Demonstrating how to use the tests property to wrap only a specific set of tests with a fixture.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <cmath> // Fixture added by the macro FCF_TEST_BEFORE_DEFINE("MyLib", "Math", "Sin", fcf::NTest::FL_TEST) { fcf::NTest::log() << "Running Math/Sin test 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 test 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("MyLib", "Math", "Sin") { // 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("MyLib", "Math", "Cos") { // 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("MyLib"); fixture.groups.push_back("Math"); fixture.tests.push_back("Cos"); fixture.before = true; fixture.level = fcf::NTest::FL_TEST; 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 test setup... Performing the test: "MyLib" -> "Math" -> "Cos" ... [SUCCESS] Test completed successfully (0.000`001`659 sec) > Running Math/Sin test setup... Performing the test: "MyLib" -> "Math" -> "Sin" ... [SUCCESS] Test completed successfully (0.000`000`839 sec) [SUCCESS] All tests were completed. Tests: 2 passed, 0 failed, 0 skipped, 2 total Duration: 0.000`002`498 sec