jstemmer / go-junit-report

Convert Go test output to JUnit XML
MIT License
763 stars 222 forks source link

feat: populate <skipped> message with last line of test output #158

Open marcuscaisey opened 1 year ago

marcuscaisey commented 1 year ago

This PR sets the <skipped> node's message attribute to the last line of the output from the skipped test.

I've made this change as I came across an issue when trying to integrate this tool with https://github.com/thought-machine/please which only looks at the message attribute of the <skipped> node and not the containing text, so was outputting Skipped as the reason for each skipped test which isn't very helpful.

This seems more the correct behaviour imo since this is how JUnit outputs its XML report:

// AppTest.java
package com.marcuscaisey;

import org.junit.Test;
import org.junit.Ignore;

public class AppTest {
  @Test
  @Ignore("skip message")
  public void shouldBeSkipped() {
      throw new RuntimeException("should not get thrown");
  }
}
<!--TEST-com.marcuscaisey.AppTest.xml-->
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.marcuscaisey.AppTest" time="0.013" tests="1" errors="0" skipped="1" failures="0">
  <properties>
  ...
  </properties>
  <testcase name="shouldBeSkipped" classname="com.marcuscaisey.AppTest" time="0">
    <skipped message="skip message"/>
  </testcase>
</testsuite>

I've left the remaining lines of test output in the text of the <skipped> node. I'm not sure whether it should just contain all of the output lines (or none). I just did it this way to not duplicate info between the message and node text. I don't expect this case to really come up tbh since logging before skipping a test seems a bit odd.