Play-/tools/AutoTest/JUnitTestReportWriter.cpp

51 lines
1.6 KiB
C++
Raw Permalink Normal View History

2015-08-24 21:38:09 -04:00
#include "make_unique.h"
2015-05-04 03:04:36 -04:00
#include "JUnitTestReportWriter.h"
#include "StdStreamUtils.h"
#include "xml/Writer.h"
#include "string_format.h"
2015-05-05 00:12:39 -04:00
CJUnitTestReportWriter::CJUnitTestReportWriter()
2015-05-04 03:04:36 -04:00
{
m_reportNode = std::make_unique<Framework::Xml::CNode>("", true);
2023-11-15 10:19:11 -05:00
auto testSuitesNode = m_reportNode->InsertNode(std::make_unique<Framework::Xml::CNode>("testsuites", true));
m_testSuiteNode = testSuitesNode->InsertNode(std::make_unique<Framework::Xml::CNode>("testsuite", true));
2015-05-04 03:04:36 -04:00
}
CJUnitTestReportWriter::~CJUnitTestReportWriter()
{
}
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, const TESTRESULT& result)
2015-05-04 03:04:36 -04:00
{
2023-11-15 10:19:11 -05:00
auto testCaseNode = std::make_unique<Framework::Xml::CNode>("testcase", true);
2015-05-04 03:04:36 -04:00
testCaseNode->InsertAttribute("name", testName.c_str());
if(!result.succeeded)
2015-05-04 03:04:36 -04:00
{
std::string failureDetails;
for(const auto& lineDiff : result.lineDiffs)
{
auto failureLine = string_format(
2018-04-30 21:01:23 +01:00
"result : %s\r\n"
"expected : %s\r\n"
"\r\n",
lineDiff.result.c_str(), lineDiff.expected.c_str());
failureDetails += failureLine;
}
2023-11-15 10:19:11 -05:00
auto resultNode = std::make_unique<Framework::Xml::CNode>("failure", true);
resultNode->InsertTextNode(failureDetails.c_str());
2023-11-15 10:19:11 -05:00
testCaseNode->InsertNode(std::move(resultNode));
2015-05-04 03:04:36 -04:00
}
2023-11-15 10:19:11 -05:00
m_testSuiteNode->InsertNode(std::move(testCaseNode));
2015-05-04 03:04:36 -04:00
m_testCount++;
}
2015-05-05 00:12:39 -04:00
void CJUnitTestReportWriter::Write(const fs::path& reportPath)
2015-05-05 00:12:39 -04:00
{
m_testSuiteNode->InsertAttribute("tests", string_format("%d", m_testCount).c_str());
auto testOutputFileStream = Framework::CreateOutputStdStream(reportPath.native());
Framework::Xml::CWriter::WriteDocument(testOutputFileStream, m_reportNode.get());
}