繁体   English   中英

适用于Android Studio中活动开关的Espresso单元测试用例

[英]Espresso unit test case for Activity switch in android studio

我想使用Espresso编写单元测试用例,该用例应检查用户是否成功从注销页面(活动)导航到登录页面。 请让我知道是否任何一天都知道这一点。 如何检查用户是从活动A导航到活动B还是从一个片段导航到另一个片段。

在活动1开始,您可以按“导航”按钮,使用intended在它已经创建,以验证意图启动咖啡。

// Click on the item that starts navigation
onView(withId(R.id.buttonToGoActivity2)).perform(click());

// Check if intent with Activity 2 it's been launched
intended(hasComponent(Activity2.class.getName()));

gradle依赖需要:

androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'

对于片段,您可以在导航到片段时检查是否显示了内部视图

// Click on the item that starts navigation
onView(withId(R.id.buttonToShowFragment)).perform(click());

// wait for navigation delay
Thread.sleep(2000);

// Check that a view inside the fragment is shown
// Means navigaition to fragment is correct
onView(withId(R.id.viewInFragment)).check(matches(isDisplayed()));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM