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

level from class fcf::NTest::Fixture

Property: level = fcf::NTest::FL_GLOBAL

Type: fcf::NTest::EFixtureLevel

Class: fcf::NTest::Fixture

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Defines the hierarchical scope of the fixture.

The level property determines the granularity of the fixture's application within the test hierarchy. It controls how often the fixture is invoked during the test execution process.

Available levels:

    fcf::NTest::FL_GLOBAL: The fixture runs exactly once at the very beginning and once at the very end of the entire test suite.
  • fcf::NTest::FL_PART: The fixture runs for every Part that matches the specified criteria.
  • fcf::NTest::FL_GROUP: The fixture runs for every Group that matches the specified criteria.
  • fcf::NTest::FL_TEST: The fixture runs for every individual Test that matches the specified criteria.

Example: Global vs Test Level Fixtures

Comparing the behavior of a fcf::NTest::FL_GLOBAL fixture and a fcf::NTest::FL_TEST fixture.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> // Global fixture: runs once for the whole suite FCF_TEST_BEFORE_DEFINE("Suite", "*", "*", fcf::NTest::FL_GLOBAL) { fcf::NTest::log() << "--- GLOBAL START ---" << std::endl; } FCF_TEST_AFTER_DEFINE("Suite", "*", "*", fcf::NTest::FL_GLOBAL) { fcf::NTest::log() << "--- GLOBAL END ---" << std::endl; } // Test level fixture: runs for every single test FCF_TEST_BEFORE_DEFINE("Suite", "Group", "*", fcf::NTest::FL_TEST) { fcf::NTest::log() << " [Test Setup]" << std::endl; } FCF_TEST_AFTER_DEFINE("Suite", "Group", "*", fcf::NTest::FL_TEST) { fcf::NTest::log() << " [Test Teardown]" << std::endl; } FCF_TEST_DEFINE("Suite", "Group", "Test1") { FCF_TEST(true); } FCF_TEST_DEFINE("Suite", "Group", "Test2") { FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { std::vector<fcf::NTest::Fixture> fixtures = fcf::NTest::storage().fixtures(); fcf::NTest::log() << "List of registered fixtures:" << std::endl; for(fcf::NTest::Fixture& fixture : fixtures) { std::string parts; std::string groups; std::string tests; for(std::string item : fixture.parts) { parts += std::string(parts.empty() ? "" : "|") + item; }; for(std::string item : fixture.groups) { groups += std::string(groups.empty() ? "" : "|") + item; }; for(std::string item : fixture.tests) { tests += std::string(tests.empty() ? "" : "|") + item; }; fcf::NTest::log() << " Fixture: " << parts << " -> " << groups << " -> " << tests << " (level: " << fixture.level << "; before: " << fixture.before << ")" << std::endl; } bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

> List of registered fixtures: > Fixture: Suite -> * -> * (level: 0; before: 1) > Fixture: Suite -> * -> * (level: 0; before: 0) > Fixture: Suite -> Group -> * (level: 3; before: 1) > Fixture: Suite -> Group -> * (level: 3; before: 0) > --- GLOBAL START --- > [Test Setup] Performing the test: "Suite" -> "Group" -> "Test1" ... [SUCCESS] Test completed successfully (0.000`000`617 sec) > [Test Teardown] > [Test Setup] Performing the test: "Suite" -> "Group" -> "Test2" ... [SUCCESS] Test completed successfully (0.000`000`265 sec) > [Test Teardown] > --- GLOBAL END --- [SUCCESS] All tests were completed. Tests: 2 passed, 0 failed, 0 skipped, 2 total Duration: 0.000`000`882 sec