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

FCF_TEST_FIXTURE_DECLARE_END macro

FCF_TEST_FIXTURE_DECLARE_END (const char* am_part, const char* am_group, const char* am_test, EFixtureLevel am_level)
FCF_TEST_FIXTURE_DECLARE_END (const char* am_part, const char* am_group, const char* am_test, EFixtureLevel am_level, TYPE am_fixtureClassName)

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Ends the declaration of a test fixture. It defines the teardown logic that runs after the fixture's scope has ended.

The FCF_TEST_FIXTURE_DECLARE_END macro is used to complete the definition of a test fixture. It provides the teardown (completion) logic that is executed once the fixture's scope is finished.

This macro must be paired with the FCF_TEST_FIXTURE_DECLARE_START macro to define a complete fixture lifecycle.

Arguments

const char* am_part
- The name of the part to which this fixture applies (must match the START macro).

const char* am_group
- The name of the group to which this fixture applies (must match the START macro).

const char* am_test
- The name of the specific test to which this fixture applies (must match the START macro).

fcf::NTest::EFixtureLevel am_level
- The scope level of the fixture (must match the START macro).

TYPE am_fixtureClassName
- [OPTIONAL] Specifies the name of the fixture class (must match the START macro). Can be used when declaring a friend class.
Detailed description

Behavior:

  1. Registers the completion handler for a previously declared fixture in the global storage.
  2. The execution timing of the code block depends on the am_level specified in the corresponding FCF_TEST_FIXTURE_DECLARE_START macro:

      fcf::NTest::FL_GLOBAL: The teardown runs once after all tests in the entire suite have finished.
    • fcf::NTest::FL_PART: The teardown runs after the last test in the specified partition has completed.
    • fcf::NTest::FL_GROUP: The teardown runs after the last test in the specified group has completed.
    • fcf::NTest::FL_TEST: The teardown runs immediately after the specific test finishes.

Example: Completing a Group Fixture

A complete example demonstrating how to use FCF_TEST_FIXTURE_DECLARE_END to clean up resources after a group of tests has finished.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> // This fixture will be held before the "Mathematics: Basics" group. FCF_TEST_FIXTURE_DECLARE_START("Math", "Basic", "*", fcf::NTest::FL_GROUP) { fcf::NTest::log() << "[FIXTURE] Setting up group environment..." << std::endl; // Perform setup logic here. Set data for tests. fcf::NTest::state().data("fixture_data", fcf::NTest::SharedPtrAny::make<int>(1)); } // This fixture will be held after the "Mathematics: Basics" group. FCF_TEST_FIXTURE_DECLARE_END("Math", "Basic", "*", fcf::NTest::FL_GROUP) { fcf::NTest::log() << "[FIXTURE] Tearing down group environment..." << std::endl; // Perform teardown logic here. fcf::NTest::state().eraseData("fixture_data"); } FCF_TEST_DECLARE("Math", "Basic", "Addition") { // Get the data set by the fixture int* fixtureData = fcf::NTest::state().data("fixture_data").cast<int>(); FCF_TEST(1 + *fixtureData == 2); } FCF_TEST_DECLARE("Math", "Basic", "Subtraction") { // Get the data set by the fixture int* fixtureData = fcf::NTest::state().data("fixture_data").cast<int>(); FCF_TEST(5 - *fixtureData == 4); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

> [FIXTURE] Setting up group environment... Performing the test: "Math" -> "Basic" -> "Addition" ... [SUCCESS] Test completed successfully (0.000`000`729 sec) Performing the test: "Math" -> "Basic" -> "Subtraction" ... [SUCCESS] Test completed successfully (0.000`000`293 sec) > [FIXTURE] Tearing down group environment... [SUCCESS] All tests were completed. Tests: 2 passed, 0 failed, 0 skipped, 2 total Duration: 0.000`001`022 sec