1

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

chang93
  • 15
  • 6

2 Answers2

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
  • Maybe a stupid question but is this supported in `AndroidJUnit4`? – Chisko Mar 17 '22 at 23:50
  • 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