With CF9 on the horizon, I'm back using ColdFusion again (yay!). I'm rolling out a new project at Booz Allen, and I'm knocking out a bunch of unit tests this morning. One thing I miss in MXUnit versus what I've been using in the J2EE world is the ability to easily use a (Cold)Spring factory from within my tests. Spring provides handy integration classes for this. Borrowing from its ideas, and adding a little bit of ColdFusion dynamic easiness, I've cooked up what I call the ColdSpringXMLBeanFactoryTest. It's a simple extension of mxunit.framework.TestCase that lets you annotate a test with needing a specific beans XML file. Basically, here's all you need to do to create a test that'll load up a bean factory using the beans in both "/conf/beans.xml" and "/conf/testBeans.xml" and wire a bean named "SomeDAO" into variables.beans.SomeDAO:
<cfcomponent extends="ColdSpringXMLBeanFactoryTest" beansXml="/conf/beans.xml,/conf/testBeans.xml" beans="SomeDAO">
Things to note:
- Multiple bean xml paths and beans are comma-delimited lists
- The bean factory is created once per-request: if a second test needs it, it'll reuse the bean factory from the first. The same bean XML will not be loaded twice.
- Inheritance is supported: it walks up your metadata chain, allowing definitions of beansXml and beans at each point.
Comment 1 written by marc esher on 11 September 2009, at 10:26 AM
Comment 2 written by Bob Silverberg on 11 September 2009, at 10:26 AM
I found that changing my approach to use mocks instead made things much cleaner. So I'm wondering in what situations you find this beneficial?
Comment 3 written by Joe Rinehart on 11 September 2009, at 10:47 AM
I should've used better terminology - these are basically higher level integration tests where I'm testing Flex remoting endpoints that wrap Coldspring-managed services. Yep, they could wrap a mock that always "behaves," but I like to have a full-stack test in place at this level.
Comment 4 written by Jamie Krug on 11 September 2009, at 2:35 PM