0

I am trying test an Activity derived from FragmentActivity(from android-support-v4.jar) using ActivityInstrumentationTestCase2. The android-support-v4.jar is located in the libs folder of my main project(tested project). To make the test project pass the build, I add add a link from the main project to the test project with command "ln ../mainProject/libs/android-support-v4.jar ./libs/android-support-v4.jar" in my test project root directory. It is recommended by http://dtmilano.blogspot.com/2009/12/android-testing-external-libraries.html?showComment=1348480869133. Following the guideline from the blog, I can run the test with Eclipse successfully. However, when I try to run the test with command "ant clean debug install test", I will always met the below exception:

[exec] android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:
[exec] Error in testSuiteConstructionFailed:
[exec] java.lang.RuntimeException: Exception during suite construction
[exec]     at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
[exec]     at java.lang.reflect.Method.invokeNative(Native Method)
[exec]     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
[exec]     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
[exec]     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
[exec]     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
[exec] Caused by: java.lang.reflect.InvocationTargetException
[exec]     at com.test.QuestionListActivityTest.<init>(QuestionListActivityTest.java:17)
[exec]     at java.lang.reflect.Constructor.constructNative(Native Method)
[exec]     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
[exec]     at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
[exec]     at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
[exec]     at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
[exec]     at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
[exec]     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
[exec]     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
[exec]     at android.app.ActivityThread.access$3000(ActivityThread.java:125)
[exec]     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
[exec]     at android.os.Handler.dispatchMessage(Handler.java:99)
[exec]     at android.os.Looper.loop(Looper.java:123)
[exec]     at android.app.ActivityThread.main(ActivityThread.java:4627)
[exec]     at java.lang.reflect.Method.invokeNative(Native Method)
[exec]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
[exec]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
[exec]     at dalvik.system.NativeStart.main(Native Method)
[exec] Caused by: java.lang.NoClassDefFoundError: com.activity.QuestionListActivity
[exec]     ... 19 more

Here is the snap of test code:

 public class QuestionListActivityTest extends ActivityInstrumentationTestCase2<QuestionListActivity>{
    private Solo solo;
    private FragmentActivity activity;

 public QuestionListActivityTest() {  
     super(QuestionListActivity.class); **// the exception happened here**
 }
...
}

I am using android sdk R15. The test was run with the emulator. Does anybody know how to solve it? I really need to run it with ant so as to integrate with hudson. Thanks in advance!

George_BJ
  • 596
  • 2
  • 9
  • 21
  • I found a walk around for problem: 1. Use Activity instead of FragmentActivity in the test code. 2. Add the link(ln) during the compile phase(ant debug) of the test project, and then remove the link before the test running phase(ant install test). Then test case can be run successfully. – George_BJ Sep 26 '12 at 03:17
  • possible duplicate of [java.lang.NoClassDefFoundError in android.test.ServiceTestCase](http://stackoverflow.com/questions/5758966/java-lang-noclassdeffounderror-in-android-test-servicetestcase) – mthmulders Feb 04 '14 at 07:47

1 Answers1

1

Have you checked the related issue here?

It is similar to yours.

Community
  • 1
  • 1
dwbrito
  • 5,194
  • 5
  • 32
  • 48