How to add data to testcase with JUnit and Maven Surefire Plugin

…衆ロ難τιáo~ 提交于 2021-02-11 14:27:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!