運行的TestCase我在 在androidTest文件夾中創建一個測試用例作爲MyHomeActivityTest.Java /app/src/androidTest/java/MyHomeActivityTest.javaButterKnife錯誤而androidstudio
而且我有一個HomeActivity.java類在 /app/src/main/java/HomeActivity.java
在我的HomeActivity.java類中,我正在使用butterknife進行視圖注入。我正在MyHomeActivityTest.java中運行HomeActivity的測試用例。
但是當我運行測試用例時,測試運行良好,但獲得了butterknife的NoClassDefFound錯誤。
我的項目類是
MyHomeActivityTest.java
public class HomeActivityTest extends ActivityInstrumentationTestCase2<HomeActivity> {
private Solo solo;
public HomeActivityTest() {
super(HomeActivity.class);
}
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation());
getActivity();
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
public void testRun() {
solo.assertCurrentActivity("Home activity class",HomeActivity.class);
final LinearLayout homeScreen =
(LinearLayout) solo.getCurrentActivity().findViewById(R.id.home_screen);
assertEquals(View.GONE, homeScreen.getVisibility());
}
}
的build.gradle
dependencies{
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.squareup.picasso:picasso:1.1.1'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
}
一旦我運行它給我MyHomeActivityTest類NoClassDefFoundError的,因爲超類的這是使用butterKnife的HomeActivity.class。
我試圖在依賴關係文件夾中添加測試依賴項,就像這個androidTestcompile'com.jakewharton:butterknife:5.1.1',但仍然沒有結果!同樣的錯誤 – anand 2014-09-05 08:08:09