Skip to content
Search

Android:JUnit

lastmod 2018-08-17created 2015-10-265 edits

Describes how to test with JUnit on Android.

Testing a regular class

public class FirstJunitTest extends AndroidTestCase {
    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    /** JUNIT Library 테스트. */
    public void testPrecondition() {
        assertEquals(true, true);
    }
}

Testing an Android Activity

This section describes how to test the Main class (which extends android.app.Activity).

public class MainTest extends ActivityUnitTestCase<Main> {
    private Intent mStartIntent;

    public MainTest() {
        super(Main.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mStartIntent = new Intent(Intent.ACTION_MAIN);
    }

    @MediumTest
    public void testPrecondition() {
        Log.d("MainTest", "ActivityUnitTestCase test");
    }
}

See also

Favorite site

Tutorials