简体   繁体   English

如何从TestNG获得一份关于所有测试用例的junit报告?

[英]How do I get one junit report from TestNG for all my test cases?

I have a TestNG xml file formatted like this: 我有一个TestNG xml文件,其格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySuite" parallel="tests" thread-count="5">
<parameter name="browser" value="firefox" />
<parameter name="remoteOrLocal" value="local" />
<parameter name="environment" value="####" />
<parameter name="remoteAddress" value="0.0.0.0" />
<test name="1" >
    <classes>
        <class name="tests.Test1"/>
    </classes>
</test>
<test name="2">
    <classes>
        <class name="tests.Test2"/>
    </classes>
</test>
<test name="3">
    <classes>
        <class name="tests.Test3"/>
    </classes>
</test>
</suite

But I use a test case management tool that requires junit output which shouldn't be a problem since TestNG generates junit output automatically. 但是我使用了一个需要用junit输出的测试用例管理工具,这不是问题,因为TestNG自动生成了junit输出。

The problem is this: In the directory under test-output called junitreports, there is one junit report for each class in the following format: 问题是这样的:在test-output下的名为junitreports的目录中,每个类都有一个junit报告,格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
<testsuite hostname="fadavis-HP-EliteBook-8470p" name="tests.Test1" tests="3" failures="1" timestamp="15 May 2015 19:25:12 GMT" time="0.023" errors="1">
  <testcase name="method1" time="0.012" classname="tests.Test1"/>
  <testcase name="method3" time="0.004" classname="tests.Test1"/>
  <testcase name="method2" time="0.007" classname="tests.Test1">
    <error type="java.lang.AssertionError" message="null">
      <![CDATA[java.lang.AssertionError: null
    at org.testng.Assert.fail(Assert.java:94)
    at org.testng.Assert.fail(Assert.java:101)
    at tests.Test1.method2(Test1.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:37)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
    at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
]]>
    </error>
  </testcase> <!-- method2 -->
</testsuite> <!-- tests.Test1 -->

where the suite name is the same as the classname. 套件名称与类名称相同。 How can I get just one Junit report file with the results from a suite of TestNG tests? 我如何只获得一个Junit报告文件以及一组TestNG测试的结果?

There should be directory called MySuite on same level as junitreports (basically name from your <suite name="MySuite" parallel="tests" thread-count="5"> ) and inside is one XML for all tests. 应该有所谓的目录MySuite在同一水平junitreports (从基本的名字<suite name="MySuite" parallel="tests" thread-count="5">和里面的所有测试一个XML。

This is generated by org.testng.reporters.JUnitXMLReporter if it's not there, try to add this reporter to your listeners. 如果不存在此文件,则由org.testng.reporters.JUnitXMLReporter生成,请尝试将此报告程序添加到您的侦听器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取测试类实例JUnit从ClassRunner内部运行测试用例? - How do I get the test class instance JUnit is running test cases on from inside the ClassRunner? 如何从我的testng报告中获取控制台输出? - How do I get the console output out of my testng report? 如何从NetBeans运行所有JUnit测试用例? - How to run all JUnit test cases from NetBeans? 如何在Android的JUnit测试用例中获取MainActivity的上下文和活动? - How do I get the context and activity of MainActivity in JUnit test cases in android? 如何为JUnit中的接口准备测试用例? - How do I prepare test cases for Interfaces in JUnit? 如何为NetBeans中运行的TestNG测试用例生成html报告? - How to generate html report for TestNG test cases run in Netbeans? 如何在 TestNG 报告中显示消息(对于通过的测试用例) - How to display a message in TestNG report (for passed test cases) 从JUnit 4转换为TestNG。 如何处理参数? - Converting from JUnit 4 to TestNG. How do I deal with a parameter? 如何从JUnit测试中的模拟对象获取typeName()? - How do I get typeName() from a mock object in a JUnit test? 如果我没有实现Junit测试用例,可以在Junit中使用Assert类吗? - Can I use Assert class in Junit if I am not implementing Junit test cases and how to do that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM