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

Eric Palakovich Carr picture Eric Palakovich Carr · Jan 12, 2011 · Viewed 21.3k times · Source

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?

Answer

David Weiser picture David Weiser · Jan 12, 2011

This blog post explains it best. Basically, it is the following:

testing chart

  1. Small: this test doesn't interact with any file system or network.
  2. Medium: Accesses file systems on box which is running tests.
  3. Large: Accesses external file systems, networks, etc.

Per the Android Developers blog, a small test should take < 100ms, a medium test < 2s, and a large test < 120s.

See this page (search for "@SmallTest") on how to specify which tests get run.