错误时使用的任何东西();在Android的需要测试不兼容的类型:匹配器<视图>发现:匹配器<对象> [英] Error when use anything(); in Android testing incompatible types required: Matcher <View> found: Matcher <Object>

查看:314
本文介绍了错误时使用的任何东西();在Android的需要测试不兼容的类型:匹配器<视图>发现:匹配器<对象>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行code初级讲座,并在任何回报()遇到错误;

I run the code belows and got error at return anything();

error: incompatible types
required: Matcher <View>
found:    Matcher <Object>

/** 
     * Perform action of waiting until UI thread is free. <p/> E.g.: onView(isRoot()).perform(waitUntilIdle());
     * @return
     */
    public static ViewAction waitUntilIdle(){
      return new ViewAction(){
        @Override public Matcher<View> getConstraints(){
          return anything();
        }
        @Override public String getDescription(){
          return "wait until UI thread is free";
        }
        @Override public void perform(    final UiController uiController,    final View view){
          uiController.loopMainThreadUntilIdle();
        }
      }
    ;
    }

任何想法?

推荐答案

什么()不是一个通用的方法,所以你总是会得到一个匹配器&LT;对象&gt;

anything() is not a generic method, so you will always get a Matcher<Object>.

在内部什么()使用 IsAnything 类。你可以让你自己的 Anyview的()方法返回一个匹配器&LT;视图&gt;

Internally anything() uses the IsAnything class. You can make your own anyView() method to return a Matcher<View>.

public static ViewAction waitUntilIdle(){
    return new ViewAction(){
        @Override public Matcher<View> getConstraints(){
            return anyView();
        }

        @NonNull
        private Matcher<View> anyView() {
            return new IsAnything<>();
        }

        @Override public String getDescription(){
            return "wait until UI thread is free";
        }
        @Override public void perform(    final UiController uiController,    final View view){
            uiController.loopMainThreadUntilIdle();
        }
    }
            ;
}

这篇关于错误时使用的任何东西();在Android的需要测试不兼容的类型:匹配器&LT;视图&gt;发现:匹配器&LT;对象&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆