I'll be speaking Wednesday Nov 3, 2010 @ the ColdFusion User Group in St. Paul/Minneapolis on mxUnit Testing with Hudson Continuous Integration Server.
I'll be talking about basic Assertions, as well as going into some advanced mocking topics with the new 2.x release of the mxUnit Framework.
The second part of the evening we'll look at the Hudson Server to help execute our Unit Tests and provide jUnit reports that show execution trends as well as some special surprises.
See you there!
Discussions on ColdFusion, Flex, Web Architecture and other technologies that power the web, our minds, and our lives.
Showing posts with label mxunit. Show all posts
Showing posts with label mxunit. Show all posts
Wednesday, November 3, 2010
Friday, February 19, 2010
Executing Remote MXUnit Tests in CFBuilder/CFEclipse
I had some interesting problems the other week while working on some Model-Glue (gesture) RemoteService requests. I had posted to the Model-Glue Google Group about a few things I ran into when using the AbstractRemotingService.cfc, and getting url variables to work properly through the service, which they have addressed (Thank you!).
Obviously you need to read the wiki documentation first.
When you Create your RemoteService.cfc that exists at the root of your application, which will be your remoting front controller if you will, you need to tell it where your main model-glue template file is located. (download the zip file from www.model-glue.com and find the modelglueapplicationtemplate directory for the sample RemotingService.cfc)
Once you have a simple working version up / running by calling /RemotingService.cfc?method=executeEvent&event=my.event&format=json and pass in the data you need to, then you need a good way to test it right? If you use MXUnit then you have more than likely configured your IDE to execute these tests.
Figure 1.0
ISSUE:
The thing I ran into was that I was using model-glue's event security where I could specify certain events to be 'authentication' needed etc. My remoting service was calling an event that required prior authorization (i.e. session.isLoggedin() or some other means). Now, when I executed a test for this event in mxUnit through the Eclipse plugin for mxunit, it would Fail the test and kept telling me I was unauthorized to execute this event etc, and return the source code for my login screen instead (which would be correct if I was not logged in). However in my unit Test, I was making sure to Call my AuthorizationFacade and log me in in the 'setup' method and verified that 'isLoggedIn()' returned true.
RESOLUTION:
So in my unit test I am doing a cfhttp 'post' (or now that they supported url variables better in the service a 'get' ) request to the RemoteService.cfc passing in my data. HOWEVER, I needed to also pass in the following through my cfhttp call:
<cfhttpparam ....="formfield" name="CFIDE" value="#cookie.CFIDE#">
<cfhttpparam ....="formfield" name="CFTOKEN" value="#cookie.CFTOKEN#">
<cfhttpparam ....="formfield" name="JSESSIONID" value="#session.sessionid#">
Once this was in place, the calls worked as expected, and returned proper json data.
Obviously you need to read the wiki documentation first.
When you Create your RemoteService.cfc that exists at the root of your application, which will be your remoting front controller if you will, you need to tell it where your main model-glue template file is located. (download the zip file from www.model-glue.com and find the modelglueapplicationtemplate directory for the sample RemotingService.cfc)
Once you have a simple working version up / running by calling /RemotingService.cfc?method=executeEvent&event=my.event&format=json and pass in the data you need to, then you need a good way to test it right? If you use MXUnit then you have more than likely configured your IDE to execute these tests.
Figure 1.0
ISSUE:
The thing I ran into was that I was using model-glue's event security where I could specify certain events to be 'authentication' needed etc. My remoting service was calling an event that required prior authorization (i.e. session.isLoggedin() or some other means). Now, when I executed a test for this event in mxUnit through the Eclipse plugin for mxunit, it would Fail the test and kept telling me I was unauthorized to execute this event etc, and return the source code for my login screen instead (which would be correct if I was not logged in). However in my unit Test, I was making sure to Call my AuthorizationFacade and log me in in the 'setup' method and verified that 'isLoggedIn()' returned true.
RESOLUTION:
So in my unit test I am doing a cfhttp 'post' (or now that they supported url variables better in the service a 'get' ) request to the RemoteService.cfc passing in my data. HOWEVER, I needed to also pass in the following through my cfhttp call:
<cfhttpparam ....="formfield" name="CFIDE" value="#cookie.CFIDE#">
<cfhttpparam ....="formfield" name="CFTOKEN" value="#cookie.CFTOKEN#">
<cfhttpparam ....="formfield" name="JSESSIONID" value="#session.sessionid#">
Once this was in place, the calls worked as expected, and returned proper json data.
Subscribe to:
Posts (Atom)