简体   繁体   English

使用Maven的JUnit3和Junit4 XML报告

[英]JUnit3 and Junit4 XML Reports with 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. 我试图弄清楚如何结合Maven使用JUnit(3和4)的假定报告功能,但谷歌搜索在如何实际运行JUnit(通过Maven)的方式上并没有太大的影响,得到一个报告每个测试(或所有测试)以及它将采用何种格式。

So, my multi-part questions is: 所以,我的多部分问题是:

1.) What sort of XML format is JUnit (3/4) capable of outputting? 1.)JUnit(3/4)能够输出什么样的XML格式?

2.) What sort of calling convention/arguments are required for JUnit to output these reports? 2.)JUnit需要什么样的调用约定/参数才能输出这些报告?

3.) Where are the reports output? 3.)报告输出在哪里?

4.) Can these reports be generated while running via Maven or is my only option to use a report that Maven generates? 4.)可以在通过Maven运行时生成这些报告,还是使用Maven生成的报告的唯一选择?

Any links or advice would be greatly appreciated. 任何链接或建议将不胜感激。

The Maven Surefire Plugin is the plugin that runs tests and generates 2 raw reports by default: Maven Surefire插件是运行测试并默认生成2个原始报告的插件:

The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. Surefire插件在构建生命周期的测试阶段使用,以执行应用程序的单元测试。 It generates reports in 2 different file formats: 它以两种不同的文件格式生成报告:

  • Plain text files (*.txt) 纯文本文件(* .txt)
  • XML files (*.xml) XML文件(* .xml)

By default, these files are generated at ${basedir}/target/surefire-reports 默认情况下,这些文件是在${basedir}/target/surefire-reports

The plugin has some parameter allowing to tweak the reports a bit. 该插件有一些参数允许稍微调整报告。 From the surefire:test mojo documentation: surefire:test mojo文档:

  • disableXmlReport : Flag to disable the generation of report files in xml format. disableXmlReport :标记以禁用以xml格式生成报告文件。 Default value is: false. 默认值为: false。
  • reportFormat : Selects the formatting for the test report to be generated. reportFormat :选择要生成的测试报告的格式。 Can be set as brief or plain. 可以设置为简短或简单。 Default value is: brief. 默认值为: brief。
  • trimStackTrace : Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. trimStackTrace :是否将报表中的堆栈跟踪修剪为仅测试中的行,或显示完整跟踪。 Default value is: true. 默认值为: true。

For an HTML format of the report, you can then use the Maven Surefire Report Plugin : 对于报告的HTML格式,您可以使用Maven Surefire报告插件

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 Plugin在${basedir}/target/surefire-reports surefire ${basedir}/target/surefire-reports下解析生成的TEST-*.xml文件,并将它们呈现给DOXIA,从而创建测试结果的Web界面版本。

You can either get the report generated as part of the site generation or by running the standalone surefire-report:report goal. 您可以将生成的报告作为网站生成的一部分生成,也可以运行独立的surefire-report:report目标。 From the Usage page: 使用情况页面:

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: 要在网站生成过程中生成Surefire报告,请在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> 

When the mvn site is invoked, the report will be automatically included in the Project Reports menu as shown in the figure below. 调用mvn site ,报告将自动包含在Project Reports菜单中,如下图所示。

替代文字
(source: apache.org ) (来源: apache.org

Generate the report as standalone 以独立方式生成报告

The Surefire report can also generate the report using its standalone goal: Surefire报告还可以使用其独立目标生成报告:

 mvn surefire-report:report 

A HTML report should be generated in ${basedir}/target/site/surefire-report.html . in ${basedir}/target/site/surefire-report.html生成HTML报告。

替代文字
(source: apache.org ) (来源: apache.org

The Maven Surefire Plugin is what executes a lot of the test reports. Maven Surefire插件执行大量测试报告。

You may also want to look at Cobertura for code coverage. 您可能还想查看Cobertura的代码覆盖率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM