I'm trying to run parameterized tests using Android Test Orchestrator. But for some reason parameterized tests won't start. I can run all tests properly without Orchestrator but I need it to clear some data between tests.
This is output from Gradle. It can see all 14 tests but only 12 are executed (missing 2 are parameterized):
Starting 14 tests on Nexus_5X_API_27(AVD) - 8.1.0
Tests on Nexus_5X_API_27(AVD) - 8.1.0 failed: Test run failed to complete. Expected 14 tests, received 12
Test run failed to complete. Expected 14 tests, received 12
Gradle:
android {
defaultConfig {
testInstrumentationRunner "foo.bar.CustomRunner"
}
testOptions {
unitTests.returnDefaultValues = true
execution 'ANDROID_TEST_ORCHESTRATOR'
}
}
dependencies {
androidTestImplementation "com.android.support.test:runner:$runnerVersion"
androidTestUtil "com.android.support.test:orchestrator:$runnerVersion"
}
Test:
@LargeTest
@RunWith(Parameterized::class)
class ParamTest(val param1: String, val param2: String) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Array<Any>> {
return listOf(
arrayOf("param1", "param2"),
arrayOf("param21", "param22")
)
}
}
@Test
fun shouldDoSthWithParams() {
//some test
}
}
EDIT:
As a workaround sealed class can be used:
@LargeTest
@RunWith(AndroidJUnit4::class)
class ParamTest1 : ParamTest("param1", "param2")
@LargeTest
@RunWith(AndroidJUnit4::class)
class ParamTest2 : ParamTest("param21", "param22")
sealed class ParamTest(val param1: String, val param2: String) {
@Test
fun shouldDoSthWithParams() {
//some test
}
}
The issue was fixed in version 1.3.0-beta02 of the androidx.test:runner library. See the AndroidX Test 1.3.0 Beta02 release notes which calls this issue out explicitly as fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With