Skip to content

Commit 51bcd2a

Browse files
authored
java: Implement JUnit XML formatter (#3)
1 parent 438ec1f commit 51bcd2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2935
-0
lines changed

.github/renovate.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": [
3+
"config:base",
4+
":preserveSemverRanges",
5+
":rebaseStalePrs",
6+
":disableDependencyDashboard"
7+
],
8+
"labels": [":robot: dependencies"],
9+
"prHourlyLimit": 0,
10+
"packageRules": [
11+
{
12+
"depTypeList": ["devDependencies", "dependencies"],
13+
"updateTypes": ["minor", "patch"],
14+
"automerge": true,
15+
"automergeType": "branch"
16+
}
17+
]
18+
}

.github/workflows/test-java.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test-java
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- renovate/**
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_call:
12+
13+
jobs:
14+
test-java:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
java: ["11", "17"]
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- uses: actions/setup-java@v3
27+
with:
28+
distribution: "zulu"
29+
java-version: ${{ matrix.java }}
30+
cache: "maven"
31+
32+
- run: mvn verify
33+
working-directory: java
34+

.github/workflows/test-testdata.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: test-testdata
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test-testdata:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
17+
- uses: actions/checkout@v3
18+
19+
- uses: actions/setup-node@v3
20+
with:
21+
cache: 'npm'
22+
cache-dependency-path: testdata/package-lock.json
23+
24+
- run: npm ci
25+
working-directory: testdata
26+
27+
- name: check repository is not dirty
28+
run: "[[ -z $(git status --porcelain) ]]"
29+
30+
- name: show diff
31+
if: ${{ failure() }}
32+
run: git status --porcelain

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Java implementation ([#3](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/3) M.P. Korstanje)
12+
13+
1014
[Unreleased]: https://github.com/cucumber/action-publish-poetry/compare/0.0.0...HEAD

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) M.P. Korstanje
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+107
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,112 @@
1+
[![Maven Central](https://img.shields.io/maven-central/v/io.cucumber/junit-xml-formatter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.cucumber%22%20AND%20a:%22junit-xml-formatter%22)
2+
3+
⚠️ This is an internal package; you don't need to install it in order to use the JUnit XML Formatter.
4+
15
JUnit XML Formatter
26
===================
37

48
Writes Cucumber message into a JUnit XML report.
59

10+
The JUnit XML report is a loose standard. We validate it against the
11+
[Jenkins JUnit XML XSD](./jenkins-junit.xsd) so there should be a good
12+
chance your CI will understand it.
13+
14+
If not, please let us know in the issues!
15+
16+
## Features and Limitations
17+
18+
### Test outcome mapping
19+
20+
Cucumber and the JUnit XML Report support a different set of test outcomes.
21+
These are mapped according to the table below.
22+
23+
Additionally, it is advisable to run Cucumber in strict mode. When used in
24+
non-strict mode scenarios with a pending or undefined outcome will not fail
25+
the test run ([#714](https://github.com/cucumber/common/issues/714)). This
26+
can lead to a xml report that contains `failure` outcomes while the build
27+
passes.
28+
29+
| Cucumber Outcome | XML Outcome | Passes in strict mode | Passes in non-strict mode |
30+
|------------------|-------------|-----------------------|---------------------------|
31+
| UNKNOWN | n/a | n/a | n/a |
32+
| PASSED | passed | yes | yes |
33+
| SKIPPED | skipped | yes | yes |
34+
| PENDING | failure | no | yes |
35+
| UNDEFINED | failure | no | yes |
36+
| AMBIGUOUS | failure | no | no |
37+
| FAILED | failure | no | no |
38+
39+
40+
### Step reporting
41+
42+
The JUnit XML report assumes that a test is a method on a class. Yet a scenario
43+
consists of multiple steps. To provide info about which step failed, the `system-out`
44+
element will contain a rendition of steps and their result.
45+
46+
```xml
47+
<system-out><![CDATA[
48+
Given there are 12 cucumbers................................................passed
49+
When I eat 5 cucumbers......................................................passed
50+
Then I should have 7 cucumbers..............................................passed
51+
]]></system-out>
52+
```
53+
54+
### Naming Rules and Examples
55+
56+
Cucumber does not require that scenario names are unique. To disambiguate
57+
between similarly named scenarios and examples the report prefixes the rule
58+
to the scenario or example name.
59+
60+
```feature
61+
Feature: Rules
62+
63+
Rule: a sale cannot happen if change cannot be returned
64+
Example: no change
65+
...
66+
Example: exact change
67+
...
68+
69+
Rule: a sale cannot happen if we're out of stock
70+
Example: no chocolates left
71+
...
72+
```
73+
74+
```xml
75+
<testcase classname="Rules" name="a sale cannot happen if change cannot be returned - no change" time="0.007" />
76+
<testcase classname="Rules" name="a sale cannot happen if change cannot be returned - exact change" time="0.009" />
77+
<testcase classname="Rules" name="a sale cannot happen if we're out of stock - no chocolates left" time="0.009" />
78+
```
79+
80+
Likewise for example tables, the rule (if any), scenario outline name, example
81+
name, and number are included.
82+
83+
```feature
84+
Feature: Examples Tables
85+
86+
Scenario Outline: Eating cucumbers
87+
Given there are <start> cucumbers
88+
When I eat <eat> cucumbers
89+
Then I should have <left> cucumbers
90+
91+
Examples: These are passing
92+
| start | eat | left |
93+
| 12 | 5 | 7 |
94+
| 20 | 5 | 15 |
95+
96+
Examples: These are failing
97+
| start | eat | left |
98+
| 12 | 20 | 0 |
99+
| 0 | 1 | 0 |
100+
```
101+
102+
```xml
103+
<testcase classname="Examples Tables" name="Eating cucumbers - These are passing - Example #1.1" />
104+
<testcase classname="Examples Tables" name="Eating cucumbers - These are passing - Example #1.2" />
105+
<testcase classname="Examples Tables" name="Eating cucumbers - These are failing - Example #2.1" />
106+
<testcase classname="Examples Tables" name="Eating cucumbers - These are failing - Example #2.2" />
107+
```
108+
## Contributing
109+
110+
Each language implementation validates itself against the examples in the
111+
`testdata` folder. See the [testdata/README.md](testdata/README.md) for more
112+
information.

java/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
*.iml
3+
target/

java/pom.xml

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>io.cucumber</groupId>
7+
<artifactId>cucumber-parent</artifactId>
8+
<version>4.1.1</version>
9+
</parent>
10+
11+
<artifactId>junit-xml-formatter</artifactId>
12+
<version>0.0.1-SNAPSHOT</version>
13+
<packaging>jar</packaging>
14+
<name>Cucumber JUnit XML Formatter</name>
15+
<description>Renders Cucumber Messages as JUnit XML</description>
16+
<url>https://github.com/cucumber/cucumber-junit-xml-formatter</url>
17+
18+
<properties>
19+
<project.Automatic-Module-Name>io.cucumber.junitxmlformatter</project.Automatic-Module-Name>
20+
<project.build.outputTimestamp>1000000000</project.build.outputTimestamp>
21+
</properties>
22+
23+
<scm>
24+
<connection>scm:git:git://github.com/cucumber/cucumber-junit-xml-formatter.git</connection>
25+
<developerConnection>scm:git:[email protected]:cucumber/cucumber-junit-xml-formatter.git</developerConnection>
26+
<url>git://github.com/cucumber/cucumber-junit-xml-formatter.git</url>
27+
<tag>HEAD</tag>
28+
</scm>
29+
30+
<dependencyManagement>
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.junit</groupId>
34+
<artifactId>junit-bom</artifactId>
35+
<version>5.9.1</version>
36+
<type>pom</type>
37+
<scope>import</scope>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.fasterxml.jackson</groupId>
42+
<artifactId>jackson-bom</artifactId>
43+
<version>2.14.1</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>io.cucumber</groupId>
53+
<artifactId>messages</artifactId>
54+
<version>[21.0.1,22.0.0)</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.core</groupId>
59+
<artifactId>jackson-databind</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>com.fasterxml.jackson.datatype</groupId>
65+
<artifactId>jackson-datatype-jdk8</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>com.fasterxml.jackson.module</groupId>
71+
<artifactId>jackson-module-parameter-names</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.hamcrest</groupId>
77+
<artifactId>hamcrest</artifactId>
78+
<version>2.2</version>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.assertj</groupId>
84+
<artifactId>assertj-core</artifactId>
85+
<version>3.23.1</version>
86+
<scope>test</scope>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>org.xmlunit</groupId>
91+
<artifactId>xmlunit-assertj</artifactId>
92+
<version>2.9.0</version>
93+
<scope>test</scope>
94+
</dependency>
95+
96+
<dependency>
97+
<groupId>org.junit.jupiter</groupId>
98+
<artifactId>junit-jupiter-engine</artifactId>
99+
<scope>test</scope>
100+
</dependency>
101+
102+
<dependency>
103+
<groupId>org.junit.jupiter</groupId>
104+
<artifactId>junit-jupiter-params</artifactId>
105+
<scope>test</scope>
106+
</dependency>
107+
</dependencies>
108+
</project>

0 commit comments

Comments
 (0)