[英]No test found message using 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()));
}
}
但是,我無法運行它。 為了幫助理解我正在向您展示以下圖片。
為什么我收到此消息?
錯誤:未指定Instrumentation runner類 。
我還宣稱它是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'
}
}
有任何想法嗎?
謝謝。
請查看Espresso
設置說明: https : //google.github.io/android-testing-support-library/docs/espresso/setup/
特別是在這一部分:
下載濃縮咖啡
確保您已在
Extras
下安裝了最新的Android Support Repository
(請參閱說明 )。打開應用程序的
build.gradle
文件。 這通常不是頂級的build.gradle
文件,而是app/build.gradle
。在依賴項中添加以下行:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile 'com.android.support.test:runner:0.5'
有關更多
artifacts
(espresso-contrib
,espresso-web
等),請參閱(下載)[ https://google.github.io/android-testing-support-library/downloads/index.html]部分。
您已經在build.gradle
文件中遺漏了這兩個依賴build.gradle
。
您的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'
}
}
希望它會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.