且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式创建 JUnit 报告

更新时间:2023-11-15 17:59:04

您粘贴的代码相当于调用 junitreport 任务:

The code you've pasted is the equivalent of calling the junitreport task:

<junitreport todir="..">
<fileset dir="..">
<include name="TEST-*.xml" />
</Fileset>
<report format="frames" todir=".." />
</Junitreport>

你需要把它放到一个方法中并自己运行.此代码将获取所有名为 TEST-*.xml 的文件并使用它们创建报告.它不会创建这些文件.这些文件是由 Ant 中的 junit 任务创建的.所以你需要:

You need to put this into a method and run it yourself. This code will take all files called TEST-*.xml and create a report with them. It will not create those files. Those files are created by the junit task in Ant. So you need to:

  1. 以编程方式运行 junit 任务(参见 JUnitTask (Apache Ant API)),确保在某个临时目录中创建 TEST*.xml 文件.
  2. 运行上述代码以使用这些临时文件生成报告.
  1. Run the junit task programmatically (see JUnitTask (Apache Ant API)), ensuring that the TEST*.xml files are created in a temp directory somewhere.
  2. Run the above code to produce the report, using those temp files.

最简单的方法可能就是您所做的,在某处放置一个 build.xml,然后直接调用 ant.如果您使用的文件集是稳定的,那么这可能是最简单的方法.为此,请使用 ProcessBuilder java 类.

The easiest way to do this is probably what you've done, to have a build.xml somewhere, and invoke ant directly. If the fileset you're using is stable, then this is probably the easiest way to go. Use the ProcessBuilder java class for this.