Activity doesn't restart in different tests with Robotium

0
0

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!

  • You must to post comments
0
0

I believe your issue is being caused because you’re overriding the setUp() method from ActivityInstrumentationTestCase2 rather than using the Robotium method. In your test classes, Robotium looks for a method with the signature public void setUp() to configure its tests, which can get confusing, because it has the same name as the method that can be overridden. I’m not sure of exactly when or how often the protected setUp is called, but I know that the public one is the best place to initialize solo as Robotium is guaranteed to call it before each individual test. Try changing:

@Override
protected void setUp() throws Exception

to:

public void setUp() throws Exception

with the same method body (but without the @Override annotation) and see if that allows you to run all your tests.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website