2012-03-13 41 views
3

我一直在使用robotium來測試我的android應用程序。到目前爲止,我發現它非常有用。最近我們做了一個重構,只在整個應用程序中使用一個活動,每個頁面將被一個片段替換。Robotium測試找不到活動類

但是,在我們開始使用該活動來運行單元測試之後,測試會報告NoClassDefound錯誤 - 它找不到活動類。我沒有看到任何地方我改變了配置。

任何人都可以提供一個線索可能是錯的,在哪裏檢查等?

[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應該也可以。

+0

這將有助於獲得manifest.xml。你可以添加它嗎? – BlackHatSamurai 2012-06-18 23:00:32

回答

0

製作sureafter重構:

測試項目的AndroidManifest.xml中仍然是準確的:

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

測試類仍然是準確的:

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

應用程序的所有庫在測試中,只能在libs/yourlibrary.jar中找到(!)並在項目 - >屬性 - > Java構建路徑 - >庫中引用(

+0

嗨,我有同樣的問題。然後,我將主項目中使用的所有庫添加到測試應用程序的lib文件夾中。是否有可能將這些庫添加爲Maven依賴項? – 2014-06-19 06:17:59