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

This entry was posted in Unit Testing and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.

5 Comments

  1. Dipak
    Posted October 19, 2006 at 6:01 pm | Permalink

    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?

  2. Kevan Stannard
    Posted November 14, 2006 at 4:32 pm | Permalink

    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

  3. Dipak
    Posted December 4, 2006 at 12:45 pm | Permalink

    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…

  4. colin
    Posted September 22, 2008 at 11:00 pm | Permalink

    I followed these steps, and I got "cfcunit doesn’t support the "hostname" attribute" error at compiling time. What is the reason?
    Thanks.

  5. Posted September 24, 2008 at 5:10 am | Permalink

    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/