Type: std::string
Class: fcf::NTest::Logger::OutputTarget
Package: fcfTest
File: test.hpp
Available from version: 1.1.13
The name of the format to be used for this specific target.
The format property specifies which formatting rule should be applied to messages sent to this target. If the string is empty, the target will use the global default format set in the fcf::NTest::Logger.
Commonly used format names include:
- "default": Standard human-readable output.
- "junit": XML format compatible with JUnit.
- "": If an empty string is specified, the format specified in the current environment via fcf::NTest::Options::format or the
--test-format command-line argument is used.
Example: Using Target-Specific Formats
Demonstrating how to configure one target to use the 'junit' format while another uses the 'default' format.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
#include <fstream>
FCF_TEST_DEFINE("FormatDemo", "Logger", "MultiFormat") {
fcf::NTest::log() << "Formatting test message" << std::endl;
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
std::ofstream junitFile("results.xml");
fcf::NTest::Logger& logger = fcf::NTest::logger();
// 1. Target for Console (Default format)
fcf::NTest::Logger::OutputTarget consoleTarget;
consoleTarget.name = "console";
consoleTarget.stream = &std::cout;
consoleTarget.format = "default";
// 2. Target for File (JUnit format)
fcf::NTest::Logger::OutputTarget junitTarget;
junitTarget.name = "junit_file";
junitTarget.stream = &junitFile;
junitTarget.format = "junit";
// 3. Apply targets
logger.targets({consoleTarget, junitTarget});
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "FormatDemo" -> "Logger" -> "MultiFormat" ...
> Formatting test message
[SUCCESS] Test completed successfully (0.000`006`021 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`006`021 sec
The console shows the standard output, while results.xml contains the JUnit XML structure.
results.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failure="0" skipped="0" time="0.000006021">
<testsuite name="FormatDemo/Logger" tests="1" failure="0" skipped="0" time="0.000006021">
<testcase classname="FormatDemo/Logger" name="MultiFormat" time="0.000006021"/>
</testsuite>
</testsuites>