0

使用 TestDroid 运行 Android Instrumentation 测试时,它会输出 JUnit XML。例如,

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuites>
  <testsuite errors="0" failures="1" hostname="Acer Iconia Tab A1-810 - YSF6Y9HE6SQCOJPV" name="ExampleInstrumentedTest" package="com.myco.androidtest" tests="2" time="0.0000" timestamp="Fri Sep 29 21:29:49 CEST 2017">
    <testcase classname="com.myco.androidtest.ExampleInstrumentedTest" name="someTest" time="0.0000"/>
    <testcase classname="com.myco.androidtest.ExampleInstrumentedTest" name="someOtherTest" time="0.0000">
      <failure message="" type="">java.lang.AssertionError&#13;
        at org.junit.Assert.fail(Assert.java:86)&#13;
        ...
      </failure>
    </testcase>
  </testsuite>
  <properties>
    ...
    <property name="ro.product.manufacturer" value="Acer"/>
    <property name="ro.serialno" value="32206769320"/>
    <property name="ro.product.name" value="a1-810_ww_gen1"/>
    <property name="ro.build.version.release" value="4.2.2"/>
    <property name="ro.build.version.sdk" value="17"/>
    <property name="ro.build.fingerprint" value="acer/a1-810_ww_gen1/mango:4.2.2/JDQ39/1381313631:user/release-keys"/>
    <property name="ro.product.cpu.abi" value="armeabi-v7a"/>
    <property name="ro.product.model" value="A1-810"/>
  </properties>
</testsuites>

除了有关测试的元数据之外,它们似乎将 Java 系统属性转储到 xml 中,这非常有用。

我想添加到 JUnit XML 中的元数据/属性。关于如何做到这一点的任何想法?

4

1 回答 1

0

它是基于 ddmlib 功能完成的。你应该使用com.android.ddmlib.testrunner.RemoteAndroidTestRunner正确的传递com.android.ddmlib.IDevice和你的实现com.android.ddmlib.testrunner.ITestRunListener(它应该负责收集测试信息和生成junit xml)到run方法,一旦测试完成,你可以生成xml并转储到文件,com.android.ddmlib.IDevice#getProperties最后添加。

于 2017-10-06T14:42:20.963 回答