Skip to content

Android:JUnit

안드로이드에서 JUnit으로 테스트하는 방법에 대하여 설명한다.

일반적인 클래스 테스트

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);
    }
}

안드로이드 Activity 테스트방법

여기에서는 Main클래스(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