0
我正在使用robotium測試應用程序。在我的測試班有2個測試:測試不在其他活動機器人中運行
public class MainActivityTestAll extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
private static TestItem item;
private boolean isTimeOut;
private ArrayList<Button> arrButton;
private static final String USER_NAME = "varick";
private static final String PASSWORD = "123456";
private static final String BTN_DISMISS = "Dismiss";
private static final String BTN_OK = "OK";
private static final String BTN_TRYAGAIN = "Try Again";
private static final String BTN_CANCEL = "Cancel";
private static final String BTN_GETSTARTED = "Get Started";
private static final String BTN_EXIT = "Exit";
private static EditText edtName, edtPass;
private View inflaterView;
private Button btnLight, btnSwitch, btnOutlet;
public MainActivityTestAll(String name) {
super(MainActivity.class);
setName(name);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
edtName = (EditText) solo.getView(R.id.edittext_userName);
edtPass = (EditText) solo.getView(R.id.edittext_passWord);
LayoutInflater i = (LayoutInflater) getActivity().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
inflaterView = i.inflate(R.layout.consumer_welcome, null);
isTimeOut = true;
item = new TestItem();
}
@MediumTest
public void test1_DoorLock_Click() throws Exception {
Login();
View view = (View) solo.getView(R.id.fragment_holder);
solo.waitForView(view);
solo.clickOnView(view);
solo.waitForActivity(ConsumerSystemMapDetailPhone.class.getName());
btnLight = (Button) solo.getView(R.id.btnLight);
btnSwitch = (Button) solo.getView(R.id.btnSwitch);
btnOutlet = (Button) solo.getView(R.id.btnOutlet);
assertNotNull(btnLight);
assertNotNull(btnSwitch);
assertNotNull(btnOutlet);
solo.clickOnView(btnLight);
solo.clickOnView(btnSwitch);
solo.clickOnView(btnOutlet);
solo.sleep(2000);
arrButton = solo.getCurrentViews(Button.class,
solo.getView(R.id.consumerzoom_main_container));
assertTrue("DoorLock button had not active", clickonDoorlock(arrButton.get(0)));
}
@MediumTest
public void test2_Switch_Click() throws Exception{
/*
btnLight = (Button) solo.getView(R.id.btnLight);
btnOutlet = (Button) solo.getView(R.id.btnOutlet);
assertNotNull(btnLight);
assertNotNull(btnOutlet);
solo.clickOnView(btnLight);
solo.clickOnView(btnOutlet);
*/
btnSwitch = (Button) solo.getView(R.id.btnSwitch);
assertNotNull(btnSwitch);
solo.clickOnView(btnSwitch);
solo.sleep(2000);
clickonSpinner(1, 3);
solo.sleep(1000);
arrButton = solo.getCurrentViews(Button.class, solo.getView(R.id.consumerzoom_main_container));
clickonSwitch(arrButton.get(0), true, item.getbtnLevel2());
clickonSpinner(0, 1);
clickonSpinner(1, 4);
solo.sleep(1000);
arrButton = solo.getCurrentViews(Button.class, solo.getView(R.id.consumerzoom_main_container));
clickonSwitchInfortop(arrButton.get(0), false, item.getbtnParentLevel8(), item.getbtnLevel3());
exitApp();
}
我的問題是在test1完成測試2後什麼都不做。它仍在運行,但什麼都不做。當我將test2的代碼放入test1時,它運行正常。
我不確定這裏有什麼問題,但我猜測原因是因爲test2不能從MainActivity啓動。
我覺得這不是問題。我也嘗試tearDown(),但它不起作用。 – gamo