|
| 1 | +[](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 | + |
1 | 5 | JUnit XML Formatter |
2 | 6 | =================== |
3 | 7 |
|
4 | 8 | Writes Cucumber message into a JUnit XML report. |
5 | 9 |
|
| 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. |
0 commit comments