Eclipse 中的 Android 单元测试 : "Failed to launch test"

标签 android eclipse unit-testing

我刚刚开始尝试在本质上是我的第一个 Android 应用程序中设置一些单元测试。我花了很多时间为此寻找资源,但最终能够拼凑出我希望的正确前进道路。

首先,这就是我所做的。

在 Eclipse 中,我右键单击了我要为其创建测试项目的项目。 我选择了 AndroidTools -> New Test Project 我填写了必要的信息,为新项目选择了 ../MyApp/tests 的位置,并选择 MyApp 作为要测试的项目。其他一切都保留为默认值。

在执行过程中,我收到以下错误信息:

[2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!

但一切似乎都还好。我的测试文件夹中有一个新的源代码树。

所以我尝试通过 RunAs -> Android jUnit 测试来执行它(首先在硬件上,然后在模拟器上)。

在这两次运行中,我在我的 eclipse 控制台中收到了以下内容:

[2011-04-01 08:23:04 - WPMSTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
[2011-04-01 08:23:04 - WPMSTest] Failed to launch test

我的两个 list 文件:

WPMS 测试:

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

<instrumentation android:targetPackage="com.WPMS" android:name="android.test.InstrumentationTestRunner" />
<application android:icon="@drawable/icon" android:label="@string/app_name">

<uses-library android:name="android.test.runner" />
</application>

WPMS:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.WPMS"
  android:versionCode="1"
  android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher_wpms">
    <activity android:name=".WPMS"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>    

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

我希望有人以前见过类似的东西,并且可以阐明我做错了什么。如果您需要更多文件,请告诉我,我一定会发布它们。

谢谢!

最佳答案

我的测试项目中缺少一个测试套件。一旦我的 AllTests 类扩展了 TestSuite,我就克服了错误。

关于Eclipse 中的 Android 单元测试 : "Failed to launch test",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5513491/

相关文章:

java - 从颜色中移除 alpha 但保留其纹理

java - Maven 从终端运行,但不能从 Yosemite 中的 Eclipse 运行

android - ProgressDialog 或 ProgressBar 会减慢运行 Android 4.1 的应用程序

android - 使用指南时在 ConstraintLayout 中正确设置约束

Java继承编译

ruby-on-rails - 如何在 rspec expect 中保存变量?

javascript - Jest.js 模拟模块中的方法

python - 有没有开源工具可以自动为遗留代码生成测试用例?

java - 集成pdk(pinterest sdk)时出错

java - Eclipse 无法启动 chrome 驱动程序