草庐IT

getInstrumentation

全部标签

android instrumentation 测试用例 - getinstrumentation() 返回 null

我一直在尝试制作一个扩展intstrumentationtestcase的测试用例,每当我调用getinstrumentation()时,它都会返回Instrumentation的空实例而不是Instrumentation,从而使我想执行的任何自动化都变得无用。我也在list中设置了权限,即使我只是在这个案例将要运行的同一个应用程序上测试自动化......有什么想法吗? 最佳答案 您需要通过调用injectInstrumentation(InstrumentationRegistry.getInstrumentation());使用

android - Espresso 复选框已选中

我是Espresso的新手,我遇到了这个问题:如何检查是否选中了某个复选框?我从复选框创建了一个匹配器,然后用espresso单击它。我阅读了一些关于使用getInstrumentation()的教程,但我只能使用InstrumentationRegistry.getInstrumentation()并且它不起作用。一般来说,如何从Matcher对象创建真正的小部件,如Button、CheckBox等?感谢您的帮助。 最佳答案 点击后你可以用这样的表达式检查复选框是否被选中:onView(withId(R.id.checkbox))