I can see from your example how to do this if I was hard coding things.  The 
problem I am having is with using ColdSpring to handle the injection.  The test 
I am writing is for the service object.  The service object could either call 
ColdSpring to get the DAO it needs or the DAO could be injected ... I am 
running into confusion issues either way.

If the service object calls ColdSpring to get the DAO object, then the only 
place I can see for the code to tell the mock object what to return is in the 
service object itself which is no good.

If the DAO object is injected into the service object via ColdSpring, it is 
still a case that I don't have a handle on the mock object in the unit test to 
define its methods before it gets inserted into the service object.

The only way I can see around this is to create the DAO object in the unit 
test, write the code to handle its functionality, and then manually pass it to 
the service object.  While this could work, the dependencies are now being 
managed in the unit test instead of within ColdSpring and I have to inject the 
DAO into the service object rather than having the service object utilize 
ColdSpring to get the DAO.

Does that make any more sense?

-- Jeff

>Hi Jeff. Yes, you have to tell the mock object what you're expecting it to
>return, so that the object being tested (your service in this case)
>interacts with the mock the same way it would interact with the real object.
>You'd do this in your unit test methods. So in your case, you'd mock a
>business object, then mock the DAO, and finally tell the DAO that when the
>service calls the method on it, it returns the business object. The whole
>point is that the only "real" object you're testing at a time is the object
>you actually want to test. Everything else is fake. Does that make sense or
>am I misreading your question?
>
>On Nov 12, 2007 4:16 PM, Jeff Chastain <[EMAIL PROTECTED]> wrote:
>
>> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293160
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to