写 Android 浓缩咖啡测试
Write Android Espresso test
我需要编写一个 UI 测试来验证单击浮动操作按钮会导致显示第二个 Activity。
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 是否正确显示传入对象的文本内容:姓名、年龄、phone 号码?
我刚开始使用浓缩咖啡(
Is it enough?
不,这还不够。这段代码
onView(withId(R.id.button)).perform(click());
仅对按钮执行单击,但之后没有任何内容可以验证应用程序是否正常运行。
要验证打开 SecondActivity 的意图是否已创建,您需要使用 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 了解更多信息。
我需要编写一个 UI 测试来验证单击浮动操作按钮会导致显示第二个 Activity。
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 是否正确显示传入对象的文本内容:姓名、年龄、phone 号码?
我刚开始使用浓缩咖啡(
Is it enough?
不,这还不够。这段代码
onView(withId(R.id.button)).perform(click());
仅对按钮执行单击,但之后没有任何内容可以验证应用程序是否正常运行。
要验证打开 SecondActivity 的意图是否已创建,您需要使用 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 了解更多信息。