All,
Some of you have expressed interest in taking a look at the CF port of EasyMock I've been working on. Well, the first pass is done, so if you could reply off-list I'll get zips with docs out to you.
I'll try and get the source up on a publicly available site once, I've completely finished.
Mike Steele
Sounds like Brian Kotek's ColdMock?
Can you give more detail about what EasyMock provides that ColdMock does not?
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
<cfcomponent
name="Document"><cffunction name="init">
<cfargument name="listener">
<cfset variables.listener = arguments.listener />
<cfreturn this />
</cffunction>
<cffunction name="newDocument">
<cfargument name="docName">
<cfif len( arguments.docName ) gt 4>
<cfset variables.listener.createDocument( arguments.docName ) />
</cfif>
</cffunction>
</cfcomponent>
I realize that you're trying to give a simple use case, but this seems
quite contrived. Do you have a more "real world" example? Because I
just don't see something like this actually happening in a
application, where a method call is simply swallowed up with no
indication of whether an expected result actually happened. Let me put
it this way: if the above Document component was used in a real
application, and something called newDocument() on it, how would the
actual application know whether anything happened or not?
In any event, it would be pretty easy for me to add a
"methodCallCount()" to the mock object so that you could tell how many
times a given method was run, if people think that would help.
True, you have to find other invariants to assert.
> Then to test both outcomes of the if condition, you can use EasyMock to
> define behavior for both.
You show how to test for the call happening - how would you verify the
call did not happen? Would it just be an empty sequence of calls? I
think, as Brian hinted, this really just speaks to the number of
calls. Can you give a bit more detail? I'm intrigued but not convinced
yet.
I apologize for not having a more 'real' example to show you at this moment. Work and personal issues are eating up a lot of my time.
Behavior checking requires that you 1) record the expected behavior, 2) test the method, 3) verify the expected behavior and the actual behavior match. So you are correct that just giving a number of method calls isn't enough. The EasyMock package provides the verify() method, which will compare all recorded actual calls with the expected calls.
<!--- Set the expectation, mocks in this mock framework start in record mode. so any method call made on the mock is recorded --->
<cfset mock.getProxyInvoker().expect( mock.someFunction() ).andReturns( "Hello" ) />
<!--- Now switch the mock to accept the actual method calls --->
<cfset mock.getProxyInvoker().replay() />
<!--- We expect that testFunction will call mockSomeFunction() with no arguments. FYI, testFunction doesn't return a value --->
<cfset testComp.testFunction( mock ) />
OK, that helps me understand better. Interesting. Thanx.