Eugene
Eugene

Reputation: 60224

Is tearDown() supposed to run after each test?

I thought the tearDown() is supposed to run after each test, but what I see from logs is that it is started just after setUp() method. Can you guys clarify?

public class LaunchManagerActivityTest extends ActivityInstrumentationTestCase2<LaunchManagerActivity> {
    private Solo solo;

    public LaunchManagerActivityTest() {
        super(LaunchManagerActivity.class);

    }

    protected void setUp() throws Exception {
        super.setUp();
        Log.e("Dev", "setup");

        solo = new Solo(getInstrumentation(), getActivity());

    }

    protected void tearDown() throws Exception {
        super.tearDown();
        Log.e("Dev", "tearDown  ");

    }

Output:

02-11 11:33:33.095: E/Dev(26779): setup
02-11 11:33:34.395: E/Dev(26779): tearDown 

Upvotes: 5

Views: 5492

Answers (2)

kofemann
kofemann

Reputation: 4423

I suppose this is JUnit3. The tearDown runs after each test. Do you have any test in your test file? JUnit will run only tests defined in the current class..

Upvotes: 0

Paul Harris
Paul Harris

Reputation: 5819

You have no tests in the class you posted so it just ran setup and then teardown. That is the expected behaviour, if you had any test it would run:

constructor()
setUp();
testXXX();
tearDown();

if you had two tests it would run

constructor()
setUp();
testXXX();
tearDown();

setUp();
testXXX2();
tearDown();

Remember a test in junit 3 (which android uses) has to start with the word test and be in the same class.

to test what i said add the following methods in:

public void testXXX(){
    Log.d("Dev", "testXXX  ");
}

public void testXXX2(){
    Log.d("Dev", "testXXX2  ");
}

Upvotes: 8

Related Questions