2015-10-21 62 views
1

我有Espresso测试并希望应用程序保持在测试完成时的确切活动。我需要继续与应用程序进行交互。安卓意式浓缩咖啡让应用程序在测试后运行

@SmallTest 
public void testOpenNavigationDrawer() 
{ 
    Espresso.onView(ViewMatchers.withId(com.eleks.espresso.example.app.R.id.content_frame)).perform(ViewActions.swipeRight()); 
    ListView lvDrawerMenu = (ListView) getActivity().findViewById(com.eleks.espresso.example.app.R.id.lvDrawerMenu); 
    Preconditions.checkNotNull(lvDrawerMenu, "lvDrawerMenu is null"); 
    final int count = lvDrawerMenu.getAdapter().getCount(); 
    Preconditions.checkPositionIndex(2, count, "No 1 index " + count + " size"); 
    Object obj = lvDrawerMenu.getItemAtPosition(2); 
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(com.eleks.espresso.example.app.R.id.tvItem), ViewMatchers.hasSibling(ViewMatchers.withText(obj.toString())))).perform(ViewActions.click()); 
} 

我该怎么做? 谢谢!

回答

1

对不起,但这是不可能的。

我觉得你对自动化测试不够了解。 \

Espresso,Robotium,Calabash和其他UI测试框架用于短期测试事件。它模拟用户的特定行为 - 运行应用程序,执行一些技巧和(如果成功)而不是关闭应用程序。

当然,Espresso允许您创建自定义闲置资源,并将其注册到应用程序中。此外,使测试休眠特定时间的最简单方法是使用方法Thread.sleep(time_in_miliseconds),但正如我所说的,它违背了自动测试的想法。

3

如果您希望在特定测试后运行该应用程序,那么您可以执行某些手动交互,甚至只需要更长时间查看最终结果。您可以在测试结束时放置一个Thread.sleep(MS);,使其在您想要的时间内坐在那里。

想要看到您可以在睡眠后(以及您手动进行的任何交互)进行另一次检查并继续测试。很明显,你不想经常这样做,因为它不会为自动测试做好准备。