Issue
I have some Android instrumentation tests with a custom test runner that all seemed to work fine until at some point after I upgraded to Android Studio 2.1, bumped up some library versions, and did some other things over time. Now, my tests don't run anymore with the dreaded Unable to find instrumentation info for: ComponentInfo{} that has been asked about on StackOverflow a million times already.
Upon further investigation, it seems like Android Studio simply doesn't compile my test code, which then means its code is never included, so it can't find the ComponentInfo for the test runner. I verified that by adding compile errors in my test code, which never cause any issues when I try to run a test.
Furthermore, the test code seems to be treated like non-test code in the syntax highlighter? As an example, the test runner imports android.support.test.runner.AndroidJUnitRunner, but runner is highlighted in red as if that library is missing (but it's in the gradle file as androidTestCompile). If I change that to compile, the syntax highlighter is happy. However, the test code shows up in the project view in yellow, like test code would.
I'm not sure what determines what Android Studio compiles for a test. The setup is straightforward. My file hierarchy is
app
+--src
+ +--main
+ | +--java
+ | +--com/package/files
+ |
+ +--androidTest
+ +--java
+ +--com/package/files
In other words, there's app/src/main/java/com/... and app/src/androidTest/java/com.... Both the main app and the tests use the same package.
build.gradle (relevant parts):
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion '24.0.0 rc3'
defaultConfig {
multiDexEnabled = true
applicationId 'com.package'
minSdkVersion 10
targetSdkVersion 23
versionCode 2
versionName '0.8a'
signingConfig signingConfigs.release
testInstrumentationRunner 'com.package.TestRunner'
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
}
}
productFlavors {
}
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
checkReleaseBuilds true
abortOnError true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
[...]
}
apply plugin: 'com.google.gms.google-services'
The run/debug configuration for the test is straightforward as well - it's an Android Test, the instrumentation runner is com.package.TestRunner. I tried cleaning/rebuilding many times.
Solution
The answer is so embarrassing that I shouldn't post it.
The "Build Variant" for all my modules was set to "Release", so none of the test stuff was compiled. Setting it to "Debug" took care of the problem. Would be nice if Android Studio was a bit more vocal about it, like warning about running tests while using the release shards.
Answered By - EboMike
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.