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 
Eugene
  • 59,186
  • 91
  • 226
  • 333

2 Answers2

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  ");
}
Paul Harris
  • 5,769
  • 1
  • 25
  • 41
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..

kofemann
  • 4,217
  • 1
  • 34
  • 39