Class AllureReporter

The Allure reporter creates a xml containing the test results, the steps and the attachments. http://allure.qatools.ru/

class AllureReporter
  : 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

AllureSuiteXml should add the attachments

string resource = buildPath(getcwd(), "some_text.txt");
std.file.write(resource, "");

auto uuid = randomUUID.toString;

scope(exit) {
  remove(resource);
  remove("allure/" ~ uuid ~ "/title.0.some_text.txt");
}

auto epoch = SysTime.fromUnixTime(0);

auto result = SuiteResult("Test Suite");
result.begin = Clock.currTime;
result.end = Clock.currTime;
result.attachments = [ Attachment("title", resource, "plain/text") ];

auto allure = AllureSuiteXml("allure", result, uuid);

allure.toString.should.equal(
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:test-suite start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" version="1.5.2" xmlns:ns2="urn:model.allure.qatools.yandex.ru">
  <name>` ~ result.name ~ `</name>
  <title>` ~ result.name ~ `</title>
  <test-cases>
  </test-cases>
  <attachments>
    <attachment title="title" source="` ~ uuid ~ `/title.0.some_text.txt" type="plain/text" />
  </attachments>
  <labels>
      <label name="framework" value="Trial"/>
      <label name="language" value="D"/>
  </labels>
</ns2:test-suite>`);

Example

AllureTestXml should transform a test with steps

auto epoch = SysTime.fromUnixTime(0);

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

StepResult step = new StepResult();
step.name = "some step";
step.begin = result.begin;
step.end = result.end;

result.steps = [step, step];

auto allure = AllureTestXml("allure", result, "");

allure.toString.should.equal(
`        <test-case start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
          <name>Test</name>
          <steps>
              <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
                <name>some step</name>
              </step>
              <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
                <name>some step</name>
              </step>
          </steps>
      </test-case>`);

Example

AllureTestXml should transform a test with labels

auto epoch = SysTime.fromUnixTime(0);

TestResult result = new TestResult("Test");
result.begin = Clock.currTime;
result.end = Clock.currTime;
result.status = TestResult.Status.success;
result.labels ~= Label("status_details", "flaky");

auto allure = AllureTestXml("allure", result, "");

allure.toString.should.equal(
`        <test-case start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
          <name>Test</name>
          <labels>
            <label name="status_details" value="flaky"/>
          </labels>
      </test-case>`);

Example

AllureTestXml should add the attachments

string resource = buildPath(getcwd(), "some_text.txt");
std.file.write(resource, "");

auto uuid = randomUUID.toString;

scope(exit) {
  if(exists(resource)) {
    remove(resource);
  }

  remove("allure/" ~ uuid ~ "/title.0.some_text.txt");
}

auto epoch = SysTime.fromUnixTime(0);

TestResult result = new TestResult("Test");
result.begin = Clock.currTime;
result.end = Clock.currTime;
result.status = TestResult.Status.success;
result.attachments = [ Attachment("title", resource, "plain/text") ];

auto allure = AllureTestXml("allure", result, uuid);

allure.toString.should.equal(
`        <test-case start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
          <name>Test</name>
          <attachments>
            <attachment title="title" source="` ~ uuid ~ `/title.0.some_text.txt" type="plain/text" />
          </attachments>
      </test-case>`);

Example

AllureStepXml should transform a step

auto epoch = SysTime.fromUnixTime(0);
StepResult result = new StepResult();
result.name = "step";
result.begin = Clock.currTime;
result.end = Clock.currTime;

auto allure = AllureStepXml("allure", result, 0, "");

allure.toString.should.equal(
`  <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
  <name>step</name>
</step>`);

Example

AllureStepXml should transform nested steps

auto epoch = SysTime.fromUnixTime(0);
StepResult result = new StepResult();
result.name = "step";
result.begin = Clock.currTime;
result.end = Clock.currTime;

StepResult step = new StepResult();
step.name = "some step";
step.begin = result.begin;
step.end = result.end;

result.steps = [ step, step ];

auto allure = AllureStepXml("allure", result, 0, "");

allure.toString.should.equal(
`  <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
  <name>step</name>
  <steps>
      <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
        <name>some step</name>
      </step>
      <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
        <name>some step</name>
      </step>
  </steps>
</step>`);

Example

AllureStepXml should add the attachments

string resource = buildPath(getcwd(), "some_image.png");
scope(exit) {
  resource.remove();
}
std.file.write(resource, "");

auto uuid = randomUUID.toString;

scope(exit) {
  rmdirRecurse("allure");
}


auto epoch = SysTime.fromUnixTime(0);
StepResult result = new StepResult();
result.name = "step";
result.begin = Clock.currTime;
result.end = Clock.currTime;

result.attachments = [ Attachment("name", resource, "image/png") ];

auto allure = AllureStepXml("allure", result, 0, uuid);

allure.toString.should.equal(
`  <step start="` ~ (result.begin - epoch).total!"msecs".to!string ~ `" stop="` ~ (result.end - epoch).total!"msecs".to!string ~ `" status="passed">
  <name>step</name>
  <attachments>
    <attachment title="name" source="` ~ uuid ~ `/name.0.some_image.png" type="image/png" />
  </attachments>
</step>`);