views:

22

answers:

2

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 the 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.

A: 

I think that's a good approach, especially if these classes are being used frequently.

Bernard
I'm not sure I understand what you mean, in the context of the question.
devoured elysium
Refer to Jeff Sternal's more complete answer.
Bernard
+1  A: 

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.

Jeff Sternal
I suspect your concept of "behavioral tests" and "state-based tests" is the exact opposite of how "devoured elysium" uses the terms.
Michael Borgwardt
@Michael - I certainly can't rule that out, but what does the question mean if that's the case?
Jeff Sternal
I'm using flower's definition, which is probably the same as Jeff's.
devoured elysium