android studio中活动切换的浓缩咖啡单元测试用例

android studio中活动切换的浓缩咖啡单元测试用例,android,junit4,android-espresso,Android,Junit4,Android Espresso,我想使用Espresso编写单元测试用例,它应该检查用户是否成功地从注销页面(活动)导航到登录页面。 如果有人知道这件事,请告诉我。如何检查用户是从活动A导航到活动B还是从一个片段导航到另一个片段。从活动1开始,您可以按下“导航”按钮,并在创建的浓缩咖啡中使用预期的,以验证是否启动了预期 // Click on the item that starts navigation onView(withId(R.id.buttonToGoActivity2)).perform(click()); /

我想使用Espresso编写单元测试用例,它应该检查用户是否成功地从注销页面(活动)导航到登录页面。
如果有人知道这件事,请告诉我。如何检查用户是从活动A导航到活动B还是从一个片段导航到另一个片段。

从活动1开始,您可以按下“导航”按钮,并在创建的浓缩咖啡中使用
预期的
,以验证是否启动了预期

// 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()));
需要渐变依赖项:

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()));

嗨,谢谢你的重播。。我可以知道这是测试从一个页面导航到另一个页面的标准方法吗:S bcz我对单元测试是新手。我的意思是每个人都是这样测试导航的看看我的最新版本。我想这取决于你想测试什么。请看一看添加的文档。您需要使用IntentsTestRule