作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用 Mockito 编写一个简单的单元测试:
@Test
public void toggleBlockingControlTest_turnOff() {
when(mainViewPresenter.getAppSettingsStorage().loadBlockingStatus())
.thenReturn(Mockito.anyBoolean());
AppSettingsStorage appSettingsStorage = mainViewPresenter.getAppSettingsStorage();
boolean statusBefore = appSettingsStorage.loadBlockingStatus();
Mockito.verify(appSettingsStorage).saveBlockingStatus(Mockito.eq(!statusBefore));
}
在运行时我得到了 org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 在这个字符串:
.thenReturn(Mockito.anyBoolean());
我是 Mockito 的新手,不明白为什么这个框架不能返回任何 boolean 值???
最佳答案
when(mainViewPresenter.getAppSettingsStorage().loadBlockingStatus())
.thenReturn(Mockito.anyBoolean());
此处您应该返回 Boolean.TRUE
或 Boolean.FALSE
。如果您不关心这个 boolean 值,那么:
替换:Mockito.anyBoolean() --> Boolean.TRUE/Boolean.FALSE
关于java - Mockito anyBoolean() 返回时匹配器异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37939390/
我是一名优秀的程序员,十分优秀!