sau đây là một trong các trường hợp thử nghiệm Espresso của tôi.Espresso - Làm cách nào để kiểm tra xem một hoạt động có được khởi chạy sau khi thực hiện một hành động nhất định không?
public void testLoginAttempt() {
Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("[email protected]"));
Espresso.onView(ViewMatchers.withId(R.id.username)).perform(ViewActions.clearText()).perform(ViewActions.typeText("invalidpassword"));
Espresso.onView(ViewMatchers.withId(R.id.login_button)).perform(ViewActions.click());
// AFTER CLICKING THE BUTTON, A NEW ACTIVITY WILL POP UP.
// Clicking launches a new activity that shows the text entered above. You don't need to do
// anything special to handle the activity transitions. Espresso takes care of waiting for the
// new activity to be resumed and its view hierarchy to be laid out.
Espresso.onView(ViewMatchers.withId(R.id.action_logout))
.check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
}
Hiện tại, tôi đã kiểm tra xem chế độ xem trong hoạt động mới (R.id.action_logout) có thể hiển thị hay không. Nếu có thể nhìn thấy, tôi sẽ giả định tha hoạt động đã mở thành công. Nhưng nó dường như không hoạt động như tôi mong đợi. Có cách nào tốt hơn để kiểm tra xem một hoạt động mới có được khởi chạy thành công thay vì kiểm tra chế độ xem trong hoạt động đó có hiển thị không? Cảm ơn
Tại sao bạn không nhập ViewMatchers?'nhập static android.support.test.espresso.matcher.ViewMatchers. *' – Roel
@ user2062024 Bạn có thể đăng mã hoạt động không? –
Espresso mới nhất sẽ tự động chờ Asyntask. – WenChao