Type: std::string
Class: fcf::NTest::Options::File
Package: fcfTest
File: test.hpp
Available from version: 1.1.7
Specifies the output format for a particular log file.
The format property defines the specific formatting rule to be applied when writing logs to a file. This allows the test runner to generate different types of reports (e.g., human-readable text or machine-readable XML) for different output destinations simultaneously.
Commonly used values include:
- "default": Standard text output.
- "junit": XML output compatible with the JUnit schema.
Example: Using different formats for different files
Demonstrating how to configure multiple log files where one uses the 'default' format for human reading and another uses the 'junit' format for CI/CD integration.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// A simple test to generate output
FCF_TEST_DEFINE("FormatExample", "Files", "MultiFormatTest") {
fcf::NTest::log() << "Generating multi-format logs..." << std::endl;
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
// 1. Initialize the Options object
fcf::NTest::Options options;
// 2. Create a configuration for a standard text log file
fcf::NTest::Options::File textFile;
textFile.file = "console_output.log";
textFile.format = "default";
options.files.push_back(textFile);
// 3. Create a configuration for a JUnit XML report file
fcf::NTest::Options::File junitFile;
junitFile.file = "test_report.xml";
junitFile.format = "junit";
options.files.push_back(junitFile);
// 4. Execute the tests with the configured file targets
bool error = false;
fcf::NTest::run(options, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "FormatExample" -> "Files" -> "MultiFormatTest" ...
> Generating multi-format logs...
[SUCCESS] Test completed successfully (0.000`007`736 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`007`736 sec
The test runner has successfully created 'console_output.log' with standard text and 'test_report.xml' with JUnit XML structure.
console_output.log file
Performing the test: "FormatExample" -> "Files" -> "MultiFormatTest" ...
> Generating multi-format logs...
[SUCCESS] Test completed successfully (0.000`007`736 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`007`736 sec
test_report.xml file
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failure="0" skipped="0" time="0.000007736">
<testsuite name="FormatExample/Files" tests="1" failure="0" skipped="0" time="0.000007736">
<testcase classname="FormatExample/Files" name="MultiFormatTest" time="0.000007736"/>
</testsuite>
</testsuites>