在Eclipse中使用自定义InstrumentationTestRunner会导致错误

Spe*_*lEd 6 android unit-testing

我在Eclipse中有一个单独的测试项目,它已经在命令行和Eclipse中成功运行了一段时间.在使用Jenkins运行我的测试时,我遇到了标准InstrumentationTestRunner不以Jenkins支持的xml格式输出的问题.我已经在互联网上阅读使用自定义InstrumentationTestRunner.这在使用ADB的命令行中有效,但在作为Android Test Case运行时在Eclipse中失败.

我已经下载了一个自定义仪器测试运行器(com.neenbedankt.android.test)并将其添加到AndroidManifest中,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testedapplication.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <instrumentation
        android:name="com.neenbedankt.android.test.InstrumentationTestRunner"
        android:targetPackage="com.testedapplication" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>    
</manifest>
Run Code Online (Sandbox Code Playgroud)

这是我在Eclipse中遇到的错误:

没有为运行测试正确配置[Test Project]:找不到AndroidManifest.xml中检测android.test.InstrumentationTestRunner的targetPackage属性!

你可以看到我在那里设置了targetPackage,所以我不确定我还能做什么?

Hui*_*.Li 12

在AndroidManifest.xml中添加两个检测.

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.example.myapp" />

<instrumentation
    android:name=".MyRunner"
    android:targetPackage="com.example.myapp" />
Run Code Online (Sandbox Code Playgroud)

然后转到Package explorer - > $(Your Test Prject $) - > Run As - > Run configurations - > Android JUnit Test - > $(Your Test Project) - > Instrumentation Runner并选择你的跑步者.

  • 我再试一次,似乎不需要android.test.InstrumentationTestRunner.您只需更改"仪表运行器"设置即可. (2认同)
  • 伙计,我喜欢stackoverflow. (2认同)