So you're writing unit tests, maybe even dabbling in "real" test-driven development (i.e. writing tests before code, letting tests drive design, etc). And you have these tests sitting there, and you run them as you're developing, and angels sing and heralds trumpet. And you think to yourself, "you know, i should run these tests often". And that's good. And then you think "you know, i should let the computer run these tests for me and tell me what's what". And that's better.
Particularly when you're just starting out with unit testing, your creative energy is primarily directed at the test writing itself. It's new, and that's mentally exhausting. Then some test guru tells you that you need a continuous integration server and that if you don't have one you might as well pack your crap up and go program in php 'cause you's a n00b and we don't want you here.
Ignore that talk. Getting your tests running in a scheduled manner should take about 5 minutes to set up. I guarantee it will take you far longer to read this document than it will to automate your tests. So let's get started with some really simple test automation. Note... eventually, as your entire team gets test-infected, you're going to want more. You'll want metrics and logging and test history and reports and all that stuff. You'll want your most recent test runs on your intranet wiki front page. You'll hear "What bastard broke the app!?" lobbed over the cubes. For now, though, let's keep it simple.
My app was at c:\inetpub\wwwroot\AppCFCSite1, and I created a directory named "tests" under that. In "tests", I created a directory named "TestRuns"
Create a new file in the top level of your tests directory and call it "run.cfm"
On your file system, go to your mxunit install directory (e.g., c:\inetpub\wwwroot\mxunit), go to "samples", and open ScheduledRun.cfm. Copy the contents.
Then, paste the contents into your new run.cfm file
You don't need to do this, but it significantly improves performance of the DirectoryTestSuite. So do it.
In my example, I changed
<cfinvoke component="#DTS#" method="run" directory="#dir#" recurse="true" excludes="#excludes#" returnvariable="Results" componentpath="????.?????.?????"><!--- <-- Fill this in! --->
<cfinvoke component="#DTS#" method="run" directory="#dir#" recurse="true" excludes="#excludes#" returnvariable="Results" componentpath="AppCFCSite1.test"><!--- <-- Fill this in! --->
If you don't have any tests in your test directory (or its subdirectories), this will show 0 results
Now that your run file is set up, let's automate the running of it. Open CF Administrator, and go to "Scheduled Tasks". Click the "Schedule New Task" button
Name the task. Select the "daily every" radio, and tell it when you want to run. This sample has it running every 2 hours starting at 6 AM and ending at 5 PM
Add the URL to your run file into the "URL" box
Click the checkbox beside "save output to file".
In the "File" box, add a path to a file where your output will be stored. For my sample app, I entered c:\inetpub\wwwroot\AppCFCSite1\test\testruns\MostRecent.html
In the scheduled tasks list, click the green button beside your new scheduled task. This will run it. This will put a new file at the location you specified.
On your file system (or in your IDE), find the new file that was created. Open it in the browser. You should see virtually the same thing you saw when you ran the file manually in the browser
in the mxunit install location, in the "samples" directory, open "TestCaseSkeleton.cfc". Copy the contents.
In your "tests" directory, create a new test component if you don't have any. Name it something like "MyNewTest.cfc". This is a throwaway, only for use in demonstrating the automation. Paste your contents from TestCaseSkeleton into your new component. Save it.
Re-run your new run.cfm file. You'll now see your new test component, which will contain a failure.
Back in your CF Admin, manually run the scheduled task again. This will overwrite the existing "MostRecent.html" file
Open that MostRecent.html file and confirm that it now contains your new test
Back in CFAdmin, open up that scheduled task. in the "URL" box, add "&email=true" to the end of the URL.
The run.cfm file is, by default, purposely simple with its handling of email:
Now that the email is set up, run your task manually one more time in CF Admin. Assuming your mail server and all that is set up correctly, you should get an email momentarily that contains your test results.
Voila... simple test automation.