Skip to content

Commit

Permalink
Fix missing execution steps statuses (#24)
Browse files Browse the repository at this point in the history
The xml report formatter now returns the same number of step results as
the number of steps in a cucumber test, even if some steps have the same name.
  • Loading branch information
fahadi-henix authored Feb 15, 2024
1 parent f559f44 commit 5e6da5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Missing execution steps statuses if same step is called multiple times in a test ([#24](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/24) F. Ahadi)

## [0.2.0] - 2023-04-07

## [0.1.0] - 2022-12-27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import java.time.Duration;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.Comparator;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -207,19 +207,19 @@ public String getFeatureName(String testCaseStartedId) {
return scenarioAstNodeIdToFeatureName.get(astNodeId);
}

LinkedHashMap<String, String> getStepsAndResult(String testCaseStartedId) {
List<Map.Entry<String, String>> getStepsAndResult(String testCaseStartedId) {
String testCaseId = testCaseStartedIdToTestCaseId.get(testCaseStartedId);
TestCase testCase = testCaseIdToTestCase.get(testCaseId);
Pickle pickle = pickleIdToPickle.get(testCase.getPickleId());

return testCase.getTestSteps().stream()
.filter(testStep -> testStep.getPickleStepId().isPresent())
.collect(Collectors.toMap(
renderTestStepText(pickle),
this::renderTestStepResult,
(existing, replacement) -> replacement,
LinkedHashMap::new
));
.map(testStep -> {
String key = renderTestStepText(pickle).apply(testStep);
String value = renderTestStepResult(testStep);
return new AbstractMap.SimpleEntry<>(key, value);
})
.collect(Collectors.toList());
}

private String renderTestStepResult(TestStep testStep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import io.cucumber.messages.types.TestStepResult;
import io.cucumber.messages.types.TestStepResultStatus;

import java.util.List;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import java.io.Writer;
import java.text.NumberFormat;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import static io.cucumber.messages.types.TestStepResultStatus.FAILED;
import static io.cucumber.messages.types.TestStepResultStatus.PASSED;
import static io.cucumber.messages.types.TestStepResultStatus.SKIPPED;

Expand Down Expand Up @@ -126,7 +125,7 @@ private void writeNonPassedElement(EscapingXmlStreamWriter writer, String id) th
}

private void writeStepAndResultList(EscapingXmlStreamWriter writer, String id) throws XMLStreamException {
LinkedHashMap<String, String> results = data.getStepsAndResult(id);
List<Map.Entry<String, String>> results = data.getStepsAndResult(id);
if (results.isEmpty()) {
return;
}
Expand All @@ -136,10 +135,10 @@ private void writeStepAndResultList(EscapingXmlStreamWriter writer, String id) t
writer.newLine();
}

private static String createStepResultList(LinkedHashMap<String, String> results) {
private static String createStepResultList(List<Map.Entry<String, String>> results) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
results.entrySet().forEach(r -> {
results.forEach(r -> {
String stepText = r.getKey();
String status = r.getValue();
sb.append(stepText);
Expand Down

0 comments on commit 5e6da5d

Please sign in to comment.