2012-10-08 39 views
1

我在項目中遇到了測試問題。我已經正確配置了依賴關係,但我無法使用Robotium運行測試。當我的活動剛好延伸活動 - 一切都很好,當我添加「擴展SherlockActivity」後來我Robotium和Sherlock - NoClassDefFoundError

java.lang.RuntimeException: Exception during suite construction 
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238) 

Caused by: java.lang.NoClassDefFoundError: com.calculator.Main (example project from Robotium www). 

我試圖在的IntelliJ和Eclipse運行測試。兩個IDE都有同樣的結果。

編輯:這是我的清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.calculator.test" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 

    <uses-library android:name="android.test.runner" /> 
    </application> 
    <uses-sdk android:minSdkVersion="8" /> 
    <instrumentation android:targetPackage="com.calculator" android:name="android.test.InstrumentationTestRunner" /> 
</manifest> 

回答

1

它看起來像你使用正確的依賴項編譯你的類,但在運行時沒有指定它們。由於IntelliJ和Eclipse都應該使用相同的配置來運行,比如編譯,問題是:您是如何運行測試的?

+0

在Intellij中沒有很多關於運行配置的選項。我已經把它設置爲用測試開始一堂課。我已經在上面添加了清單。奇怪的是,「TestMain擴展活動」的作品,但「TestMain擴展SherlockActivity」不 – user1728732

0

這對您使用的任何編輯器都沒有問題。

這裏是一般語法開始從亞行外殼的任何活動:

adb shell am start -a android.intent.action.MAIN -n com.package.name/com.package.name.ActivityName 

所以,當你從robotium它必須調用的任何活動「延伸活動」。

和「擴展SherlockActivity」不適用於robotium,因爲上述語法只需要活動名稱。所以,如果你擴展任何其他的東西,它將無法工作。

注:

[1]首先嚐試與語法打開你的活動波紋管

adb shell am start -a android.intent.action.MAIN -n com.calculator/com.calculator.Main 

這裏 「主」 是你的包 「com.calculator」 活動。

[2]如果這個工作適合你,那麼它將適用於robotium。

我希望這個概念能幫助你。謝謝。

+0

我可以使用上面的代碼運行我的應用程序,但我仍然不知道它是如何幫助我。你能更詳細地描述點[2]嗎?我如何在Eclipse/Intellij中使用它? 當我想手動運行它不起作用(與上面相同的錯誤 - NoClassDefFoundError)。代碼: adb shell am instrument -w com.calculator.test/android.test.InstrumentationTestRunner – user1728732

+0

首先嚐試執行「adb shell am start -a android.intent.action.MAIN -n com.calculator/com.calculator.Main 「從命令提示符。如果它運行然後與機器人去。因爲當你嘗試使用robotium代碼啓動任何活動時,它首先遵循「adb shell am start -a android.intent.action.MAIN -n com.calculator/com.calculator.Main」。 –