【问题标题】:Robotium test cannot find activity classRobotium 测试找不到活动类
【发布时间】:2012-03-29 10:53:03
【问题描述】:

我一直在使用 robotsium 来测试我的 android 应用程序。到目前为止,我发现它非常有用。最近我们做了一个重构,在整个应用程序中只使用一个活动,每个页面将被一个片段替换。

但是,在我们开始使用该活动来运行单元测试后,测试报告 NoClassDefound 错误——它找不到活动类。我没有看到任何我更改配置的地方。

任何人都可以提供线索可能是什么问题,在哪里检查等等?

[INFO]     java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(T  estSuiteBuilder.java:239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
....
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: com.xxx.wallet.HaloActivity
at com.xxx.wallet.HaloActivityTest.<init>(HaloActivityTest.java:12)
... 18 more

应用 apk 已加载,AndroidManifest.xml 也应该没问题。

【问题讨论】:

  • 拥有 manifest.xml 会有所帮助。可以加一下吗?

标签: android unit-testing android-activity robotium


【解决方案1】:

确保重构后:

测试项目的AndroidManifest.xml还是准确的:

<instrumentation android:targetPackage="package.of.the.app.under.test">

Test 类仍然准确:

public class YourTest extends ActivityInstrumentationTestCase2<SplashScreenActivity> {
    protected static final String TARGET_PACKAGE_ID = "package.of.the.app.under.test";

    protected Solo solo;
    public Test() {
        super(TARGET_PACKAGE_ID, StartingActivityOfYourAppUnderTest.class);
    }
    //..
} 

被测应用的所有库只能(!)在 libs/yourlibrary.jar 中找到,并在 Project->Properties->Java Build Path->Libraries 中引用

【讨论】:

  • 嗨,我遇到了同样的问题。然后我将主项目中使用的所有库添加到测试应用程序的 lib 文件夹中。是否可以将这些库添加为 Maven 依赖项?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 1970-01-01
相关资源
最近更新 更多