Sunday, July 30, 2006

Thank you Paul and John Paul!

You know it's been a while since I had one of those days where I truly had a great time writing code. Could be all the Java I've been working on these days, or maybe a few other reasons, but I've been feeling a little bogged down lately and it sure was nice to have a fun time coding again. So why was yesterday so nice you may ask? Well I'm back to some contracting work that I was working on last year on a well designed system written in ColdFusion, for one thing. And it's been quite easy to jump right back in to the system, which in itself is a testament to good design. But what made yesterday even that much better than the breath of fresh air which is working with ColdFusion was a little gift that Paul Kenney sent me the other day. I know, Sean has already told you about the wonderful new cfcUnit with Ant integration, brought to you via John Paul Ashenfelter, but I simply must sing it's praises again! Now I am a huge believer in TDD or Test Driven Development. JUnit is a big part of my development cycle these days, and I do try to use cfcUnit as much as I can. But to be honest, unit testing in cf has been pretty far behind Java, and the main reason is the fact that I want to test while I'm coding, immediately. Having to deploy (unless you work locally out of a web root), and then go to the cfUnit test runner app, and then load my test case there, well, it's not exactly the greatest. But it is worth it, so I do it. Until now...

So I finally deployed the new version of cfcUnit and stuck the ant-cfcunit.jar somewhere easy, in an ant-cfcunit directory in my home folder, btw, put together a quick build script and, well a few minor glitches, but 15 minutes of tinkering later... cfcUnit tests! Right there in eclipse! And some nice simple output in the console! This is freaking great! (Can you tell I'm excited, btw?) But really, I'm working on very broad changes to the model in this app, top level logic changes that will effectively make changes all over the codebase. So I want to pretty much work in isolation right in test cases before I put these components into the model and check them inside the app logic. What I want to do is work in complete isolation of the rest of the app, and test at a very fine grained level. The great think about being able to do this right in eclipse is, all I have to do is start the cf server, but I never have to leave the editor. Even though running tests from the test runner app is still outside of the application, this just feels so much more natural, and, well, I guess more like JUnit. So thank you so much Paul and John Paul, much kudos to you!

Since it would be helpful of course to show how this is done, here we go. As I said, I deployed the new, soon to be released cfcUnit to my app server, and put the ant-cfcunit.jar in /Users/Chris/ant-cfcunit/. My build.xml file looks like so:

<project name="tests" basedir="." default="VerboseTest">

  <property name="home" location="/Users/chris/">
  <property name="hostname" value="localhost">

  <taskdef name="cfcUnit"
      classname="org.cfcunit.ant.CFCUnitTask"
      classpath="${home}/ant-cfcunit/ant-cfcunit.jar">

  <target name="VerboseTest">
    <cfcunit hostname="${hostname}"
            testcase="org.foo.unitTests.AllTests"
            verbose="true"
            haltonfailure="true"
            haltonerror="true"
            showstacktrace="true"/>
  </target>

  <target name="SimpleTest">
    <cfcunit hostname="${hostname}" testcase="org.foo.unitTests.AllTests"
            verbose="false"/>
  </target>

</project>


Next, open up the and view, load the build button and hit the little play button, and watch her go! You can see I have the verbose version set as the default, and can change to a simple version if I need. Also, I have set up a test suite, and each time I change a cfc, I write a test case and add it to the suite. So there you have it, now go and test!

1 Comments:

Anonymous Anonymous said...

Hi Chris,

taskdef defines name as "cfcUnit" and within the target it has reference to "cfcunit".(camel case).

This would result in error.

11:47 AM  

Post a Comment

<< Home