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

appendFixture() method from fcf::NTest::Storage class

void appendFixture(const fcf::NTest::Fixture& a_fixture)

Class: fcf::NTest::Storage

Package: fcfTest

File: test.hpp

Available from version: 1.2.2

Registers a new test fixture into the global storage.

The appendFixture method is used to add setup and teardown logic to the test suite. Fixtures can be applied at different levels of the hierarchy: Global, Part, Group, or Test.

This method is typically used via the FCF_TEST_BEFORE_DEFINE and FCF_TEST_AFTER_DEFINE macros, but it can be used manually to inject logic into the registry.

Arguments

const fcf::NTest::Fixture& a_fixture
- The fcf::NTest::Fixture object containing the setup/teardown function and its scope (level, parts, groups, etc.).

Example: Manual Fixture Registration

Demonstrating how to manually register a global setup/teardown fixture.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> void mySetup() { fcf::NTest::log() << "Manual Setup Executed" << std::endl; } FCF_TEST_DEFINE("Manual", "Demo", "Test") { FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::Storage& storage = fcf::NTest::storage(); // 1. Create a Fixture object manually fcf::NTest::Fixture manualFixture; manualFixture.parts = {"*"}; manualFixture.groups = {"*"}; manualFixture.tests = {"*"}; manualFixture.before = true; manualFixture.level = fcf::NTest::FL_GLOBAL; manualFixture.fixtureFunction = mySetup; manualFixture.file = __FILE__; manualFixture.line = 5; // 2. Append it to storage storage.appendFixture(manualFixture); // 3. Run the tests fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

> Manual Setup Executed Performing the test: "Manual" -> "Demo" -> "Test" ... [SUCCESS] Test completed successfully (0.000`000`782 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`782 sec