我需要编写一个 UI 测试来验证单击 float 操作按钮是否会导致显示 SecondActivity。
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);
@Before
public void setUp() throws Exception {
}
@Test
public void onClick() throws Exception {
onView(withId(R.id.button)).perform(click());
}
}
够了吗?
我如何验证 Activity 是否正确显示传入对象的文本内容:姓名、年龄、电话号码?
我刚开始使用 Espresso (
最佳答案
Is it enough?
不,这还不够。这段代码
onView(withId(R.id.button)).perform(click());
仅对按钮执行单击,但之后没有任何东西可以验证应用程序是否正确运行。
要验证打开 SecondActivity 的 Intent 是否已创建,您需要使用 Espresso Intents .
how can I validate that the Activity properly displays the text contents of an incoming object
你可以使用类似的东西:
onView(withId(R.id.textView)).check(matches(withText("Expected text")));
看看 Espresso Cheatsheet了解更多。
关于android - 编写 Android Espresso 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44810315/