3 ms·
Regarding Mockito specifically, I think there are worse and better ways to use it. I think it's great for mocking out external services, like web services calls
by msluyter 13y ago
Regarding Mockito specifically, I think there are worse and better ways to use it. I think it's great for mocking out external services, like web services calls or database queries. That way, you can easily test a bit of functionality without having to instantiate the universe.
On the other hand, I've also seen it used overly invasively -- that is, the test writer uses it to verify the status of some object internal to the class under test, like your example above. As you note, it creates an incredibly tight coupling between the test and the method being tested.
In general, I think that this sort of thing is correlated with classes that are highly stateful. If, for example, your class is full of void methods that modify class members, then you may have no other option than inspecting the internals of the class in order to test its functionality. OTOH, if you can manage to write things in a more functional, less state-heavy manner, then you need less of this sort of introspection.
- UK-AL 13y agoThat's hardcore unit testing. If you don't mock out classes around the class your testing, its a integration test.