Re: [Twisted-Python] Adding mock as a test suite dependency

From: exarkun@twistedmatrix.com
Well it seems I sidestepped behavior vs. state but fell into isolationist vs integration :). The reason I think even this was a reasonable example is because in the code that this will test, there is no dependence on an actual debugger whatsoever. What this test should be testing is that an object whose interface is irrelevant for the purpose of the test was handed off to another method in the case that that is expected. In short, the isolationist view as I understand and have come to appreciate says that mocks (in a broader sense here since these aren't true mocks I guess) aren't just for cases where the real object is expensive or annoying to create – they also remove irrelevant details from the body of the test. That being said though, I'm still looking (read: I have not yet looked but will do so when I get home) for actual examples in the test suite I can point to and say that real, actual mocks would have helped if that's what you'd be looking for. To go back to your first point about verification, mock has a bunch of things there of which if I'm truthful I only use some of them with any regularity. The thing that sounds like what you're referring to is likely the `spec` argument, which will do something like:
As someone mentioned you also can hand it an implementor of ITestCase too but it will then pull off all attributes that that object has. There's plenty more granularity, but like anything else the design of the test requires common sense. If the test is meant to test how a specific method on the testCase mock is being used then assertions on how it was called generally seem most natural. As an alternate approach, I've learned (from a few places I think) that in cases where I want to verify that the places I've mocked are being used in a way that isn't going to differ from their actual use in the code, that a much wider scoped test that does integrate but doesn't need to be a unit test can be helpful, such that there are a whole bunch of isolated tests for each piece of logic and then one integrated test that actually does push the real object through such that anyone who does change the way that the two objects interacts still will have something telling them that the tests need updating as they would if all of the tests integrated. Jean-Paul
participants (1)
-
Julian Berman