Simple Example

1 <cfcomponent extends="mxunit.framework.TestCase" output="false">
2     <cffunction name="testMyComponentInteractions">
3     <!--- Create the mock --->
4     <cfset mock = createObject('component','MightyMock').init('MyComponent') />
5     <!--- Define Behavior --->
6     <cfset mock.doSomething('foo').returns( 123456 ) />
7     <!--- Inject into component --->
8     <cfset myComponent.setMyOtherComponent(mock) />
9     <!--- Exercise MyComponent --->
10     <cfset retVal = myComponent.myMethod('foo') />
11     <!--- When doSomething('foo') is called by MyComponent, MightyMock
12       will return the value 123456 to MyComponent--->
13 
14     <cfset assertEquals(123456, retVal) />
15 
16         <!--- If you need to verify calls, do this --->
17     <cfset mock.verifyTimes(1).doSomething('foo') />
18 
19   </cffunction>
20 </cfcomponent>
Comments