生成JUnit报表使用的XML文件 [英] Generate XML Files Used by JUnit Reports

查看:258
本文介绍了生成JUnit报表使用的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式创建由JUnit/TestNG生成的测试报告.因此,这排除了ANT.我主要关心的是生成XML文件,这些文件由Junit在执行测试用例时创建.我已经读过RunListener可以帮助我实现这一目标,但是我还无法弄清楚如何实现?我正在使用Selenium创建我的测试用例.

I want to create test reports generated by JUnit / TestNG PROGRAMMATICALLY. So, that rules out ANT. My main concern is to generate XML files which are created by Junit while executing test cases. I'have read that RunListener could help me achieve that, but i havn't been able to figure out how ? I'm using Selenium to created my test cases.

如何生成由JUnit创建的XML文件?

How can i generate XML files which are created by JUnit ?

推荐答案

JUnit不会生成XML报告. JUnit没有标准的XML输出格式.

JUnit does not generate XML reports. There isn't a standard XML output format for JUnit.

其他工具会生成XML,例如Ant/Maven.因此,您需要做的第一件事就是确定所需的XML文件格式,就像创建文件后要处理的文件一样.

Other tools generate XML, such as Ant/Maven. So the first thing you need to do is to decide which form of XML file you want, as in what you want to do with the files once you've created them.

实际上,您对程序的限制并不排除ANT.您可以以编程方式调用ant(请参见从以下位置调用ant Java,然后在蚂蚁终止后返回到Java ).这可能是生成与ant兼容的文件的最简单方法.

And, actually, your restriction of programmatically doesn't rule out ANT. You can invoke ant programmatically (see Invoke ant from java, then return to java after ant termination). This would probably be the easiest way to generate files which are ant-compatible.

如果您希望创建自己的XML文件,则可以创建扩展 RunListener ,然后通过调用

If you wish to create your own XML files, then you can create a class which extends RunListener, and then run your tests by invoking JUnitCore#run(), or similar.

public void main(String... args) {
    JUnitCore core= new JUnitCore();
    core.addListener(new RingingListener());
    core.run(MyTestClass.class);
}

您的RunListener只会发出适当的XML.这很容易理解:重写方法testRunStarted()等并写出XML.有关其工作方式的示例,请参见文本监听器,它执行相同的操作,但仅用于文本.

Your RunListener would just emit the appropriate XML. It is fairly easy to understand: override the methods testRunStarted() etc and write out the XML. For an example of how it works, see TextListener, which does the same thing, but for text.

这篇关于生成JUnit报表使用的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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