Issue
I want to define unit tests for my classes and am running into the following issue. If I define the unit test inside the androidTest folder (testing with instrumentation) then the test runs normally with valid results. If, however, I define the test inside the test folder (local testing) then running the test generates a message "class not found: "[classname]" Empty test suite". This wouldn't be so bad and I would just run all tests from androidTest, except that I want to use code coverage and Android Studio doesn't allow me to run coverage tests from androidTest, but only from test.
Why isn't Android Studio able to find the unit tests when they are defined in the test folder, but is able to when they are defined in the androidTest folder?
Code:
public class SomeTest{
private Context mInstrumentationCtx;
@Before
public void setup() {
mInstrumentationCtx = InstrumentationRegistry.getTargetContext();
// do some setup actions
}
@Test
public void testFirst() throws Exception {
Assert.assertEquals(true, true);
}
}
Gradle config:
android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
debug {
testCoverageEnabled = true
}
}
testCompile 'junit:junit:4.12'
testCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
Solution
May be not an answer per se
You could try changing
testCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
to
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
which seems to be default runner in recent gradle versions.
It works for me with the latter but fails with the former
Edit:
After some struggle it looks like downgrade to version 2.2.3 is a solution for now, smth must have changed in 2.3 beta that author has used
Answered By - Oleg Bogdanov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.