Tag Archives: cfcunit

Automated tests using Ant integration of testing frameworks – cfunit, cfcunit and mxunit


If you have seen my previous post, Then you might want to automate testing. You can automate all three popular testing frameworks (cfunit, cfcunit and mxunit) with ant.

I’ve tested in eclipse 3.6 version, but it will also work in Adobe ColdFusion Builder.

Step 1: Create build.xml file and put it in your project.

Step 2: Copy and paste the following code in build.xml file.

For mxunit :

<?xml version="1.0"?>

<project name="mxunit_example" default="main" basedir=".">
	<taskdef name="mxUnit" classname="org.mxunit.ant.MXUnitAntTask" />

	<property name="domain" value="localhost"/>
	<property name="webroot" value="c:\inetpub\wwwroot"/>

	<target name="main">
		<mxUnit server="${domain}"
			defaultrunner="/mxunit/runner/HttpAntRunner.cfc"
			verbose="true">
			<!-- componentPath is not required, but it results in a much faster test run -->
			<directory remoteMethod="run" path="${webroot}\mxunit_example" packageName="mxunit_example" componentPath="mxunit_example" recurse="true" includes="*.cfc"/>
		</mxUnit>
	</target>
</project>

For cfunit :

<?xml version="1.0"?>
<project name="CFUnitExample" default="main" basedir=".">
	<taskdef name="CFUnit" classname="net.sourceforge.cfunit.ant.CFUnit"/>

	<property name="domain" value="http://localhost/"/>

	<target name="main">
		<CFUnit testcase="${domain}CFUnitExample/test/MyCFCTest.cfc"
			verbose="true"/>
	</target>
</project>

For cfcunit :

<?xml version="1.0"?>

<project name="CFCUnit_example" default="main" basedir=".">
	<taskdef name="CFCUnit" classname="org.cfcunit.ant.CFCUnitTask" />

	<property name="domain" value="localhost"/>

	<target name="main">
		<CFCUnit hostname="${domain}"
			testcase="CFCUnit_example.CalculatorTest"
			verbose="true"
			haltonfailure="true"
			haltonerror="true"
			showstacktrace="true"/>
	</target>
</project>

Explanation :

1) Project name should match with you project name.

2) Class name of the taskdef: You should have put class file on the correct location. For e.g. org.mxunit.ant.MXUnitAntTask

I have the MXUnitAntTask.class file in c:\inetpub\wwwroot\org\mxunit\ant\ location.

If you don’t have that class file then download the mxunit, extract it, extract the jar file located in mxunit\ant\lib\mxunit-ant.jar. You will find the class files in that.

Step 3: Configure Ant for you project

1) Right click on your project and go to properties -> Builders. Click on new button.

2) Select Ant builder. Press ok and it will open a dialog (edit configuration). Type a new build name.

3) Select your build.xml file for build file by browse the workspace.

4) Select class path tab and click on “add external jars” button. Link your mxunit-ant.jar file.

5) Select Build option tab and click the check box for “Specify working set of relevant resources”.

6) Click on “Specify Resources” button and select your project or you can also select single directory. Click on ok button.

If you find the difficulties in above steps then please visit fusion authority website.

Cheers! Now write test cases. Each time when you hit save, eclipse will automatically build you files and you will see outputs in console.

Useful links :

http://blog.stannard.net.au/2006/09/23/cfcunit-and-ant/

http://corfield.org/blog/post.cfm/Automated_Testing_with_cfcUnit

http://www.fusionauthority.com/techniques/4568-test-driven-development-with-coldfusion-part-ii.htm

Testing frameworks – cfunit, cfcunit and mxunit


Hi folks,

There are lots of testing frameworks available for Test-driven development (TDD).
Most of them are of xUnit family. Recently I had gone through three most popular
testing frameworks for ColdFusion.

CFUnit

CFCUnit

MXUnit

After using all three, I decided to post a comparison of them. Information may be inaccurate, Corrections are always acceptable.

Features CFUnit CFCUnit MXUnit
Based on XUnit & JUnit Yes Yes Yes
Eclipse Plug-in Removed in final cfeclipse release No Yes
Eclipse Ant integration using jar Yes Yes Yes
Supported Output format HTML HTML, XML HTML,XML,JUnit Report XML, CF query, CF Array
HTML UI No Yes Yes
Easy to see your data with cfoutput, cfdump, and debug(), also cfcatch to view data No No Yes
Directory runner No No Yes
Testing private methods Yes Yes
Support for setUp() and tearDown() functions Yes Yes Yes
beforeTests() and afterTests() functions No No Yes
Help and tutorials availability Few Few Enough
Assertion Only Standard Assertions More than 30 Built-in assertion There are around 10 built-in assertions

I personally like MXUnit for its eclipse
Plug-in and better UI.