我正在做一个旧项目,我需要做一些测试。
首先,我将此行添加到了gradle中。
testInstrumentationRunner = 'android.support.test.runner.AndroidJUnitRunner'
然后,我将lib添加到了gradle中
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.2'
androidTestCompile 'com.android.support.test:rules:1.0.2'
androidTestCompile "com.android.support.test.espresso:espresso-core:3.0.2"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:3.0.2"
然后,我编写了一个简单的测试,即打开一个活动并单击一个按钮,这很简单,但是当我运行测试时,我enter code here
会遇到如下错误:
error: package android.support.test.espresso does not exist
error: package android.support.test.filters does not exist
error: package android.support.test.runner does not exist
....
我认为这是因为我当前的 sourceSets 配置:
android {
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
multiDexEnabled true
minSdkVersion 22
targetSdkVersion compile_sdk_version
testInstrumentationRunner = 'android.support.test.runner.AndroidJUnitRunner'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
java.excludes = ['src/androidTest']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileOptions {
encoding encoding_type
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError false
}
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
}
}
dexOptions {
preDexLibraries false
javaMaxHeapSize heap_size
jumboMode true
}
}
在这一点上,我不知道为什么会这样。