rct29
rct29

Reputation: 21

AndroidJUnit4.class not found on Instrumentation tests

I'm having trouble with AndroidJunit4.class import. I created the test class in the androidTest/java/ folder but it seems that the class is not found.

Even if I force the right import it still doesn't work. ( import android.support.test).

@RunWith(AndroidJunit4.class)
public class RandomTest {

}

Here is my gradle :

defaultConfig {
 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

dependencies {
 compile "com.android.support:support-annotations:23.4.0"
 compile "com.android.support:appcompat-v7:23.4.0"
 compile 'cat.ereza:customactivityoncrash:1.5.0'
 testCompile 'junit:junit:4.12'
 androidTestCompile 'junit:junit:4.12'
 androidTestCompile('com.android.support.test:runner:0.5')
 androidTestCompile('com.android.support.test:rules:0.5')
 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2')
 androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2')
 androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2')

 testCompile('com.android.support.test:runner:0.5')
 testCompile('com.android.support.test:rules:0.5')
 testCompile('com.android.support.test.espresso:espresso-core:2.2.2')
 testCompile('com.android.support.test.espresso:espresso-contrib:2.2.2')
 testCompile('com.android.support.test.espresso:espresso-intents:2.2.2')

 testCompile 'org.mockito:mockito-core:1.10.19'
 testCompile "org.robolectric:robolectric:3.1.1"
}

Weird thing is that I can find AndroidJunit4 file in my project, but in its parent AndroidJunit4ClassRunner, AndroidRunnerParams class is not resolved even if I also can find the file in my Project.

Upvotes: 2

Views: 1524

Answers (1)

roplacebo
roplacebo

Reputation: 2937

Comment out the annotation

//@RunWith(AndroidJunit4.class)

In Android Studio, choose "Build > Rebuild Project"

Get the annotation back in again

@RunWith(AndroidJunit4.class)

ALT-ENTER -> Import class

Upvotes: 0

Related Questions