0
我已经能够成功运行一个测试方法的android junit测试,但是当涉及多个测试方法时,它只运行第一个测试,在tearDown之后,活动执行对于后续测试不会重新启动。结果,我的所有测试方法都失败了,保存了第一个。Robotium:第二次测试没有启动
在调试时,我注意到setUp方法在运行第一个testMethod之前成功启动了MainActivity,但是在第二个testMethod启动之前重新访问,同样的活动没有得到重新启动。代码如下:
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();
}
}
它看起来OK。无论如何@Test注解是junit4注释。我确定,在android上没有办法运行junit4。你使用junit 3还是junit4? – maszter 2013-03-17 18:27:01
你为什么叫super.tearDown();?它不在机器人的入门页面中调用。和super.setUp(); – 2013-03-18 09:30:55
对迟到的答复道歉!还没有习惯于stackoverflow的方式! – MMehta 2013-04-24 19:11:05