Added more details to JUnit reports in AutoTest.

This commit is contained in:
Jean-Philip Desjardins 2015-07-03 03:21:48 -04:00
parent 1109a1c28f
commit a95be1ee5c
4 changed files with 47 additions and 12 deletions

View File

@ -18,14 +18,25 @@ CJUnitTestReportWriter::~CJUnitTestReportWriter()
}
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, bool succeeded)
void CJUnitTestReportWriter::ReportTestEntry(const std::string& testName, const TESTRESULT& result)
{
auto testCaseNode = new Framework::Xml::CNode("testcase", true);
testCaseNode->InsertAttribute("name", testName.c_str());
if(!succeeded)
if(!result.succeeded)
{
std::string failureDetails;
for(const auto& lineDiff : result.lineDiffs)
{
auto failureLine = string_format(
"result : %s\r\n"
"expected : %s\r\n"
"\r\n",
lineDiff.result.c_str(), lineDiff.expected.c_str());
failureDetails += failureLine;
}
auto resultNode = new Framework::Xml::CNode("failure", true);
resultNode->InsertTextNode(failureDetails.c_str());
testCaseNode->InsertNode(resultNode);
}

View File

@ -10,7 +10,7 @@ public:
CJUnitTestReportWriter();
virtual ~CJUnitTestReportWriter();
void ReportTestEntry(const std::string&, bool) override;
void ReportTestEntry(const std::string&, const TESTRESULT&) override;
void Write(const boost::filesystem::path&) override;
private:

View File

@ -16,8 +16,10 @@ std::vector<std::string> ReadLines(Framework::CStream& inputStream)
return lines;
}
bool CompareResults(const boost::filesystem::path& testFilePath)
TESTRESULT GetTestResult(const boost::filesystem::path& testFilePath)
{
TESTRESULT result;
result.succeeded = false;
try
{
auto resultFilePath = testFilePath;
@ -30,19 +32,27 @@ bool CompareResults(const boost::filesystem::path& testFilePath)
auto resultLines = ReadLines(resultStream);
auto expectedLines = ReadLines(expectedStream);
if(resultLines.size() != expectedLines.size()) return false;
if(resultLines.size() != expectedLines.size()) return result;
for(unsigned int i = 0; i < resultLines.size(); i++)
{
if(resultLines[i] != expectedLines[i]) return false;
if(resultLines[i] != expectedLines[i])
{
LINEDIFF lineDiff;
lineDiff.expected = expectedLines[i];
lineDiff.result = resultLines[i];
result.lineDiffs.push_back(lineDiff);
}
}
return true;
result.succeeded = result.lineDiffs.empty();
return result;
}
catch(...)
{
return false;
}
return result;
}
void ExecuteTest(const boost::filesystem::path& testFilePath)
@ -92,11 +102,11 @@ void ScanAndExecuteTests(const boost::filesystem::path& testDirPath, const TestR
{
printf("Testing '%s': ", testPath.string().c_str());
ExecuteTest(testPath);
bool succeeded = CompareResults(testPath);
printf("%s.\r\n", succeeded ? "SUCCEEDED" : "FAILED");
auto result = GetTestResult(testPath);
printf("%s.\r\n", result.succeeded ? "SUCCEEDED" : "FAILED");
if(testReportWriter)
{
testReportWriter->ReportTestEntry(testPath.string(), succeeded);
testReportWriter->ReportTestEntry(testPath.string(), result);
}
}
}

View File

@ -3,12 +3,26 @@
#include <string>
#include <memory>
struct LINEDIFF
{
std::string expected;
std::string result;
};
struct TESTRESULT
{
typedef std::vector<LINEDIFF> LineDiffArray;
bool succeeded = false;
LineDiffArray lineDiffs;
};
class CTestReportWriter
{
public:
virtual ~CTestReportWriter() {}
virtual void ReportTestEntry(const std::string& name, bool succeeded) = 0;
virtual void ReportTestEntry(const std::string& name, const TESTRESULT&) = 0;
virtual void Write(const boost::filesystem::path& reportPath) = 0;
};