Skip to content

Include value from Exception.stacktrace if available #30

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

Merged
merged 1 commit into from
Mar 23, 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 @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Include value from Exception.stacktrace if available ([#30](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/30), M.P. Korstanje)

### Fixed
- Do not overwrite results of retried tests ([#29](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/29), M.P. Korstanje)

Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[21.0.1,25.0.0)</version>
<version>[24.0.0,25.0.0)</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStart
Optional<String> message = result.getMessage();
Optional<String> exceptionType = result.getException().map(Exception::getType);
Optional<String> exceptionMessage = result.getException().flatMap(Exception::getMessage);
Optional<String> exceptionStackTrace = result.getException().flatMap(Exception::getStackTrace);

if (message.isPresent()) {
boolean hasMessageOrStackTrace = message.isPresent() || exceptionStackTrace.isPresent();
if (hasMessageOrStackTrace) {
writer.writeStartElement(elementName);
} else {
writer.writeEmptyElement(elementName);
Expand All @@ -113,13 +115,21 @@ private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStart
if (exceptionMessage.isPresent()) {
writer.writeAttribute("message", exceptionMessage.get());
}
if (message.isPresent()) {
writer.newLine();
writer.writeCData(message.get());
writer.newLine();
if (hasMessageOrStackTrace) {
if (exceptionStackTrace.isPresent()) {
writer.newLine();
writer.writeCData(exceptionStackTrace.get());
writer.newLine();
} else {
// Fall back to message for older implementations
// that put the stack trace in the message
writer.newLine();
writer.writeCData(message.get());
writer.newLine();
}
}

if (message.isPresent()) {
if (hasMessageOrStackTrace) {
writer.writeEndElement();
}
writer.newLine();
Expand Down