Different espresso tests for different devices

Viewed 202

I have an app with different layouts - for tablets, normal portrait and small. How can I write and execute different test suites for each device type ?

1 Answers

Annotating your tests with conditions that must evaluate to true in order to run is one way to do it. The repository Android Test Rules helps you do it like this:

@Test
@IgnoreWhen(device = Form.Tablet.class)
public void phoneCanMakeACall() {
    // Run test that only applies to phones.
}

Just follow the steps in the README. Those steps also show you how to create more conditions to add to the ones already provided.

Notes:

  • I am using it in a small project and I can confirm that it works as expected.
  • Since using the @IgnoreWhen annotation more than once for a test method is not possible, I haven't yet figured out how to combine my custom conditions with the ones already provided without copying and pasting their logic into my code.
Related