3

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.

eric
  • 73
  • 5

1 Answers1

0

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

JoachimR
  • 5,150
  • 7
  • 45
  • 50
  • Hi, I had the same issue. Then I add all libraries that were used in main project to lib folder in test application. Is it possible add these libraries as Maven dependencies ? – Rukmal Dias Jun 19 '14 at 06:17