Skip to content

Commit f84b6d6

Browse files
authored
Merge pull request #2661 from Fork-World/2660-fail_annotation_in_xml_report
#2660 fail annotation in xml report
2 parents 41c0454 + 6c18e0c commit f84b6d6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

karate-core/src/main/java/com/intuit/karate/report/ReportUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static File saveJunitXml(String targetDir, FeatureResult result, String f
216216
testCase.setAttribute("name", name);
217217
testCase.setAttribute("time", formatter.format(sr.getDurationMillis() / 1000));
218218
Element stepsHolder;
219-
if (error != null) {
219+
if (error != null && sr.isFailed()) {
220220
stepsHolder = doc.createElement("failure");
221221
stepsHolder.setAttribute("message", error.getMessage());
222222
} else {

karate-core/src/test/java/com/intuit/karate/report/ReportUtilsTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,25 @@ void testCustomTags() {
8181
File file = ReportUtils.saveJunitXml("target", fr.result, null);
8282
assertTrue(FileUtils.toString(file).contains(expectedCustomTags));
8383
}
84+
85+
@Test
86+
void testFailAnnotationXML() {
87+
String expectedSystemout = "<system-out>";
88+
Feature feature = Feature.read("classpath:com/intuit/karate/core/fail-tag.feature");
89+
FeatureRuntime fr = FeatureRuntime.of(new Suite(), new FeatureCall(feature));
90+
fr.run();
91+
File file = ReportUtils.saveJunitXml("target", fr.result, null);
92+
assertTrue(FileUtils.toString(file).contains(expectedSystemout));
93+
}
94+
95+
@Test
96+
void testFailAnnotationXMLFailure() {
97+
String expectedSystemout = "<failure";
98+
Feature feature = Feature.read("classpath:com/intuit/karate/core/fail-tag-failure.feature");
99+
FeatureRuntime fr = FeatureRuntime.of(new Suite(), new FeatureCall(feature));
100+
fr.run();
101+
File file = ReportUtils.saveJunitXml("target", fr.result, null);
102+
assertTrue(FileUtils.toString(file).contains(expectedSystemout));
103+
}
84104

85105
}

0 commit comments

Comments
 (0)