0

我正在尝试使用 ActivityInstrumentationTestCase2 测试从 FragmentActivity(来自 android-support-v4.jar)派生的 Activity。android-support-v4.jar 位于我的主项目(测试项目)的 libs 文件夹中。为了使测试项目通过构建,我使用命令“ln ../mainProject/libs/android-support-v4.jar ./libs/android-support-v4”添加了一个从主项目到测试项目的链接。 jar”在我的测试项目根目录中。由http://dtmilano.blogspot.com/2009/12/android-testing-external-libraries.html?showComment=1348480869133推荐。按照博客中的指南,我可以使用 Eclipse 成功运行测试。但是,当我尝试使用命令“ant clean debug install test”运行测试时,总是会遇到以下异常:

[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

这是测试代码的快照:

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

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

我正在使用android sdk R15。测试是用模拟器运行的。有人知道如何解决吗?我真的需要用 ant 运行它,以便与 hudson 集成。提前致谢!

4

1 回答 1

1

您是否在这里检查过相关问题?

它与您的相似。

于 2013-01-11T12:38:41.707 回答