问题
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
回答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.
来源:https://stackoverflow.com/questions/51844639/how-to-add-data-to-testcase-with-junit-and-maven-surefire-plugin