[英]No test found message using Espresso
I have a simple test in Espresso. 我在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 . 错误:未指定Instrumentation runner类 。
I also declared it the gradle file. 我还宣称它是gradle文件。
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/ 请查看
Espresso
设置说明: 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
underExtras
(see instructions ).确保您已在
Extras
下安装了最新的Android Support Repository
(请参阅说明 )。Open your app's
build.gradle
file.打开应用程序的
build.gradle
文件。 This is usually not the top-levelbuild.gradle
file butapp/build.gradle
.这通常不是顶级的
build.gradle
文件,而是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.)有关更多
artifacts
(espresso-contrib
,espresso-web
等),请参阅(下载)[ https://google.github.io/android-testing-support-library/downloads/index.html]部分。
You're already missing these two dependencies in your build.gradle
file. 您已经在
build.gradle
文件中遗漏了这两个依赖build.gradle
。
Your Gradle
's dependencies should look like: 您的
Gradle
依赖项应如下所示:
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 希望它会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.