Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

shazam/androidTestRules

Open more actions menu

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)
public void phoneCanMakeACall() {
    // 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:

@Rule
public ConditionalIgnoreRule conditionalIgnoreRule = new ConditionalIgnoreRule();

How to contribute

Different conditions could be useful for various cases and users. To add a new condition, you can implement the Condition interface:

public class NewCondition implements Condition {
    @Override
    public boolean isSatisfied() {
        // Implementation of condition goes here...
        return conditionIsSatisfied;
    }
}

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.

public class Form {
    public static class Tablet implements Condition {
        @Override
        public boolean isSatisfied() {
            // Decide if this is a tablet;
        }
    }
    public static class Phone implements Condition {
        @Override
        public boolean isSatisfied() {
            // 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

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.