I'm testing my app's Login with Robotium and I'm having some problems. I've got two different user types so I've made 3 tests. One for each type and another failed login. If I execute them individually they all success, but if I run all the test case it runs one, executes the tearDown(solo.finishOpenedActivities) and it doesn't restart the activity to execute the other tests. So in the second test when I'm asking for a EditText it says that is not available.
Here is my code:
public class TestLogin extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public TestLogin() {
super("com.truekke4.test", MainActivity.class);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
super.setUp();
}
@Override
public void tearDown() throws Exception {
getActivity().logout();
solo.finishOpenedActivities();
super.tearDown();
}
public void testUsuarioDesconocido() {
solo.clearEditText(0);
solo.enterText(0, "usuario desconocido");
solo.assertCurrentActivity("Error", MainActivity.class);
solo.clickOnButton("OK");
solo.clickOnButton("OK");
solo.assertCurrentActivity("Error", MainActivity.class);
}
public void testUsuario() {
solo.clearEditText(0);
solo.enterText(0, "usuario");
solo.clickOnButton("OK");
solo.assertCurrentActivity("Error", InicioUsuarioActivity.class);
}
public void testEmpresa() {
solo.clearEditText(0);
solo.enterText(0, "empresa");
solo.clickOnButton("OK");
solo.assertCurrentActivity("Error", InicioPymeActivity.class);
}
}
I've got to restart the activity manually? Create and Intent and startActivity(intent)?
I don't have to finish opened activities? Or I have to finish activities but restart them/it in setUp(). How Can I restart or create activities to make recognizeables for Robotium?
Help!