【发布时间】:2012-08-09 19:12:23
【问题描述】:
我正在寻找一种使用 Mockito 验证的方法,即在测试期间与给定的模拟没有任何交互。对于具有验证模式never() 的给定方法,很容易实现这一点,但我还没有找到完整模拟的解决方案。
我真正想要实现的目标:在测试中验证,没有任何东西打印到控制台。 jUnit 的总体思路是这样的:
private PrintStream systemOut;
@Before
public void setUp() {
// spy on System.out
systemOut = spy(System.out);
}
@After
public void tearDown() {
verify(systemOut, never()); // <-- that doesn't work, just shows the intention
}
PrintStream 有很多方法,我真的不想用单独的验证来验证每一个方法——System.err 也是如此......
所以我希望,如果有一个简单的解决方案,我可以,考虑到我有很好的测试覆盖率,强制软件工程师(和我自己)删除他们的(我的)调试代码,比如 System.out.println("Breakpoint#1"); 或 e.printStacktrace();在提交更改之前。
【问题讨论】: