gpt4 book ai didi

android - 如何在 Espresso 测试中调用自定义 View 的方法?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:25 26 4
gpt4 key购买 nike

我有一个自定义 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com