gpt4 book ai didi

unit-testing - 方法抛出 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' 异常。

转载 作者:行者123 更新时间:2023-11-28 20:36:45 24 4
gpt4 key购买 nike

我正在尝试测试此方法,但出现以下错误:

Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception. 

在这一行代码:

    when(tester.method(
any(String.class), any(LocalDate.class), any(boolean.class),any(boolean.class), any(String.class))).thenReturn(item);

最佳答案

对于您正在使用的大多数类型,已经有内置的匹配器。

when(tester.method(anyString(), any(LocalDate.class), anyBoolean(),anyBoolean(), anyString()))
.thenReturn(item);

引用 Class ArgumentMatchers

For primitive types use any{Type}() family.

关于unit-testing - 方法抛出 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' 异常。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51621171/

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