Class XUnitReporter

The XUnit reporter creates a xml containing the test results

class XUnitReporter
  : ILifecycleListener ;

Methods

NameDescription
begin (testCount) This method is trigered when before the test start
end () This method is trigered when your tests are ended
update () This method is triggered when you can perform some updates. The frequency varries by the test executor that you choose

Example

XUnitTestXml should transform a suite with a success test

auto epoch = SysTime.fromUnixTime(0);
auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;

TestResult test = new TestResult("Test");
test.begin = Clock.currTime;
test.end = Clock.currTime;
test.status = TestResult.Status.success;

result.end = Clock.currTime;

result.tests = [ test ];

auto xunit = XUnitSuiteXml(result);

xunit.toString.should.equal(`  <testsuite name="` ~ result.name.escapeXUnit ~ `" errors="0" skipped="0" tests="1" failures="0" time="0" timestamp="`~result.begin.toISOExtString~`">
    <testcase name="Test">
    </testcase>
</testsuite>`);

Example

XUnitTestXml should transform a suite with a failed test

auto epoch = SysTime.fromUnixTime(0);
auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;

TestResult test = new TestResult("Test");
test.begin = Clock.currTime;
test.end = Clock.currTime;
test.status = TestResult.Status.failure;

result.end = Clock.currTime;

result.tests = [ test ];

auto xunit = XUnitSuiteXml(result);

xunit.toString.should.equal(`  <testsuite name="` ~ result.name.escapeXUnit ~ `" errors="0" skipped="0" tests="1" failures="1" time="0" timestamp="`~result.begin.toISOExtString~`">
    <testcase name="Test">
    <failure/>
    </testcase>
</testsuite>`);

Example

XUnitTestXml should transform a suite with a skipped test

auto epoch = SysTime.fromUnixTime(0);
auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;

TestResult test = new TestResult("Test");
test.begin = Clock.currTime;
test.end = Clock.currTime;
test.status = TestResult.Status.skip;

result.end = Clock.currTime;

result.tests = [ test ];

auto xunit = XUnitSuiteXml(result);

xunit.toString.should.equal(`  <testsuite name="` ~ result.name.escapeXUnit ~ `" errors="0" skipped="1" tests="1" failures="0" time="0" timestamp="`~result.begin.toISOExtString~`">
    <testcase name="Test">
    <skipped/>
    </testcase>
</testsuite>`);

Example

XUnitTestXml should transform a suite with a unknown test

auto epoch = SysTime.fromUnixTime(0);
auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;

TestResult test = new TestResult("Test");
test.begin = Clock.currTime;
test.end = Clock.currTime;
test.status = TestResult.Status.unknown;

result.end = Clock.currTime;

result.tests = [ test ];

auto xunit = XUnitSuiteXml(result);

xunit.toString.should.equal(`  <testsuite name="` ~ result.name.escapeXUnit ~ `" errors="1" skipped="0" tests="1" failures="0" time="0" timestamp="`~result.begin.toISOExtString~`">
    <testcase name="Test">
    <error message="unknown status">unknown</error>
    </testcase>
</testsuite>`);

Example

XUnitTestXml should transform an empty suite

auto epoch = SysTime.fromUnixTime(0);
auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;
result.end = Clock.currTime;

auto xunit = XUnitSuiteXml(result);

xunit.toString.should.equal(`  <testsuite name="` ~ result.name.escapeXUnit ~ `" errors="0" skipped="0" tests="0" failures="0" time="0" timestamp="` ~ result.begin.toISOExtString ~ `">
</testsuite>`);

Example

XUnitTestXml should transform a success test

auto epoch = SysTime.fromUnixTime(0);

TestResult result = new TestResult("Test");
result.begin = Clock.currTime;
result.end = Clock.currTime;
result.status = TestResult.Status.success;

auto allure = XUnitTestXml(result);

allure.toString.strip.should.equal(`<testcase name="Test">` ~ "\n      </testcase>");

Example

XUnitTestXml should transform a failing test

auto epoch = SysTime.fromUnixTime(0);
TestResult result = new TestResult("Test");
result.begin = Clock.currTime;
result.end = Clock.currTime;
result.status = TestResult.Status.failure;
result.throwable = new Exception("message");

auto xunit = XUnitTestXml(result);
xunit.toString.strip.should.equal(`<testcase name="Test">` ~ "\n" ~
`      <failure message="message">` ~ result.throwable.to!string ~ `</failure>` ~ "\n" ~
`      </testcase>`);