org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!

在写Android 单元测试的mock时,一直报这个错误

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
8 matchers expected, 7 recorded:
-> at......

This exception may occur if matchers are combined with raw values:
    //incorrect:
    someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
    //correct:
    someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class.

我的代码:

...
stubber.when(mockedClient).get(eq(url), ArgumentMatchers.<String, String>anyMap(), "",null,null,null,null,null);
...

在mock方法时,方法的参数要不都保持为具体的值,要不就都为匹配任意值,如果某个参数想要用确定的值,其他为任意值,这个参数可以使用eq(参数)的方法,改成下面的代码解决此问题

...
stubber.when(mockedClient).get(eq(url), ArgumentMatchers.<String, String>anyMap(), anyString(),anyString(),anyString(),anyString(),anyString(),anyString());
...

你可能感兴趣的:(测试,单元测试)