Continuous Integration -- ANT - The Glue between Jenkins and your Tests

Why ANT?

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.

Assumptions

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.

A thorough description of running your tests with ANT

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

Once you're familiar with running your tests with ANT

...Or, if you're the type who likes to jump right in

Directory Structure

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

Copy files from MXUnit to your app

You need the following three files to start:

  1. mxunit-ant.jar -- ANT will use this to communicate with ColdFusion
  2. 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
  3. build.xml -- This is your new ANT build file

What to put where

  1. Create a directory in your app called "lib"
  2. Copy mxunit/ant/lib/mxunit-ant.jar into that lib directory
  3. Copy mxunit/samples/build.xml into your app's root, such that you end up with /app/build.xml
  4. 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

Modify build.xml

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:

  1. In the top-level project element, change the project name to your project 
  2. In the init target, change the application.name property to the directory name of your project
  3. Next line, if necessary change the test.dir.name property to be the name of your tests directory
  4. A few lines down, change the test.server and test.port properties to match your local setup (these can change later)

Run the "init" target

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

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.

Here's what the console view will look like when you run init:

Run the "runtests" target

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.

  1. In the ANT view, run the "runtests" target
  2. Look at the console view for outputYou 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:

Next Steps

Now that you have ANT running your tests, you're ready to hook this into the Jenkins CI server

Navigate space
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.