When writing android espresso UI test, is it possible to write parameterized test which accepts data from two different json files to add list of items inside the app? I have seen parameterized tests that take two files and run same test code for junit test but couldn't find any references for android espresso UI test
Asked
Active
Viewed 1,326 times
2 Answers
1
You can do something like:
@RunWith(Parameterized.class)
public class LoginTest {
@Parameterized.Parameter
public String mUserName;
@Parameterized.Parameter(value = 1)
public String mPassword;
@Parameterized.Parameters
public static Collection<Object[]> initParameters() {
return Arrays.asList(new Object[][]{
{"validUsername", "validPassword"},
{"invalidUsername", "invalidPassword"},
// or other initialization like json file input
});
}
// Tests using mUserName and mPassword
}
Then every Test will run with each element of you parameters array.

Traendy
- 1,423
- 15
- 17
-
how can i initialize files inside initParameters? example, i have testData1.json and testData2.json – chang93 May 28 '20 at 07:01
0
Please take a look at the library https://github.com/google/TestParameterInjector , it is very convenient and the next evolution step of JUnit4 Parameterized
.

ultraon
- 2,220
- 2
- 28
- 27
-
-
AFAIK it has issues, but from my experience, exactly one parameterized param (class property) works for one unit test class. – ultraon Mar 20 '22 at 12:08