I have recently been using CFCUnit for unit testing my ColdFusion components. I have also been using Ant as a build tool.
A few people have recently blogged about being able to run CFCUnit tests from within Ant. This sounded just great, so I started to look around cfcunit.jar file to get me up and running – unfortunately I couldn’t find a download location so I have created a copy here for you to download from. I understand that this code is not yet officially released, but it is available in the CFCUnit CVS repository. Here is a snapshot of the code and build of the ant-cfcunit.jar available today. You will need to download both to get it working:
The CFCUnit code returns an XML page back to the Ant task, so ensure that you have cfsetting showdebugoutput=false for the CFCUnit code to prevent an ‘invalid XML’ problem from occurring.
A simple Ant build script to use this would be:
<project default="test" name="MyTest"> <property name="cfcUnitLib" value="d:/data/cfcunit/lib" /> <property name="hostname" value="127.0.0.1" /> <taskdef name="cfcUnit" classname="org.cfcunit.ant.CFCUnitTask" classpath="${cfcUnitLib}ant-cfcunit.jar" /> <target name="test"> <cfcUnit hostname="${hostname}" testcase="com.yourpackage.YourTestComponent" verbose="true" haltonfailure="true" haltonerror="true" showstacktrace="true" /> </target> </project>
Many thanks for Paul Kenny for developing CFCUnit and John Paul Ashenfelter for the Ant integration!
For more on CFCUnit and Ant intergation see the posts by Sean Corfield and Chris Scott

5 Comments
Can you specify some more details about this?
I tried this and getting ant error "cfcunit class can not be created…."
Any mapping is required? or to add jar file to class path?
Hi Dipak, apologies for the unbelieveably slow response! If you don’t have this working yet then … you should not need to use a mapping or add the jar file to the class path. Perhaps put the full classpath of the jar file in your <taskdef> tag rather than using a property and see what happens.
Regards
Kevan
Hi Kevan,
Thanks.
Actually, the error was because "cfcUnit" is diff. than "cfcunit". (camel case)
I got the build.xml file from another blog: http://cdscott.blogspot.com/2006/07/thank-you-paul-and-john-paul.html, where taskdef defines name as "cfcUnit" and within the target it has reference to "cfcunit".
I hope, this might help someone else…
I followed these steps, and I got "cfcunit doesn’t support the "hostname" attribute" error at compiling time. What is the reason?
Thanks.
Hi, not sure what may be the cause of that problem.
However, I am not using CFCUnit any longer – now using MXUnit. CFCUnit was great, but MXUnit seems to be getting quite a bit more attention these days. You might like to take a look:
http://mxunit.org/
One Trackback
[...] http://blog.stannard.net.au/2006/09/23/cfcunit-and-ant/ [...]