Robotium测试无法找到活动课 [英] Robotium test cannot find activity class

查看:104
本文介绍了Robotium测试无法找到活动课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用robotium测试我的android应用。我发现它非常有用的工具为止。最近,我们已经做到了将只使用一个活动在整个应用程序的重构,每个页面将片段所取代。

I have been using robotium to test my android application. I found it very useful tool so far. Recently we have done a refactoring that would use only one activity in the entire application, each page will be replaced by a fragment.

然而,当我们开始使用该活动运行单元测试,测试笙歌NoClassDefound错误 - 它无法找到活动类。我没有看到任何地方我有任何更改配置。

However, After we start using that activity to run the unit tests, the test complains NoClassDefound error -- it couldn't find the activity class. I don't see anywhere I have change the configuration whatsoever.

任何人都可以得到什么线索可能是错误的,在那里检查等?

Can anybody give a clue what might be wrong , where to check and so on ?

[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中应该没问题了。

The app apk is loaded, AndroidManifest.xml should be ok too.

推荐答案

请sureafter重构:

Make sureafter refactoring:

测试项目的Andr​​oidManifest.xml中仍然是准确的:

The AndroidManifest.xml of the test project is still accurate:

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

测试类仍然是准确的:

The Test class is still accurate:

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);
    }
    //..
} 

该应用程序的测试下的所有库只能(!)在库/ yourlibrary.jar发现,在项目 - 引用>属性 - > Java构建Path->库

All libraries of the app under test can only (!) be found in libs/yourlibrary.jar and are referenced in Project->Properties->Java Build Path->Libraries

这篇关于Robotium测试无法找到活动课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆