Continuous Integration ANT The Glue between Jenkins and your Tests - mxunit/mxunit GitHub Wiki
You won’t get far using Jenkins and ColdFusion without ANT. ANT is the Hub. It’s the glue.
Your ANT build will run your MXUnit Tests. Jenkins will run your ANT build, record the results of the tests, and perform post-build actions (notifications, etc) based on the results of those tests.
We assume you have some tests and can successfully run them via either the Eclipse plugin or your web browser
We assume that if you are not familiar with ANT that you’re willing to learn enough of it to get your CI environment set up. If you’re not up for that, perhaps simpler automation is for you.
Bill’s original walkthrough is very thorough. In addition, please see Bill’s fantastic 8-minute video showing exactly how to run your MXUnit tests with ANT.
If you are new to ANT, I implore you to visit those links, especially if you’re the type who doesn’t like flailing about trying to make sense of foreign things.
Even if you simply read Bill’s instructions, and watch the video, you’ll gain enough familiarity with ANT and MXUnit to move on ot the next step
…Or, if you’re the type who likes to jump right in
Your final directory structure will look something like the following. If your tests live somewhere else inside your app, that’s OK… just make sure to adjust the paths in the build file to account for their location.
In the example below, files demoted with an asterisk \(*) are files that do not yet exist but which will when we’re finished
*build.xml
/lib
*mxunit-ant.jar
other-whatever.jar
/test
*HttpAntRunner.cfc
/testdir1
SomeTest.cfc
/testdir2
SomeOtherTest.cfc
h2. Copy files from MXUnit to your app
You need the following three files to start:
- mxunit-ant.jar \-\- ANT will use this to communicate with ColdFusion
- HttpAntRunner.cfc \-\- This is the “endpoint”… ANT will make HTTP requests to this CFC, and that CFC will in turn run the MXUnit framework code which runs your tests
- build.xml \-\- This is your new ANT build file{*}What to put where*\# Create a directory in your app called “lib”
- Copy mxunit/ant/lib/mxunit-ant.jar into that lib directory
- Copy mxunit/samples/build.xml into your app’s root, such that you end up with /app/build.xml
- Copy mxunit/samples/HttpAntRunner.cfc into your app’s test root, such that you end up with /app/test/HttpAntRunner.cfcOpen up that HttpAntRunner.cfc after you copy it. Notice that it simply extends the framework version. While you could point directly to the framework version, you almost always want to point to your custom version, especially if you’re using ORM, testing framework controllers, or otherwise need access to your app’s Application scope
The sample build.xml file which you copied is meant to be a good-enough skeleton to get you running your tests from ANT. It also contains example “svn update” and “dist” targets for updating a directory from SVN and creating a zip file, respectively. More on those later.
For now, we need to run tests. To do this, you’ll modify several of the properties in the ANT file to point to the correct names and locations for your project
If you’re using Eclipse or another IDE which shows the structure of an ANT file, open the ANT view and drag your build file into it. It’ll look something like this:
In build.xml:
- In the top-level project element, change the project name to your project
- In the init target, change the application.name property to the directory name of your project
- Next line, if necessary change the test.dir.name property to be the name of your tests directory
- A few lines down, change the test.server and test.port properties to match your local setup (these can change later)
Now, From the ANT view in Eclipse, run the “init” target. In the console view, you’ll see a dump of all the properties that will drive your ANT build. Most of these will be file system locations
{warning} Do not proceed until test.cfcpath and test.dir.location look correct. If they’re not correct, modify the build file and make them so. {warning}Here’s what the console view will look like when you run init:
Assuming your paths are correct, you have brought the mxunit-ant.jar into your app’s “lib” directory, and you have some tests living in your test location, now’s the time to run them from ANT.
- In the ANT view, run the “runtests” target
- Look at the console view for output. You will see a log of what the ANT task is doing as it communicates with ColdFusion. When finished, you’ll see the results of your test run. Here’s an example:
Now that you have ANT running your tests, you’re ready to hook this into the Jenkins CI server