Robotium test cannot find activity class

喜欢而已 提交于 2019-12-10 19:32:18

问题


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.

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

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


回答1:


Make sureafter refactoring:

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

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



来源:https://stackoverflow.com/questions/9677250/robotium-test-cannot-find-activity-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!