如何使用JUnit和Maven Surefire插件将数据添加到测试用例 [英] How to add data to testcase with JUnit and Maven Surefire Plugin

查看:95
本文介绍了如何使用JUnit和Maven Surefire插件将数据添加到测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的带有JUnit测试的Maven项目.测试后,Maven Surefire插件会删除xml文件.除了属性和日志记录外,这些xml文件还包括以下信息:

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>

有人可以解释我通常的方式如何将数据从JUnit写入这些括号以及如何向其中添加更多数据吗?

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.

提前谢谢

推荐答案

您不能将自定义消息添加到maven-surefire-plugin生成的XML报告中.您可以通过配置此插件将您的System.out.println()调用重定向到文本文件来获得最接近的信息.借助redirectTestOutputToFile配置在您的pom.xml中进行配置,如下所示:

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>

默认情况下,这将创建target/surefire-reports/<test-name>-output.txt.测试中对System.out.println(...)的所有调用都将重定向到该文件.

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.

这篇关于如何使用JUnit和Maven Surefire插件将数据添加到测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆