Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.Duration;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -35,6 +36,7 @@ class XmlReportData {
private final NamingStrategy namingStrategy;

private static final long MILLIS_PER_SECOND = SECONDS.toMillis(1L);
private static final String REQUIREMENT_PREFIX = "@Req:";

XmlReportData(NamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy;
Expand Down Expand Up @@ -83,6 +85,19 @@ String getFeatureName(TestCaseStarted testCaseStarted) {
.orElseGet(() -> this.getPickle(testCaseStarted).getUri());
}

/**
* Extracts a requirement tag denoted by starting with "@Req:"
*/
List<String> getFeatureRequirements(TestCaseStarted testCaseStarted) {
return query.findPickleBy(testCaseStarted)
.map(Pickle::getTags)
.orElse(Collections.emptyList())
.stream()
.filter(tag -> tag.getName().startsWith(REQUIREMENT_PREFIX))
.map(tag -> tag.getName().substring(REQUIREMENT_PREFIX.length()))
.collect(toList());
}

List<Entry<String, String>> getStepsAndResult(TestCaseStarted testCaseStarted) {
return query.findTestStepFinishedAndTestStepBy(testCaseStarted)
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
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.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -78,6 +78,7 @@ private void writeTestcase(EscapingXmlStreamWriter writer, TestCaseStarted testC
writer.writeStartElement("testcase");
writeTestCaseAttributes(writer, testCaseStarted);
writer.writeNewLine();
writeRequirementProperties(writer, testCaseStarted);
writeNonPassedElement(writer, testCaseStarted);
writeStepAndResultList(writer, testCaseStarted);
writer.writeEndElement();
Expand All @@ -90,6 +91,19 @@ private void writeTestCaseAttributes(EscapingXmlStreamWriter writer, TestCaseSta
writer.writeAttribute("time", String.valueOf(data.getDurationInSeconds(testCaseStarted)));
}

private void writeRequirementProperties(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException {
List<String> requirements = data.getFeatureRequirements(testCaseStarted);

if (!requirements.isEmpty()) {
writer.writeStartElement("properties");
writer.writeStartElement("property");
writer.writeAttribute("name", "requirements");
writer.writeAttribute("value", String.join(",", requirements));
writer.writeNewLine();
}

}

private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException {
TestStepResult result = data.getTestCaseStatus(testCaseStarted);
TestStepResultStatus status = result.getStatus();
Expand Down Expand Up @@ -164,4 +178,4 @@ private static String createStepResultList(List<Map.Entry<String, String>> resul
});
return sb.toString();
}
}
}
7 changes: 7 additions & 0 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export default {
name: testCase.name,
time: testCase.time,
})
if (testCase.requirements.length > 0) {
const properties = testcaseElement.ele('properties')
properties.ele('property', {
name: 'requirements',
value: testCase.requirements.join(",")
})
}
if (testCase.failure) {
const failureElement = testcaseElement.ele(testCase.failure.kind)
if (testCase.failure.kind === 'failure' && testCase.failure.type) {
Expand Down
6 changes: 6 additions & 0 deletions javascript/src/makeReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const NAMING_STRATEGY = namingStrategy(
NamingStrategyExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED
)

const REQUIREMENT_TAG_PREFIX = "@Req:"

interface ReportSuite {
time: number
tests: number
Expand All @@ -31,6 +33,7 @@ interface ReportTestCase {
time: number
failure?: ReportFailure
output: string
requirements: string[]
}

interface ReportFailure {
Expand Down Expand Up @@ -85,6 +88,9 @@ function makeTestCases(query: Query): ReadonlyArray<ReportTestCase> {
return formatStep(gherkinStep, pickleStep, testStepFinished.testStepResult.status)
})
.join('\n'),
requirements: pickle.tags
.filter(tag => tag.name.startsWith(REQUIREMENT_TAG_PREFIX))
.map(tag => tag.name.substring(REQUIREMENT_TAG_PREFIX.length)),
}
})
}
Expand Down
Loading