Skip to content

Repository files navigation

Build Status

Android Test Rules

A collection of runtime conditions for ignoring Android Tests.

How to conditionally ignore a test

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

How to add to your project

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();

How to contribute

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'.

About

A collection of conditions for ignoring Android tests based on device characteristics

Resources

Stars

50 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages