google / google/TestParameterInjector

Can't use more than one `TestParameter` annotation with Android Instrumentation tests.

Open
#9 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
428
Forks
38
PR merge metrics
No merged PRs in 30d

Description

When I use only one property with `TestParameter` annotation tests works well.
As soon as I add a 2nd property with `TestParameter` annotation then all tests fail.

After some investigation I've found that `androidx.test.runner.AndroidJUnitRunner.runnerArgs.tests` contains incorrect list of test classes:
- `my.test.MyTestClass#testCheckSmth[boolParam1=false`
- `boolParam2=false]`

And as soon as `TestLoader.doCreateRunner()` tries to create test class instance from string `boolParam2=false]` using reflection it fails later.

It is possible that input parameters incorrectly parsed from test args bundle splitting `my.test.MyTestClass#testCheckSmth[boolParam1=false,boolParam2=false]` by coma.

Test class sample:
```Kotlin
// This is instrumentation test, should run on device or emulator
@RunWith(TestParameterInjector::class)
class MyTestClass {

@TestParameter
var boolParam1 = false

@TestParameter
var boolParam2 = false

@Test
fun testCheckSmth() {
// test body...
}
}
```

When I use the same sample with standard JUnit tests it works well.

Test output:
```
Starting 4 tests on Android_TV_720p_API_Q(AVD) - Q

boolParam2=false] > [Android_TV_720p_API_Q(AVD) - Q] FAILED
java.lang.ClassNotFoundException: Invalid name: boolParam2=false]
at java.lang.Class.classForName(Native Method)

boolParam2=true] > [Android_TV_720p_API_Q(AVD) - Q] FAILED
java.lang.ClassNotFoundException: Invalid name: boolParam2=true]
at java.lang.Class.classForName(Native Method)

boolParam2=false] > [Android_TV_720p_API_Q(AVD) - Q] FAILED
java.lang.ClassNotFoundException: Invalid name: boolParam2=false]
at java.lang.Class.classForName(Native Method)

boolParam2=true] > [Android_TV_720p_API_Q(AVD) - Q] FAILED
java.lang.ClassNotFoundException: Invalid name: boolParam2=true]
at java.lang.Class.classForName(Native Method)

> Task :app:connectedDebugAndroidTest FAILED
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.