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

fcf::NTest::Test class

Type:
class fcf::NTest::Test

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

A lightweight structure representing a single unit test case, containing its hierarchical metadata and execution function pointer.

The fcf::NTest::Test structure is the fundamental unit of the testing framework. It encapsulates all necessary information required to identify, sort, and execute a single test case. It stores the hierarchical identifiers (part, group, and test) along with their respective priority orders, which allows the framework to provide deterministic execution sequences. Additionally, it holds a function pointer to the actual test logic.

Properties
std::string part
- The name of the logical grouping level (Part) to which the test belongs.
void partOrder = FCF_TEST_ORDER_DEFAULT
- Sets the execution priority for a specific part.
std::string group
- The name of the sub-grouping level (Group) within a part.
void groupOrder = FCF_TEST_ORDER_DEFAULT
- Sets the execution priority for a specific group.
std::string test
- The unique identifier/name of the test case.
int testOrder = FCF_TEST_ORDER_DEFAULT
- The execution priority of the specific test case.
void (*)( ) testFunction = nullptr
- A function pointer to the actual test logic.

Example: Manual Test Object Creation

Demonstrates how a fcf::NTest::Test object is structured and how its comparison operators work, which is essential for understanding how the framework handles test sorting and selection.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> // A dummy test function to use as a pointer void my_test_function() { // Test logic would go here } FCF_TEST_DEFINE("Manual", "Demo", "TestObjectCreation") { // 1. Manually constructing a Test object // The parameters are: part, partOrder, group, groupOrder, test, testOrder, testFunction fcf::NTest::Test test1 = {"Math", 1, "Arithmetic", 1, "Addition", 1, my_test_function}; // 2. Creating another test object with different priority fcf::NTest::Test test2 = {"Math", 2, "Arithmetic", 1, "Subtraction", 1, my_test_function}; // 3. Demonstrating the comparison operator used by the framework for sorting // test1 should come before test2 because its partOrder (1) is less than test2's partOrder (2) if (test1 < test2) { fcf::NTest::log() << "Test 1 comes before Test 2 due to partOrder" << std::endl; } // 4. Verifying equality fcf::NTest::Test test1_copy = test1; FCF_TEST(test1 == test1_copy, "Test objects should be equal"); // 5. Accessing metadata fcf::NTest::log() << "Executing test: " << test1.test << std::endl; } 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:

Performing the test: "Manual" -> "Demo" -> "TestObjectCreation" ... > Test 1 comes before Test 2 due to partOrder > Executing test: Addition [SUCCESS] Test completed successfully (0.000`009`820 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`009`820 sec