作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个自定义 View ,我需要在该 View 上调用特定方法来打开 Activity 。在 Espresso 测试中执行此操作的正确方法是什么?我只需要扩充此 View 还是需要编写自定义 ViewAction
?
最佳答案
您可以像这样创建自定义 ViewAction
public class MyCustomViewAction implements ViewAction{
@Override
public Matcher<View> getConstraints(){
return isAssignableFrom(YourCustomView.class);
}
@Override
public String getDescription(){
return "whatever";
}
@Override
public void perform(UiController uiController, View view){
YourCustomView yourCustomView = (YourCustomView) view;
yourCustomView.yourCustomMethod();
// tadaaa
}
}
然后像往常一样使用它,比如
onView(withId(whatever)).perform(new MyCustomViewAction());
关于android - 如何在 Espresso 测试中调用自定义 View 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39229722/
我是一名优秀的程序员,十分优秀!