I try to run Kotlin instrumentation tests for android.
In my app/build.gradle:
android {
dataBinding {
enabled = true
You don't have any functions annotated with @Test. This is likely the cause of the issue. I've run my own test using the AndroidJUnit4 runner on a class without @Test functions, and reconstructed this behavior.
The AndroidJUnit4 JUnit4 runner is the cause of this issue, and despite its attempt to provide a detailed message (see the code where the exception is thrown), it gives you a wrong message.
The following are more ways to achieve this error:
@Test
fun willThrowInitializationErrorBecauseReturnsNonUnitValue(): Int {
return 0
}
@Test
fun willThrowInitializationErrorBecauseTakesParameters(param: Int) {
}
The error is generated by the fact that you're writing JUnit4 style tests, and they're expected to conform to JUnit4 semantics, but it would be nice if the error message were more clear.
To make matters worse, if one test function is messed up the runner won't run any tests because the InitializationError is thrown in the constructor of the AndroidJUnit4 class.