A collection of runtime conditions for ignoring Android Tests.
@Test@IgnoreWhen(device = Form.Tablet.class)
publicvoidphoneCanMakeACall() {
// Run test that only applies to phones.
}Simply add a dependency for the instrumentation tests' scope:
dependencies {
androidTestCompile('com.shazam:android-test-rules:1.1.0-SNAPSHOT')
}If you are using a snapshot version also add:
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}Then in a test class where you wish to ignore certain tests, declare the following rule:
@RulepublicConditionalIgnoreRuleconditionalIgnoreRule = newConditionalIgnoreRule();Different conditions could be useful for various cases and users. To add a new condition, you can implement the Condition interface:
publicclassNewConditionimplementsCondition {
@OverridepublicbooleanisSatisfied() {
// Implementation of condition goes here...returnconditionIsSatisfied;
}
}It probably makes sense to organize individual conditions as inner static classes in classes that will act as the dimensions. For example, there could be parent classes like: Form, Architecture, InstalledApps, etc.
publicclassForm {
publicstaticclassTabletimplementsCondition {
@OverridepublicbooleanisSatisfied() {
// Decide if this is a tablet;
}
}
publicstaticclassPhoneimplementsCondition {
@OverridepublicbooleanisSatisfied() {
// Decide if this is a phone;
}
}
}Users of the library can then use code completion after the dimension they're interested in'.