java 在 Eclipse 中运行 JUnit 测试后,我可以将结果导出为 XML 格式。如何使用 JUnit 命令行获取该 xml 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14247610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:36:35  来源:igfitidea点击:

After running JUnit tests in eclipse, I can export the result in XML format. How can I get that xml file using JUnit command line?

javaxmlunit-testingtestingjunit

提问by user358591

I have Java unit tests which I run using JUnit plugin in Eclipse. After all tests are completed in eclipse, I can export the result in .xml format which I use it to upload the results in test result tracking tool.

我有在 Eclipse 中使用 JUnit 插件运行的 Java 单元测试。在eclipse中完成所有测试后,我可以将结果导出为.xml格式,我用它来将结果上传到测试结果跟踪工具中。

Now I am running same tests in AIX system where I am using command line to run JUnit tests.

现在我在 AIX 系统中运行相同的测试,我使用命令行运行 JUnit 测试。

My command is

我的命令是

java org.junit.runner.JUnitCore com.rsa.qa.sae.test.testClassName

Now I want to get results of these tests in a similar XML file.

现在我想在一个类似的 XML 文件中获得这些测试的结果。

How can I get it?

我怎么才能得到它?

回答by sharakan

The base JUnit library doesn't produce reports. Various libraries that run JUnit do (Ant, Eclipse, etc etc).

基本 JUnit 库不生成报告。运行 JUnit 的各种库(Ant、 Eclipse 等)。

If you can't/won't use those tools, then you need to generate the report yourself by implementing a RunListener, and creating your own main method that registers it with JUnitCore. Using that you can generate the XML in whatever form you'd like.

如果您不能/不会使用这些工具,那么您需要通过实现 a 来自己生成报告RunListener,并创建自己的 main 方法将其注册到JUnitCore. 使用它,您可以以您喜欢的任何形式生成 XML。

Similar questions:

类似问题: