Derek
We use "stub" as a verb to mean, *allow* a message to be sent to a
collaborator, but do not *expect* it. (JMock 2 uses the term allowing
to avoid this confusion. JMock 1 used the term stub in its API).
So we suggest allowing queries, but expecting commands.
But we don't recommend limiting your tests to just one expectation and
everything else being allowed, and definitely not to just one mock and
the rest being stub objects.
Instead, expect the significant outgoing command messages that you are
testing for -- there may be more than one. Allow outgoing queries,
the results of which affect the behaviour under test. Don't constrain
order explicitly unless it is the behaviour being tested, and even
then do so as loosely as possible -- prefer state machines to
sequences, for example. And ignore any interactions that are not
germane to the behaviour being tested if you cannot avoid them
happening in some other way (in jMock you can use the ignoring clause
to ignore messages or entire objects).
Obviously there are situations where this does not hold. For example,
if testing a read-through cache, then you would care about the number
of times a query was made to pull data into the cache, so allowing the
query would not actually test the behaviour you want to test. But
most often, in my experience, it doesn't matter to the functionality
of an object how many times a query is performed.
--Nat
On 10 January 2011 23:37, philip schwarz
Additionally, Steve stated the following in one of his responses:
"What does concern me is that all the interactions should be verified unless I turn them off explicitly."
Based on the design of JMock, how it's used in the book, and the above comment, it seems apparent Steve is an advocate of strict mocking.
That aside, the main points I was trying to make in my comments were that many of the differences expressed within the thread aren't really part and parcel to distinct paradigms of TDD, but are a result of opinions formed based upon the particular language and tooling being used and that the only real difference I saw was the view each side was taking on the subject of strict mocking. Concerning these positions, I submit that the positions aren't mutually exclusive but rather both techniques can be used depending on what's best at the time.
What's your opinion on these points?
Derek
Obviously there are situations where this does not hold. For example,
if testing a read-through cache, then you would care about the number
of times a query was made to pull data into the cache, so allowing the
query would not actually test the behaviour you want to test. But
most often, in my experience, it doesn't matter to the functionality
of an object how many times a query is performed.
By strict, I mean the behavior of throwing exceptions for any non-configured method invocation, not just out of order invocations. JMock provides the ignoring() and allowing() methods for explicitly denoting collaborations which aren't central to a particular specification and are used in the examples throughout the book.
<snip>
What's your opinion on these points?