0

I have a running maven project with JUnit tests. The Maven Surefire Plugin drops xml files after the tests. These xml files include, besides properties and logprints, following information:

<testcase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         name="methodNameForTest"
         classname="com.my.test.project.Testclass"
         time="20.931">
  <error type="java.lang.NullPointerException">java.lang.NullPointerException</error>
  </testcase>

Can someone explain me the usual way how data gets written from JUnit into these brackets and how more data can be added to it?

File search with these words doesn't help btw. Can't find anything in my project.

Thank you in advance

Daniel
  • 127
  • 3
  • 11

1 Answers1

1

You cannot add custom messages into the XML report generated by the maven-surefire-plugin. The closest you can get is by configuring this plugin to redirect your System.out.println() calls to a text file. This is configured in your pom.xml with the help of redirectTestOutputToFile configuration, as shown below:

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
        </configuration>
    </plugin>
</plugins>
</build>

By default, this would create target/surefire-reports/<test-name>-output.txt. Any calls to System.out.println(...) from your tests would get redirected to this file.

Jaywalker
  • 3,079
  • 3
  • 28
  • 44
  • But where does surefire get the data it writes into from? I mean, the values for name, classname and time has to come from somewhere. – Daniel Aug 16 '18 at 12:40
  • It runs your code. So, it knows the class name and the method name. It gets it from your JUnit test class. Or am I missing something in understanding your question? – Jaywalker Aug 16 '18 at 15:19
  • And there's no way to tell it to extend the with more variables? :( – Daniel Aug 17 '18 at 12:28
  • 1
    It's a standard plugin with a standard report layout. If it's working for most of the people, may be you need to rethink why you need custom messages to go into sure fire reports? One of your options could be to use a logger and log the messages to a different file and combine the reports using a custom tool. But once again, think again why you need this. – Jaywalker Aug 17 '18 at 17:05