我有方法来测试下面的junit
public Response submitData(String a, BigInteger b, HttpServletRequest request){
}
我有下面的mockito junit方法
@Test
public void submitData_Success() throws Exception {
when(inAbcExample.submitData(anyString(),eq(new BigInteger("12")),mockRequest)).thenReturn(response);
}
我遇到了匹配器异常的无效使用。以上几行是否正确
最佳答案
当您尝试使用 anyXXX()
mockito 包装器传递某些参数,但其中一些参数仍然正常传递时(例如您的情况下的 mockRequest
),就会出现此错误。您应该重构以下内容:
@Test
public void submitData_Success() throws Exception {
when(inAbcExample.submitData(anyString()
,Mockito.eq(new BigInteger("12")),Mockito.eq(mockRequest))).thenReturn(response);
}
关于java - 出现错误匹配器异常的无效用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42067112/