创建JUnit报告编程 [英] Creating JUnit report programmatically

查看:275
本文介绍了创建JUnit报告编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的做法,现在是从我的应用程序,只需调用Ant构建,它会创建JUnit的报告需要的,但我希望有灵活性,code JUnit的报告编程。

My current approach right now is from my application, just call the ant build and it will create the junit reports needed, but I want to have the flexibility to code junit reports programmatically.

我试过这种方法
<一href=\"http://stackoverflow.com/questions/3916717/antcreate-junit-report-task-programmatically?answertab=votes#tab-top\">Ant:create JUnit的报告任务编程

FileSet fs = new FileSet();
fs.setDir(new File(".."));
fs.createInclude().setName("TEST-*.xml");
XMLResultAggregator aggregator = new XMLResultAggregator();
aggregator.addFileSet(fs);
AggregateTransformer transformer = aggregator.createReport();
transformer.setFormat(Format.FRAMES);
transformer.setTodir(new File("..");

但我甚至不能让它运行。任何更多的想法?

but I can't even get it running. Any more ideas?

推荐答案

在code在粘贴是调用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>

您需要把这个进入的方法和自己运行它。这code将召集所有文件 TEST - *。xml的,并与他们建立一个报告。它将不可以创建这些文件。这些文件由蚂蚁的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任务(见<一href=\"http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/api/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.html\"相对=nofollow> JUnitTask(Apache Ant的API)),确保TEST * .xml文件在一个临时目录中创建的某个地方。

  2. 运行上面的code生产报告显示,使用这些临时文件。

  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.

这篇关于创建JUnit报告编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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