- February 8, 2017
- Posted by: user
- Category: Uncategorized
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 :
[code:xml]
<?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>
[/code]
For cfunit :
[code:xml]
<?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>
[/code]
For cfcunit :
[code:xml]
<?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>
[/code]
Explanation:
- Project name should match with you project name.
- 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
- Right click on your project and go to properties -> Builders. Click on new button.
- Select Ant builder. Press ok and it will open a dialog (edit configuration). Type a new build name.
- Select your build.xml file for build file by browse the workspace.
- Select classpath tab and click on "add external jars" button. link your mxunit-ant.jar file.
- Select Build option tab and click the check box for "Specify working set of relevant resources".
- 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 builds 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