Skip to content

Commit

Permalink
adding junit xslt and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Dec 24, 2024
1 parent 67248da commit db62bd5
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 61 deletions.
132 changes: 132 additions & 0 deletions src/junit-junit.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">
<xsl:choose>
<xsl:when test="testsuites">
<testsuites name="{@name}" classname="{@classname}">
<xsl:choose>
<xsl:when test="@tests">
<xsl:attribute name="tests"><xsl:value-of select="@tests"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="tests"><xsl:value-of select="sum(testsuite/@tests)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@errors">
<xsl:attribute name="errors"><xsl:value-of select="@errors"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="errors"><xsl:value-of select="sum(testsuite/@errors)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@failures">
<xsl:attribute name="failures"><xsl:value-of select="@failures"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="failures"><xsl:value-of select="sum(testsuite/@failures)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@skipped">
<xsl:attribute name="skipped"><xsl:value-of select="@skipped"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="skipped"><xsl:value-of select="sum(testsuite/@skipped)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@assertions">
<xsl:attribute name="assertions"><xsl:value-of select="@assertions"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="assertions"><xsl:value-of select="sum(testsuite/@assertions)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="@time">
<xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="time"><xsl:value-of select="format-number(sum(testsuite/@time),'#.00000000')" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>

<xsl:apply-templates/>

</testsuites>
</xsl:when>
<xsl:otherwise>
<testsuites tests="{@tests}" errors="{@errors}" failures="{@failures}" skipped="{@skipped}" assertions="{@assertions}" time="{@time}">
<testsuite name="{replace(@name, 'Root Suite.', '')}" classname="{@classname}" tests="{@tests}" errors="{@errors}" failures="{@failures}" skipped="{@skipped}" assertions="{@assertions}" time="{@time}">
<xsl:apply-templates/>
</testsuite>
</testsuites>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

<xsl:template match="testsuite">
<xsl:if test="testcase">
<testsuite name="{replace(@name, 'Root Suite.', '')}" tests="{@tests}" time="{@time}" passed="{@passed}" failures="{@failures}" errors="{@errors}" skipped="{@skipped}" timestamp="{@timestamp}">
<xsl:apply-templates select="testcase"/>
<xsl:apply-templates select="properties"/>
<xsl:apply-templates select="system-out"/>
</testsuite>
<xsl:apply-templates select="testsuite"/>
</xsl:if>
<xsl:if test="not(testcase)">
<xsl:apply-templates select="testsuite"/>
</xsl:if>
</xsl:template>

<xsl:template match="testcase">
<testcase name="{@name}" classname="{@classname}" file="{@file}" time="{@time}">
<xsl:if test="skipped">
<xsl:choose>
<xsl:when test="message">
<skipped message="{message}"/>
</xsl:when>
<xsl:otherwise>
<skipped/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="failure">
<failure type="{failure/@type}" message="{failure/@message}">
<xsl:value-of select="failure"/>
</failure>
</xsl:if>
<xsl:if test="error">
<error type="{error/@type}" message="{error/@message}">
<xsl:value-of select="error"/>
</error>
</xsl:if>
<xsl:apply-templates select="properties"/>
<xsl:apply-templates select="system-out"/>
<xsl:apply-templates select="testcase"/>
</testcase>
</xsl:template>


<xsl:template match="system-out">
<system-out>
<xsl:value-of select="."/>
</system-out>
</xsl:template>

<xsl:template match="properties">
<xsl:if test="property">
<properties>
<xsl:for-each select="property">
<property name="{@name}" value="{@value}"/>
</xsl:for-each>
</properties>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
2 changes: 1 addition & 1 deletion src/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function getError(testcase){
message = `${prefix}${fail.message.replaceAll('&#xD;', '').replaceAll('&#xA;', '')}`;
}
if(fail.$t){
estack = fail.$t.replaceAll('&#xD;', '\n');
estack = fail.$t.replaceAll('&#xD;', '\n').replaceAll('&#x27;', '\'').replaceAll('&#x3C;', '<').replaceAll('&#x3E;', '>').replaceAll('&#x22;', '\"');
}
else if(typeof fail === 'string'){
estack = fail;
Expand Down
1 change: 1 addition & 0 deletions tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function createOptions(file, type){
reportDir: outDir,
reportFilename:`${path.parse(file).name}-mochawesome.json`,
junit: true,
transformJunit: true,
junitReportFilename: `${path.parse(file).name}-junit.xml`,
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/converter.junit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ describe("JUnit converter tests", () => {
let options = common.createOptions('junit-jenkins.xml', 'junit');

await converter(options);
common.compare(options);
common.compare(options, undefined, true);
});

test('junit-notestsuites.xml', async() => {
let options = common.createOptions('junit-notestsuites.xml', 'junit');

await converter(options);
common.compare(options, 'junit-jenkins-mochawesome.json');
common.compare(options, 'junit-jenkins-mochawesome.json', true);
});

test('junit-testsuites-noattributes.xml', async() => {
let options = common.createOptions('junit-testsuites-noattributes.xml', 'junit');

await converter(options);
common.compare(options, 'junit-jenkins-mochawesome.json');
common.compare(options, 'junit-jenkins-mochawesome.json', true);
});

test('junit-mocha-xunit.xml', async() => {
let options = common.createOptions('junit-mocha-xunit.xml', 'junit')

await converter(options);
common.compare(options);
common.compare(options, undefined, true);
});

});
55 changes: 55 additions & 0 deletions tests/data/result/junit-jenkins-junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<testsuites tests="3" errors="1" failures="0" skipped="0" assertions="0" time="0.036988">
<testsuite name="PatientRegistration.Patient Registration (Example)" tests="3" time="0.036988" failures="0" errors="1" skipped="0" timestamp="2019-11-08T09:10:24.803951">
<testcase name="Create patient" classname="PatientRegistration.Patient Registration (Example)" time="0.015996">
<system-out>
@scenario.begin

@tc:62
Scenario: Create patient
When I create a patient with name "John Doe" on the host ... passed in 0.005s
Then the patient "John Doe" should also be created in the application. ... passed in 0.011s

@scenario.end
--------------------------------------------------------------------------------
</system-out>
</testcase>
<testcase name="Close patient" classname="PatientRegistration.Patient Registration (Example)" time="0.015">
<system-out>
@scenario.begin

@tc:63
Scenario: Close patient
Given a patient is opened in the application ... passed in 0.005s
When I close the patient on the host ... passed in 0.005s
Then the patient should also be closed in the application. ... passed in 0.005s

@scenario.end
--------------------------------------------------------------------------------
</system-out>
</testcase>
<testcase name="Edit patient" classname="PatientRegistration.Patient Registration (Example)" time="0.005992">
<system-out>
@scenario.begin
Scenario: Edit patient
Given a patient is opened in the application ... passed in 0.005s
When I change the patient name to "John Doe" on the host ... failed in 0.001s
Then the patient name should also be changed to "John Doe" in the application. ... skipped in 0.000s

@scenario.end
--------------------------------------------------------------------------------
</system-out>
<error type="TypeError" message="edit() missing 2 required positional arguments: 'birth_date' and 'sex'">
Failing step: When I change the patient name to "John Doe" on the host ... failed in 0.001s
Location: tests/features/PatientRegistration.feature:20
Traceback (most recent call last):
File "D:\dev\bdd_demo_behave\.venv\lib\site-packages\behave\model.py", line 1329, in run
match.run(runner.context)
File "D:\dev\bdd_demo_behave\.venv\lib\site-packages\behave\matchers.py", line 98, in run
self.func(context, *args, **kwargs)
File "tests\features\steps\step_patient_registration.py", line 33, in step_impl
context.patient.edit(first_name="John", last_name="Doe")
TypeError: edit() missing 2 required positional arguments: 'birth_date' and 'sex'
</error>
</testcase>
</testsuite>
</testsuites>
22 changes: 11 additions & 11 deletions tests/data/result/junit-jenkins-mochawesome.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"results": [
{
"uuid": "f0a8889a-a3a3-44ca-a98b-c56b44a2820c",
"uuid": "1dbbbd17-6bb3-4278-ad3b-85c4a03b5da7",
"title": "",
"fullFile": "",
"file": "",
Expand All @@ -25,7 +25,7 @@
"tests": [],
"suites": [
{
"uuid": "4e9d6c4e-e0d0-4edf-8641-e659b8521ea3",
"uuid": "9926b91e-7b47-47b3-a6cd-68fc2abe2336",
"title": "PatientRegistration.Patient Registration (Example)",
"file": "",
"beforeHooks": [],
Expand All @@ -43,8 +43,8 @@
"context": "[{\"title\":\"system-out\",\"value\":\"@scenario.begin\\n\\n @tc:62\\n Scenario: Create patient\\n When I create a patient with name \\\"John Doe\\\" on the host ... passed in 0.005s\\n Then the patient \\\"John Doe\\\" should also be created in the application. ... passed in 0.011s\\n\\[email protected]\\n--------------------------------------------------------------------------------\"}]",
"code": null,
"err": {},
"uuid": "f1cfcfd4-7a47-4eb7-8980-100f94f85ce6",
"parentUUID": "4e9d6c4e-e0d0-4edf-8641-e659b8521ea3",
"uuid": "23bb7af8-30b9-436b-a989-89ebd5499127",
"parentUUID": "9926b91e-7b47-47b3-a6cd-68fc2abe2336",
"isHook": false,
"skipped": false
},
Expand All @@ -60,8 +60,8 @@
"context": "[{\"title\":\"system-out\",\"value\":\"@scenario.begin\\n\\n @tc:63\\n Scenario: Close patient\\n Given a patient is opened in the application ... passed in 0.005s\\n When I close the patient on the host ... passed in 0.005s\\n Then the patient should also be closed in the application. ... passed in 0.005s\\n\\[email protected]\\n--------------------------------------------------------------------------------\"}]",
"code": null,
"err": {},
"uuid": "b6496130-9548-44ff-b7de-954ed06af71d",
"parentUUID": "4e9d6c4e-e0d0-4edf-8641-e659b8521ea3",
"uuid": "cb94bbf1-0cab-4224-a6c2-0bfc9a6221e5",
"parentUUID": "9926b91e-7b47-47b3-a6cd-68fc2abe2336",
"isHook": false,
"skipped": false
},
Expand All @@ -81,19 +81,19 @@
"estack": "Failing step: When I change the patient name to \"John Doe\" on the host ... failed in 0.001s\nLocation: tests/features/PatientRegistration.feature:20\nTraceback (most recent call last):\n File \"D:\\dev\\bdd_demo_behave\\.venv\\lib\\site-packages\\behave\\model.py\", line 1329, in run\n match.run(runner.context)\n File \"D:\\dev\\bdd_demo_behave\\.venv\\lib\\site-packages\\behave\\matchers.py\", line 98, in run\n self.func(context, *args, **kwargs)\n File \"tests\\features\\steps\\step_patient_registration.py\", line 33, in step_impl\n context.patient.edit(first_name=\"John\", last_name=\"Doe\")\nTypeError: edit() missing 2 required positional arguments: 'birth_date' and 'sex'",
"diff": null
},
"uuid": "0571e92b-63e8-4b1d-a573-4af8b0c50365",
"parentUUID": "4e9d6c4e-e0d0-4edf-8641-e659b8521ea3",
"uuid": "324da1ab-10ac-4d66-b63f-a9333332c6c6",
"parentUUID": "9926b91e-7b47-47b3-a6cd-68fc2abe2336",
"isHook": false,
"skipped": false
}
],
"suites": [],
"passes": [
"f1cfcfd4-7a47-4eb7-8980-100f94f85ce6",
"b6496130-9548-44ff-b7de-954ed06af71d"
"23bb7af8-30b9-436b-a989-89ebd5499127",
"cb94bbf1-0cab-4224-a6c2-0bfc9a6221e5"
],
"failures": [
"0571e92b-63e8-4b1d-a573-4af8b0c50365"
"324da1ab-10ac-4d66-b63f-a9333332c6c6"
],
"pending": [],
"skipped": [],
Expand Down
Loading

0 comments on commit db62bd5

Please sign in to comment.