Tips&Tricks: Using annotations in Android instrumentation tests

Bitbar, the mobile devops company. Logo, large

Using annotations in Android instrumentation tests

The Android InstrumentationTestRunner allows you to filter test runs from the specific Java package or class, and in addition, you can also use custom Java annotations in your test methods to filter tests runs.

Create a custom annotations

All you have to do is to create a class like this:

package com.testdroid.test.annotations;
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {

}

After this, just annotate your test method:

@MyAnnotation
public void testButtonClick() throws Exception {
/*
test code
*/

When running your tests in Testdroid Cloud, open Advanced options ->  Test case options (under Step #4 when creating a test run) and define your annotation class in the Test cases with specific annotations:

Selection_038

Tests are then executed including or excluding given annotation used in these configurations. Also, annotations can be mixed with packages or classes. Those settings are also available from Testdroid Run in Cloud plug-in with Jenkins:

Selection_041
In case you are interested to try this out with a working example, here is an example of annotations within Eclipse project.

Happy Testing!

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close