Auto Generating Unit Tests With cfcGenerator

Earlier this week Peter Bell asked if anyone was doing anything in the way of auto generating unit tests. Well, I've been using Brian Rinaldi's cfcGenerator for a project at work and early on I realized that having some unit tests for all the components I was creating with the tool would probably be a good thing. If you haven't seen Brian's tool it is very cool. Out of the box it generates Bean, DAO, Gateway and Service objects for a database table as well as a ColdSpring snippet which you can use in your bean definition XML file. The really great thing about this tool is that it is very easy to extend and customize. So knowing I really should be building unit tests and seeing how easy it was to work with the cfcGenerator I decided to download cfcUnit spent a couple of hours hacking together a way to generate some unit tests using the cfcGenerator.


Dan Wilson's Gravatar Great first cut Nathan. Thanks for sharing...
# Posted By Dan Wilson | 11/17/06 9:50 AM
Brian Rinaldi's Gravatar Nice work! Perhaps we can refine this to be included into a future version of the generator if you wouldn't mind. Hopefully we can talk and explore this further.

I got your link from Peter Bell's blog post and I commented there with some info on an upcoming significant release of the generator, hopefully to happen this weekend with some new features and a UI redone in Flex 2.
# Posted By Brian Rinaldi | 11/17/06 10:27 AM
Nathan's Gravatar Brian, I'm definitely interested in exploring this further. The generator has been a huge time saver for me and adding some sort of unit test generation could only make it that much better!

I'm looking forward to seeing the new Flex version.
# Posted By Nathan | 11/17/06 11:35 AM
Justin Treher's Gravatar Has anything else been done with CFUnit in CFCgenerator?
# Posted By Justin Treher | 6/1/07 10:51 AM
Nathan Mische's Gravatar Brian Rinaldi and I spoke about this a little bit at cfObjective. Apparently people are interested so I told him I would investigate it further. To be honest I'm kind of stuck on how to handle the database for DAOs and Gateways. Terrence Ryan posted about generated unit test for his Squidhead framework, so I've been meaning to check that out and see if I get any ideas.

The other problem I have is that the other CF developer on my team at work is leaving. His last day is today so, as much as I want to, I'm probably not going to have a lot of time to work on this over the next month or so.
# Posted By Nathan Mische | 6/1/07 11:40 AM
Justin Treher's Gravatar Thanks for the update. It would definitely be cool to see something done. Although, with as many generators and utilities coming out on a monthly basis, it may get lost. I don't know what the user base is for these vs. an ORM right now.
# Posted By Justin Treher | 6/1/07 2:08 PM
Brian Rinaldi's Gravatar I am happy to add that feature. I have not personally used any unit testing framework as of yet, which is why I asked Nathan to assist - though there are some other generators out there that are purely about generating unit test stuff (check out Brian Kotek's generator).

As for a user base, I have no exact number. I know that since I started tracking the generator has been download some 1500+ times from the two locations I have it available. It seems to have a pretty wide user base...but remember I work on this for free.

As for ORM, you are comparing apples and oranges. I mean the generator will actually even help you if you use transfer ORM since it generates transfer compatible files via one of the templates. Plus, no offense to Transfer, but ORM is not always the solution - sometimes hand-coding works nicely! Remember, the generator is about getting a head start, it is not about handing you off a complete application.
# Posted By Brian Rinaldi | 6/1/07 2:41 PM
Justin Treher's Gravatar Thanks Brian.

I'm actually not using an ORM as I don't want to become detached from the code, that's why I'm using your generator. I know that transfer needs the db info fed in, but I was thinking more of Reactor. I suppose I could look into an additional utility for unit testing, but I'm kind of a newb. I'll check out kotek's stuff.

So, in summary, if you get it in there, I'd use it :)

Happy Weekend!
# Posted By Justin Treher | 6/1/07 4:42 PM
Nathan Mische's Gravatar There is also Stubbie by Greg Stewart, which may be worth looking at:
# Posted By Nathan Mische | 6/1/07 4:50 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.