2

如果您需要测试副作用,我想知道我们的单元测试代码何时。例如,如果我有一个带有 lockItem(BaseItem item) 方法和 unlockItem(BaseItem item) 方法的锁。我们是否应该测试方法只锁定我们的元素而不是另一个,就像解锁一样?

谢谢您的回答

4

1 回答 1

0

In general you don't test a negative. Meaning don't test what the code doesn't do, test what it does. So there is not a need to test the the method locks more than just the element that it does lock. If you tried to go down the other path it would be like saying "I have a prime number generator, I need to test that it doesn't write to the file system".

于 2013-10-21T11:16:51.107 回答