1

I have setup Jake Wharton's double espresso testing utility in my Android project but when I run the test class I get the following error:

junit.framework.AssertionFailedError: Exception in constructor: testClickActionBarItems (java.lang.NoClassDefFoundError: com.example.android.activities.TrialActivity at com.example.android.activities.TrialActivityTest.(TrialActivityTest.java:23)

My test class is as follows:

@LargeTest
public class TrialActivityTest extends ActivityInstrumentationTestCase2<TrialActivity>{
@SuppressWarnings("deprecation")
public SectionsEspressoTest() {
    super(TrialActivityTest.class);
}

@Override
public void setUp() throws Exception {
    super.setUp();
    // Espresso will not launch our activity for us, we must launch it via getActivity().
    getActivity();
}

public void testClickActionBarItems() {
    onView(withId(R.id.action_search))
            .perform(click());

}
}

I have added the necessary components to my build.gradle file:

testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"

    androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
    exclude group: 'org.hamcrest'
}

androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') {
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'org.hamcrest'
}

The groups above are excluded as they are used in other libraries in my project. I'm using version gradle 0.10 and Android Studio 0.5.8. If anyone has any idea what I'm doing wrong I'd greatly appreciate the help.

chuckliddell0
  • 2,061
  • 1
  • 19
  • 25

1 Answers1

0

Not sure if this will completely resolve the issue, but you test constructor should call super like this:

public TrialActivityTest(){
    super(TrialActivity.class);
}
yogurtearl
  • 3,035
  • 18
  • 24
  • 1
    Thanks for looking at the question. Changing the constructor like you suggested has no effect on the problem. – chuckliddell0 Jun 19 '14 at 08:36
  • See my questions in the comment section above. – yogurtearl Jun 19 '14 at 13:18
  • Hey @yogurtearl I've narrowed this issue down to a dependency issue with another testing library called Fest. I have posted a separate question for it. http://stackoverflow.com/questions/24330639/android-testing-java-lang-noclassdeffounderror-error-due-to-fest-android?noredirect=1#comment37610540_24330639 – chuckliddell0 Jun 20 '14 at 15:32