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.

Download ColdSpringXMLBeanFactoryTest