各位大神,小白先有礼了,我刚接触自动化测试,写了如下的自动化测试用例。大体就是:第一个用例测试登录;第二个用例在登陆后的界面下,进行注销。
如果单独运行每一个用例,都没有问题,但是如果两个一起的话,就卡住了。通过logcat看,是卡在了第二个用例的setup阶段。
我查了半天还是不能解决,都说teardown有问题,我改了也不对,求大神帮忙!!代码如下:
package com.aspirecn.microschoolParent.test;
import android.test.ActivityInstrumentationTestCase2;
import com.jayway.android.robotium.solo.Solo;
import android.app.Activity;
import android.util.Log;
@SuppressWarnings("rawtypes")
public class LoginLogoutTest extends ActivityInstrumentationTestCase2{
private Solo solo;
public Log log;
public Activity activity;
private static Class<?> launchActivityClass;
private static String mainActiviy = "com.aspirecn.microschoolParent.MicroschoolParent";
private static String packageName = "com.aspirecn.microschoolParent";
static {
try {
launchActivityClass = Class
.forName(mainActiviy);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public LoginLogoutTest() {
super(packageName, launchActivityClass);
}
@Override
public void setUp() throws Exception {
Log.v("com.aspirecn.microschoolParent.test", "Here SetUp");
super.setUp();
this.activity = this.getActivity();
this.solo= new Solo(getInstrumentation(), getActivity());
}
public void tearDown() throws Exception {
Log.v("com.aspirecn.microschoolParent.test", "Here TearDown");
try {
this.solo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();
}
this.activity.finish();
super.tearDown();
}
public void testLogin()throws Exception{
Log.v("com.aspirecn.microschoolParent.test", "testLogin Start");
solo.waitForText("登录", 1, 10000);
if(solo.searchText("18346192082",true)){
solo.clearEditText(solo.getEditText("18346192082"));
}
solo.enterText(0, "18346192082");
solo.enterText(1, "123456");
solo.clickOnButton("登录");
solo.waitForText("消息", 1, 10000);
assertTrue(solo.searchText("消息",true));
Log.v("com.aspirecn.microschoolParent.test", "testLogin Finish");
}
public void testLogout()throws Exception{
//solo.clickOnImage(0);
Log.v("com.aspirecn.microschoolParent.test", "testLogout Start");
solo.waitForText("设置", 1, 10000);
assertTrue(solo.searchText("设置",true));
solo.clickOnText("设置");
solo.clickOnText("注销");
solo.waitForText("登录", 1, 10000);
assertTrue(solo.searchText("登录",true));
Log.v("com.aspirecn.microschoolParent.test", "testLogout Finish");
}
}
------解决方案--------------------
你怎么启动的这个用例?