使用Maven的JUnit3和Junit4 XML报告 [英] JUnit3 and Junit4 XML Reports with Maven
问题描述
我正在试图弄清楚如何结合Maven使用JUnit(3和4)的假设报告功能,但谷歌搜索在如何实际运行JUnit(通过Maven)的方式上并没有太大的影响,获得每个测试(或所有测试)的报告以及它将采用的格式。
I am trying to figure out how to use the supposed reporting capabilities of JUnit (3 and 4) in conjunction with Maven, but Google searches aren't turning up much in the way of how to actually run JUnit (via Maven), get a report for each test (or all tests) and what format it will be in.
所以,我的多部分问题是:
So, my multi-part questions is:
1。)JUnit(3/4)能够输出什么样的XML格式?
1.) What sort of XML format is JUnit (3/4) capable of outputting?
2。)什么样的调用JUnit需要约定/参数来输出这些报告吗?
2.) What sort of calling convention/arguments are required for JUnit to output these reports?
3。)报告输出在哪里?
3.) Where are the reports output?
4.。)这些报告可以在通过Maven运行时生成,还是我唯一选择使用Maven生成的报告?
4.) Can these reports be generated while running via Maven or is my only option to use a report that Maven generates?
任何链接或建议都将不胜感激。
Any links or advice would be greatly appreciated.
推荐答案
Maven Surefire插件是运行测试的插件d默认生成2个原始报告:
The Maven Surefire Plugin is the plugin that runs tests and generates 2 raw reports by default:
Surefire插件在构建生命周期的
测试阶段使用到
执行
应用程序的单元测试。它以2
不同的文件格式生成报告:
The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in 2 different file formats:
- 纯文本文件(* .txt)
- XML文件(* .xml)
默认情况下,这些文件在<$ c $生成
c> $ {basedir} / target / surefire-reports
By default, these files are generated
at ${basedir}/target/surefire-reports
该插件有一些参数允许调整报告了一下。来自 surefire:test
mojo文档:
The plugin has some parameter allowing to tweak the reports a bit. From the surefire:test
mojo documentation:
-
disableXmlReport
:标记以禁用xml中的报告文件生成格式。 默认值为: false。 -
reportFormat
:选择要生成的测试报告的格式。可以设置为简短或简单。 默认值为:简短。 -
trimStackTrace
:是否将报表中的堆栈跟踪修剪为仅测试中的行或显示完整的痕迹。 默认值为: true。
disableXmlReport
: Flag to disable the generation of report files in xml format. Default value is: false.reportFormat
: Selects the formatting for the test report to be generated. Can be set as brief or plain. Default value is: brief.trimStackTrace
: Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. Default value is: true.
对于报告的HTML格式,您可以使用< a href =http://maven.apache.org/plugins/maven-surefire-report-plugin/ =nofollow noreferrer> Maven Surefire Report Plugin :
For an HTML format of the report, you can then use the Maven Surefire Report Plugin:
Surefire Report Plugin解析
$ {basedir}下生成的
并将它们呈现给DOXIA,这将创建测试结果的Web界面版本。TEST - *。xml
文件/ target / surefire-reports
The Surefire Report Plugin parses the generated
TEST-*.xml
files under${basedir}/target/surefire-reports
and renders them to DOXIA which creates the web interface version of the test results.
您可以获取作为网站生成的一部分生成的报告,也可以运行独立的 surefire-report:report
目标。来自使用情况页面:
You can either get the report generated as part of the site generation or by running the standalone surefire-report:report
goal. From the Usage page:
作为项目报告的一部分生成报告
生成Surefire报告为
在网站生成的一部分,在您的POM的
部分中添加以下
:
Generate the report as part of Project Reports
To generate the Surefire report as part of the site generation, add the following in the section of your POM:
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</reporting>
...
</project>
当调用 mvn网站
时,
报告将自动包含在项目报告菜单中的
,如下图所示
。
When the mvn site
is invoked, the
report will be automatically included
in the Project Reports menu as shown
in the figure below.
Surefire报告还可以使用其独立目标生成
报告:
The Surefire report can also generate the report using its standalone goal:
mvn surefire-report:report
应在
$ {basedir} /target/site/surefire-report.html 中生成的HTML报告。
A HTML report should be generated in
${basedir}/target/site/surefire-report.html
.
这篇关于使用Maven的JUnit3和Junit4 XML报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!