Question

I have an android app that I am unit testing. I have 4 test classes each with multiple test methods. I run them all at the same time from a test suite. I ran into a problem on the emulator where the test would just freeze in the middle of running the tests. I switched to using an actual device and the problem went away.

Fast forward a few weeks and I'm not having the same problem while running tests on my device. I have been on Google for the last couple days trying to find a solution but nothing I have found has helped.

The Issue
When I try to run all the tests the test will freeze eventually. And by freeze I mean the test itself freezes. I saw one solution that it might be the phone or eclipse. I restarted my phone, updated everything in eclipse including eclipse itself. I tried changing views to see if maybe the eclipse view was not refreshing but none of that helped. I also tried using the junit v4 library instead of v3.

If I run the test methods individually they all run and pass. Its only when I run them all from the test suite that they fail.

The Log
I checked the log and this is what I get:
03-13 12:11:04.526: I/TestRunner(23175): started: testCheckShowDialogEnabled(com.package.name.MainActivityTest)

after that there is nothing else in the log.

On The Device
The app is finished and is removed from the screen. It it not reopened again at the beginning of the next test.

The Code
Here is the code that I think might be relevant. If you need any more code just let me know.

public class AllTests extends TestSuite {
    public static Test suite() {
        TestSuite suite = new TestSuite();

        suite.addTestSuite(MainActivityTest.class);
        suite.addTestSuite(DatabaseHandlerTest.class);
        suite.addTestSuite(ClassOneTest.class);
        suite.addTestSuite(AnotherActivityTest.class);

        return suite;
    }
}

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public MainActivityTest() {
        super("com.package.name", MainActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();


        mMainActivity = getActivity();
        mSolo = new Solo(getInstrumentation(), mMainActivity);
    }

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

        mMainActivity = null;
    }
    // all the test methods
}

All my test classes implement setup() and tearDown() similarly.

Anyone out there know why my tests keep freezing? Any help or suggestions are greatly appreciated.

Was it helpful?

Solution

@smk pointed me in the direction to find a solution to this. I just changed my tearDown() to this:

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

Now it works great!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top