Type:
class fcf::NTest::Test
Package: fcfTest
File:
test.hpp
( link_to_the_text_position_in_the_file )
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
- The name of the logical grouping level (Part) to which the test belongs.
- Sets the execution priority for a specific part.
- The name of the sub-grouping level (Group) within a part.
- Sets the execution priority for a specific group.
- The unique identifier/name of the test case.
- The execution priority of the specific test case.
- 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