gpt4 book ai didi

junit - 如何使用 mockito verify() 验证一个方法被调用两次

转载 作者:行者123 更新时间:2023-12-05 00:42:36 26 4
gpt4 key购买 nike

我想通过 mockito verify 验证是否至少调用了一次方法。我使用了验证,它提示如下:

org.mockito.exceptions.verification.TooManyActualInvocations: 
Wanted 1 time:
But was 2 times. Undesired invocation:

最佳答案

使用适当的验证模式:

import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

verify(mockObject, atLeast(2)).someMethod("was called at least twice");
verify(mockObject, times(3)).someMethod("was called exactly three times");

关于junit - 如何使用 mockito verify() 验证一个方法被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14889951/

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