我试图在时创建一个句子,但我做不好,因为我不知道如何正确地模拟任何内容。
我有这个代码:
public class OperationMovement {
@Value("${operation.check}")
private Boolean needToCheck;
private void checkOperation() {
// Code
if (BooleanUtils.isTrue(needToCheck)) {
// More code
}
}
}
我需要用Mockito创建一个测试,但我不知道如何模拟这个,否则。
我试着用这种方式嘲笑BooleanUtils:
@Mock
BeanUtils beanUtils;
// Code and more testing code
when(booleanUtils.isTrue(anyBoolean())).thenReturn(true);
但这是一个错误。
我也尝试过以下方法,但我有同样的错误:
when(BooleanUtils.isTrue(anyBoolean())).thenReturn(true);
我需要嘲笑那个财产或BooleanUtils类,但我不知道怎么做。
快速示例用法:
private OperationMovement classUnderTest;
...
@Test
void testOperationIsTrue() {
// For this test case, you are setting it to true
ReflectionTestUtils.setField(classUnderTest,"needToCheck",true);
}