Search code examples
androidunit-testingrobotiumtestcaseandroid-instrumentation

Put multiple “testXXX()” functions in a Android UnitTest Class


I maked Android UnitTest by Robotium(a support tool that help to test UI).When one Test class only include one “testXXX()” function,it was successful.But when I put multiple “testXXX()” functions in a Android UnitTest Class.
I want to these functions was excuted one by one until all test functions was end successful,but error occurred one by one so that the test task can not be completed successfully. I know that while a test completed ,it will excute super.tearDown().So I delete it,but not work.

public class TestServerMonitor extends ActivityInstrumentationTestCase2<ServerMonitorActivity> {
private Solo solo;
private SharedPreferences mSharedPreferences;
private long nowTime;
private long installTime;
private String version;

public TestServerMonitor() {
    super(ServerMonitorActivity.class);
}

public void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation());
    getActivity();
    mSharedPreferences = getActivity().getSharedPreferences(com.luckyxmobile.servermonitor.
                    activity.SettingsActivity.PREFS_NAME,
            0);
    //current time
    nowTime = System.currentTimeMillis();
    //install time
    installTime = mSharedPreferences.getLong(
            ServerMonitor.INSTALL_TIME, nowTime);
    //get version
    try {
        version = getActivity().getPackageManager().
                getPackageInfo(getActivity().getPackageName(), 0).versionName;
    } catch (Exception e) {
        version = null;
        e.printStackTrace();
    }

}

@Override
public void tearDown() throws Exception {
    solo.finishOpenedActivities();
    super.tearDown();
}

public void testAddServer() {
    ......
}
public void testAddWebsite() {
    ......
}
public void testEditServer() {
    ......
}
public void testEditWebSite() {
    ......
}

}


Solution

  • add solo.goBackActivity("activity 's name"),it work