本文介绍了如何从TestNG获得一份关于所有测试用例的junit报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TestNG xml文件,其格式如下:

I have a TestNG xml file formatted like this:

<?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

但是我使用的测试用例管理工具需要junit输出,这不是问题,因为TestNG自动生成junit输出.

But I use a test case management tool that requires junit output which shouldn't be a problem since TestNG generates junit output automatically.

问题是这样的:在test-output下的名为junitreports的目录中,每个类都有一个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:

<?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 -->

其中套件名称与类名称相同.如何仅获得一个Junit报告文件以及一组TestNG测试的结果?

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?

推荐答案

应该存在一个名为MySuite的目录,该目录与junitreports在同一级别(基本上是<suite name="MySuite" parallel="tests" thread-count="5">的名称),并且内部是用于所有测试的一种XML.

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.

这是由org.testng.reporters.JUnitXMLReporter生成的,如果不存在,请尝试将此报告程序添加到您的听众中.

This is generated by org.testng.reporters.JUnitXMLReporter if it's not there, try to add this reporter to your listeners.

这篇关于如何从TestNG获得一份关于所有测试用例的junit报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:33