5

I am running UIAutomation for android using Robotium and ActivityInstrumentationTestCase2. I have a test suite with 5 tests. Sometimes my test randomly crash because a test starts, once the previous test has not ended yet. Is there a way to avoid this? is it possible to manually add a 10 second delay before every test to get away from this horrible annoying bug?

EDIT:

public class MyTest<T extends RoboActivity> extends ActivityInstrumentationTestCase2<T>
{

    protected Solo solo;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

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

        try {
            solo.finalize();
        }
        catch (Throwable e) {
            Assert.fail(e.getMessage()+ e.toString());
            e.printStackTrace();
        }

        super.tearDown();
    }
}
aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

1

Maybe this could work :

mSolo = new Solo(getInstrumentation(), getActivity());
mSolo.waitForActivity(AccountDetail.class);

Seems that waitFor* methods are managing that better than a "sleep" http://robotium.googlecode.com/svn/doc/com/robotium/solo/Solo.html#waitForActivity(java.lang.Class, int)

ıɾuǝʞ
  • 2,829
  • 26
  • 38
0

My tests's construction, teardown, etc. are slightly different and works well (see below). I had to add a sleep to work around some non-deterministic test-failures.

public class AccountDetailTest extends ActivityInstrumentationTestCase2<AccountDetail> {

private Solo solo;

public AccountDetailTest() {
    super("com.bigcorp.breadmaker", AccountDetail.class);
}

@Override
public void setUp() {
    solo = new Solo(getInstrumentation(), getActivity());
    solo.sleep(500); //wait for activity to initialize
}

@SmallTest
public void testDummy() {
    assertNotNull(solo);
}

@Override
public void tearDown() throws Exception {
    solo.finishOpenedActivities();
}
}
Per Christian Henden
  • 1,514
  • 1
  • 16
  • 26