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.*;

public @interface MyAnnotation {


After this, just annotate your test method:

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:


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:

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

Happy Testing!