Someone recently asked us about the jMock syntax. Why do we write:
mockFoo.expects(once()).method("bar").with(eq(1)).will(returnValue(99));
rather than, say
mockFoo.expects().once().method("foo")
etc..
The methods
expects
,
method
,
with
, and
will
are defined on our builder interfaces and chained on the same object. On the other hand,
once
,
eq
, and
returnValue
are attached to the container—
MockObjectTestCase
.
One way to think of it is that our chained methods are keywords in our Domain-Specific Language, they're the fixed part of the language. The container methods represent values, points where users of the language can write their own extensions. In jMock, all these values are either a
Constraint
or a
Stub
. We provide common implementations of these interfaces, but users can write their own to add a behaviour that is meaningful within the domain of their application.
No comments:
Post a Comment