So, I was thinking and I came into the conclusion that when Unit-Testing, even if one wants to base mainly in behaviour-type testing (that is, with mocks, for example), I will eventually always to have to do state-based testing at least for t开发者_如何学编程he leaf classes (in the dependency graph).
Is this correct?
PS: I am, of course, excluding stable dependencies such as Java/C# API libraries, that one must always use.
Yes, the only way to test leaf classes in your dependency graph is to perform traditional state-based unit tests ("classical" testing in Fowler's terminology), because they have no collaborators, and therefore no hooks for your observation.
But that's a good thing: the opportunity to write state-based tests is a cause for celebration! Traditional black-box unit tests are easier to write, require less setup code, and break less often than behavioral tests that depend on implementation details.
One generally only performs behavioral testing out of necessity.
I think that's a good approach, especially if these classes are being used frequently.
精彩评论