Skip to content
Advertisement

What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android?

I’m new to Android and I’ve seen example code using these annotations. For example:

@SmallTest
public void testStuff() {
    TouchUtils.tapView(this, anEditTextView);
    sendKeys("H E L P SPACE M E PERIOD");
    assertEquals("help me.", anEditTextView.getText().toString());
}

What does that annotation accomplish?

Advertisement

Answer

As an addition to Davidann’s answer and mainly OP’s question in the comment:

In the context of the code above, does it actually DO anything except leave a note for other developers? Does it enforce anything? Are there any tools that utilizes this annotation? What’s it’s purpose in Android development?

You can run a group of tests annotated with specific annotation.

From AndroidJUnitRunner documentation:

Running a specific test size i.e. annotated with SmallTest or MediumTest or LargeTest:

adb shell am instrument -w -e size [small|medium|large] com.android.foo/android.support.test.runner.AndroidJUnitRunner

You may also setup those params through gradle:


    android {
        ...
        defaultConfig {
            ...
            testInstrumentationRunnerArgument 'size', 'Large'
        }
    }

Via gradle:

-Pandroid.testInstrumentationRunnerArguments.size=small

See Doug Stevenson blog post as well as this blog post for more details.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement