CFCUnit and Ant

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:

Download cfcunit.zip

Download ant-cfcunit.jar

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

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
19 Oct 2006 06:01PM
Dipak said:
Dipak's Gravatar 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?
14 Nov 2006 04:32PM
Kevan Stannard said:
Kevan Stannard's Gravatar 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
4 Dec 2006 12:45PM
Dipak said:
Dipak's Gravatar 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..., where taskdef defines name as "cfcUnit" and within the target it has reference to "cfcunit".

I hope, this might help someone else...
22 Sep 2008 11:00PM
colin said:
colin's Gravatar I followed these steps, and I got "cfcunit doesn't support the "hostname" attribute" error at compiling time. What is the reason?
Thanks.
24 Sep 2008 05:10AM
Kevan Stannard's Gravatar 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/
Add a comment
(will not be published)
(include http://)