Is tearDown() supposed to run after each test?
Asked Answered
S

2

5

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 
Stanislas answered 11/2, 2013 at 9:36 Comment(3)
You don't have a testcase. So, this is expected, I believe.Play
Yes, it is called after each testXXX method. Probably your test just does not output anything.Anemo
@RKajaMohideen I think he does have at least one test case hidden in superclass. Otherwise, neither setUp nor tearDown would be called.Anemo
L
8

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  ");
}
Lilas answered 11/2, 2013 at 9:38 Comment(0)
T
0

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..

Twigg answered 11/2, 2013 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.