Type: std::string
Class: fcf::NTest::Fixture
Package: fcfTest
File: test.hpp
Available from version: 1.2.2
The source file where the fixture was defined.
The file property stores the absolute or relative path to the source file where the FCF_TEST_BEFORE_DEFINE or FCF_TEST_AFTER_DEFINE macro was invoked.
This information is primarily used for diagnostic purposes. If an exception occurs within the fixture's logic, the framework uses this property to report exactly where the error originated in the source code, making debugging significantly easier.
Example: Error Reporting with File Info
Explaining how the file property is used by the framework to provide accurate error locations when a fixture fails.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <stdexcept>
// This fixture will fail and throw an exception
void demoSetup() {
fcf::NTest::log() << "Initializing..." << std::endl;
throw std::runtime_error("Critical setup failure!");
}
FCF_TEST_DEFINE("ErrorDemo", "Fixture", "Test1") {
fcf::NTest::log() << "This test will not run due to fixture error." << std::endl;
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
// Manually adding a setup fixture
fcf::NTest::Fixture fixture;
fixture.parts.push_back("ErrorDemo");
fixture.groups.push_back("*");
fixture.tests.push_back("*");
fixture.before = true;
fixture.level = fcf::NTest::FL_PART;
fixture.fixtureFunction = demoSetup;
fixture.file = __FILE__;
fixture.line = 6;
fcf::NTest::storage().appendFixture(fixture);
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
> Initializing...
Performing the test: "ErrorDemo" -> "Fixture" -> "Test1" ...
Fixture error [FILE: PATH/main.cpp:6]:
Critical setup failure!
[FAILED] Test failed (0.000`000`411 sec)
[FAILED] Testing completed with failures.
Tests: 0 passed, 1 failed, 0 skipped, 1 total
Duration: 0.000`000`411 sec