使用 Maven 的 JUnit3 和 Junit4 XML 报告

发布于 2024-09-10 15:32:46 字数 320 浏览 0 评论 0原文

我试图弄清楚如何将 JUnit(3 和 4)与 Maven 结合使用假定的报告功能,但是 Google 搜索并没有太多关于如何实际运行 JUnit(通过 Maven)的信息,请参阅每个测试(或所有测试)的报告及其格式。

因此,我的多部分问题是:

1.)JUnit (3/4) 能够输出哪种 XML 格式?

2.) JUnit 输出这些报告需要什么样的调用约定/参数?

3.) 报告输出在哪里?

4.) 这些报告可以在通过 Maven 运行时生成吗?还是我使用 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.) What sort of XML format is JUnit (3/4) capable of outputting?

2.) What sort of calling convention/arguments are required for JUnit to output these reports?

3.) Where are the reports output?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知所踪 2024-09-17 15:32:46

Maven Surefire 插件 是运行测试并生成 2 个原始报告的插件默认:

Surefire插件在
构建生命周期的测试阶段
执行单元测试
应用。它在 2 内生成报告
不同的文件格式:

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

默认情况下,会生成这些文件
${basedir}/target/surefire-reports

该插件有一些参数允许稍微调整报告。来自 surefire:test mojo 文档:

对于 HTML 格式的报告,您可以使用 Maven Surefire 报告插件< /a>:

Surefire 报告插件解析 ${basedir}/target/surefire-reports 下生成的 TEST-*.xml 文件,并将它们呈现给 DOXIA,DOXIA 创建 Web接口版本测试结果。

您可以在网站生成过程中生成报告,也可以通过运行独立的 surefire-report:report 目标来生成报告。从 用法 页面:

生成报告作为项目报告的一部分

生成 Surefire 报告为
网站生成的一部分,添加
以下部分
您的 POM:

<前><代码><项目>;
...
<报告>
<插件>
<插件>
org.apache.maven.plugins
maven-surefire-report-plugin;
<版本>2.5



...

当调用mvn site时,
报告将自动包含在内
项目报告菜单中,如图所示
如下图所示。

替代文本
(来源:apache.org)

独立生成报告

Surefire报告还可以生成
该报告使用其独立目标:

mvn Surefire-report:报告  

应在中生成 HTML 报告
${basedir}/target/site/surefire-report.html

替代文本
(来源:apache.org)


The Maven Surefire Plugin is the plugin that runs tests and generates 2 raw reports by default:

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:

  • Plain text files (*.txt)
  • XML files (*.xml)

By default, these files are generated
at ${basedir}/target/surefire-reports

The plugin has some parameter allowing to tweak the reports a bit. From the surefire:test mojo documentation:

  • 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.

For an HTML format of the report, you can then use the Maven Surefire Report Plugin:

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.

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:

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>

When the mvn site is invoked, the
report will be automatically included
in the Project Reports menu as shown
in the figure below.

alt text
(source: apache.org)

Generate the report as standalone

The Surefire report can also generate
the report using its standalone goal:

mvn surefire-report:report  

A HTML report should be generated in
${basedir}/target/site/surefire-report.html
.

alt text
(source: apache.org)

森林散布 2024-09-17 15:32:46

Maven Surefire 插件 执行大量测试报告。

您可能还想查看 Cobertura 的代码覆盖率。

The Maven Surefire Plugin is what executes a lot of the test reports.

You may also want to look at Cobertura for code coverage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文