我想验证以下两个方法调用中的任何一个是否执行一次:
myLogger.logWarn("My 1st Warning Message"); // depending on some randomness in my program,
myLogger.logWarn("My 2nd Warning Message"); // one of these two get executed
我已尝试以下方法:
verify(myLogger).logWarn(or("My 1st Warning Message", "My 2nd Log Warning Message"));
但运行测试方法导致以下错误:
No matchers found for additional matcher Or(?)
-> at foobar.builder.StopBuilderTest.build(StopBuilderTest.java:141)
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
No matchers found for additional matcher Or(?)
-> at foobar.builder.StopBuilderTest.build(StopBuilderTest.java:141)
当我只是测试单个方法调用时,如下所示..
verify(myLogger).logWarn("My 1st Warning Message");
..它运行得很好,当用参数"My 1st Warning Message"
调用logWarn()
时,我的测试总是成功的。
1条答案
按热度按时间uqdfh47h1#
AdditionalMatchers用于在ArgumentMatchers上实现常见的逻辑运算(“非”、“与”、“或”)
下面的代码:
应该可以正常工作。