简体   繁体   中英

No test found message using Espresso

I have a simple test in Espresso.

public class MainActivityTest {


@Rule
public final ActivityRule<MainActivity> main = new ActivityRule<>(MainActivity.class);

@Test
public void shouldBeAbleToLaunchMainScreen(){
    onView(withText("Hello")).check(ViewAssertions.matches(isDisplayed()));
   }
}

However,I can't run it. To help understand I am showing you the following picture.

我的测试

Why do I get this message?

Error:Instrumentation runner class not specified .

I also declared it the gradle file.

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

 defaultConfig {
    applicationId "theo.testing.androidespresso"
    minSdkVersion 18
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    
        'proguard-rules.pro'
    }
}
packagingOptions{
    exclude 'LICENCE.txt'
}

}

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'
 androidTestCompile 'com.android.support:support-annotations:24.2.0'

 compile 'com.android.support:appcompat-v7:24.2.0'
 androidTestCompile('com.android.support.test.espresso:espresso-
 contrib:2.2.2') {
    // Necessary to avoid version conflicts
    exclude group: 'javax.inject'
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'support-annotations'
  }


}

Any ideas?

Thanks.

please take a look at Espresso setup instruction: https://google.github.io/android-testing-support-library/docs/espresso/setup/

Especially at this part:

Download Espresso

  • Make sure you have installed the latest Android Support Repository under Extras (see instructions ).

  • Open your app's build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle .

  • Add the following lines inside dependencies:

      androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile 'com.android.support.test:runner:0.5' 

See the (downloads)[ https://google.github.io/android-testing-support-library/downloads/index.html] section for more artifacts ( espresso-contrib , espresso-web , etc.)

You're already missing these two dependencies in your build.gradle file.

Your Gradle 's dependencies should look like:

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'
 androidTestCompile 'com.android.support:support-annotations:24.2.0'

 compile 'com.android.support:appcompat-v7:24.2.0'
 androidTestCompile 'com.android.support.test:runner:0.5'
 androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
 androidTestCompile('com.android.support.test.espresso:espresso-
 contrib:2.2.2') {
    // Necessary to avoid version conflicts
    exclude group: 'javax.inject'
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'support-annotations'
  }


}

Hope it would help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM