Reputation: 45
I have been able to run an android junit test with one test method successfully, but when more than one test method are involved, it just runs the first test and after tearDown, the activity does not relaunch for the subsequent tests. As a result, all my test methods fail, save the first one.
On debugging, I noticed that setUp method launches the MainActivity successfully before running the first testMethod, but on being revisited before the start of second testMethod, the same activity does not get relaunched. The code is as below:
package PACKAGE.test;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
public class Login extends ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "*.*.MainActivity";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public Login() throws ClassNotFoundException {
super(launcherActivityClass);
}
private Solo solo;
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
@Test
public void testLoginScreen() {
solo.enterText(0, "user-name");
solo.enterText(1, "pwd");
solo.clickOnButton("Login");
solo.waitForActivity("*.*.*.nextActivity");
solo.clickOnRadioButton(2);
}
@Test
public void testSearch(){
solo.enterText(0, "user-name");
solo.enterText(1, "pwd");
solo.clickOnButton("Login");
solo.waitForActivity("*.*.*.nextActivity");
solo.clickOnRadioButton(1);
}
public void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
}
Upvotes: 0
Views: 790
Reputation: 582
You may need to @Override your teardown method
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
Upvotes: 3