Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing execution steps statuses if same step is called multiple times in a test #24

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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