Skip to content

Commit

Permalink
feat: list all tests in check-run template
Browse files Browse the repository at this point in the history
  • Loading branch information
error418 committed Feb 13, 2020
1 parent 807cee0 commit f37ad84
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 25 deletions.
32 changes: 17 additions & 15 deletions src/status-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,29 @@ class TestNgStatusEmitter {
testClass["test-method"]?.forEach((method: TestNg.TestMethod) => {
report._tests.total++;

const annotation = new Harness.ProjectAnnotation();
if (method.$.status == "FAIL") {
report._tests.failed++;

const annotation = new Harness.ProjectAnnotation();
annotation.severity = Harness.Severity.BLOCKER;
annotation.title = method.$.signature;
annotation.detail = method.$.description;
annotation.metadata = {
duration_ms: method.$["duration-ms"],
suite: suite.$.name,
class: testClass.$.name,
started: method.$["started-at"],
finished: method.$["finished-at"]
};

annotations.push(annotation);
} else if (method.$.status == "PASS") {
report._tests.succeeded++;
} else if (method.$.status == "SKIP") {
report._tests.skipped++;
annotation.severity = Harness.Severity.WARNING;
} else if (method.$.status == "PASS") {
report._tests.succeeded++;
return; // continue loop; do not add annotation
}

annotation.title = method.$.signature;
annotation.detail = method.$.description;
annotation.metadata = {
duration_ms: method.$["duration-ms"],
suite: suite.$.name,
class: testClass.$.name,
started: method.$["started-at"],
finished: method.$["finished-at"]
};

annotations.push(annotation);
});
});
});
Expand Down
23 changes: 14 additions & 9 deletions templates/report.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

<span title="Succeeded">&#x2714;&#xFE0F;</span> {{ event.report._tests.succeeded }} &bull; <span title="Skipped">&#x23ed;</span> {{ event.report._tests.skipped }} &bull; <span title="Failed">&#x274C;</span> {{ event.report._tests.failed }}

{% if annotations.length > 0 %}
## Failed tests

| Test | Description |
|:---|:---|
{% for annotation in annotations -%}
| {{ annotation.title }} | {{ annotation.detail }} |
{% endfor %}
{% endif %}
{%- for suite in event['testng-results'].suite %}

### Suite {{ suite.$.name }}

| | Group | Class | Test | Description |
|---|:---|:---|:---|:---|
{%- for test in suite.test %}
{%- for testClass in test.class %}
{%- for testMethod in testClass['test-method'] %}
| {{ testMethod.$.status }} | {{ testClass.$.name }} | {{ testMethod.$.signature }} | {{ testMethod.$.description }} |
{%- endfor %}
{%- endfor %}
{%- endfor %}
{% endfor %}
71 changes: 71 additions & 0 deletions test/mock/testng-report-multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<testng-results>
<suite name="Suite1">
<groups>
<group name="group1">
<method signature="com.test.TestOne.test2()" name="test2" class="com.test.TestOne"/>
<method signature="com.test.TestOne.test1()" name="test1" class="com.test.TestOne"/>
</group>
<group name="group2">
<method signature="com.test.TestOne.test2()" name="test2" class="com.test.TestOne"/>
</group>
</groups>
<test name="test1">
<class name="com.test.TestOne">
<test-method status="FAIL" signature="test1()" name="test1" duration-ms="0"
started-at="2007-05-28T12:14:37Z" description="someDescription2"
finished-at="2007-05-28T12:14:37Z">
<exception class="java.lang.AssertionError">
<short-stacktrace>
<![CDATA[
java.lang.AssertionError
... Removed 22 stack frames
]]>
</short-stacktrace>
</exception>
</test-method>
<test-method status="PASS" signature="test2()" name="test2" duration-ms="0"
started-at="2007-05-28T12:14:37Z" description="someDescription1"
finished-at="2007-05-28T12:14:37Z">
</test-method>
<test-method status="PASS" signature="setUp()" name="setUp" is-config="true" duration-ms="15"
started-at="2007-05-28T12:14:37Z" finished-at="2007-05-28T12:14:37Z">
</test-method>
</class>
</test>
</suite>

<suite name="Suite2">
<groups>
<group name="group1">
<method signature="com.test.TestOne.test2()" name="test2" class="com.test.TestOne"/>
<method signature="com.test.TestOne.test1()" name="test1" class="com.test.TestOne"/>
</group>
<group name="group2">
<method signature="com.test.TestOne.test2()" name="test2" class="com.test.TestOne"/>
</group>
</groups>
<test name="test1">
<class name="com.test.TestOne">
<test-method status="FAIL" signature="s2_test1()" name="test1" duration-ms="0"
started-at="2007-05-28T12:14:37Z" description="someDescription2"
finished-at="2007-05-28T12:14:37Z">
<exception class="java.lang.AssertionError">
<short-stacktrace>
<![CDATA[
java.lang.AssertionError
... Removed 22 stack frames
]]>
</short-stacktrace>
</exception>
</test-method>
<test-method status="SKIP" signature="s2_test2()" name="test2" duration-ms="0"
started-at="2007-05-28T12:14:37Z" description="someDescription1"
finished-at="2007-05-28T12:14:37Z">
</test-method>
<test-method status="SKIP" signature="setUp()" name="setUp" is-config="true" duration-ms="15"
started-at="2007-05-28T12:14:37Z" finished-at="2007-05-28T12:14:37Z">
</test-method>
</class>
</test>
</suite>
</testng-results>
22 changes: 21 additions & 1 deletion test/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ describe("Templating", () => {
expect(markdown).to.be.not.undefined;
expect(markdown).to.include("someDescription2");
expect(markdown).to.include("test1()");
expect(markdown).to.include("Failed tests");
expect(markdown).to.include("test2()");
expect(markdown).to.include("setUp()");
});

it(`should be able to process multiple test-suites`, async () => {
const data = await xml2js.parseStringPromise(fs.readFileSync("./test/mock/testng-report-multiple.xml"));
const result = (statusEmitter as any).processEvent(
data
);

const templateData: TestNg.ReportTemplate = {
event: data,
annotations: result
};

const markdown = uut.template(Templates.REPORT, templateData);

expect(markdown).to.be.not.undefined;
expect(markdown).to.include("s2_test1()");
expect(markdown).to.include("s2_test2()");
expect(markdown).to.include("Suite2");
});
});

0 comments on commit f37ad84

Please sign in to comment.