fcf::NTest::Test
test()
const
Class: fcf::NTest::State
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Returns the currently executing test case metadata.
The test method provides access to the metadata of the test case that is currently being executed by the test runner.
This is particularly useful when you need to inspect the context of the current execution, such as the test's part, group, or test, for advanced logging or dynamic test behavior.
Result
fcf::NTest::Test
- A copy of the fcf::NTest::Test structure representing the current test case.
Example: Accessing current test metadata
Demonstrating how to retrieve and print the name of the currently running test case using the test method.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE("MetadataDemo", "Context", "ShowTestName") {
// 1. Access the global state of the test runner
fcf::NTest::State& currentState = fcf::NTest::state();
// 2. Retrieve the metadata of the current test
fcf::NTest::Test currentTest = currentState.test();
// 3. Use the retrieved metadata (e.g., printing the test name)
fcf::NTest::log() << "Currently running test: " << currentTest.test << std::endl;
// 4. Perform a standard assertion to confirm everything is fine
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
// Run the test suite
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "MetadataDemo" -> "Context" -> "ShowTestName" ...
> Currently running test: ShowTestName
[SUCCESS] Test completed successfully (0.000`003`854 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`003`854 sec
The test method is a thread-safe way to inspect the current execution context within a test body.