Title: RE: Using getPlugin() in cfcUnit creates error with coldbox controller (coldspring)
Thread: Using getPlugin() in cfcUnit creates error with coldbox controller (coldspring)
Forum: Need Help?
User: lmajano Hi
first of all, GOOD JOB!! You are doing unit tests!!
ColdBox comes with
its own baseTest that is based off cfcunit and can easily be ported to CFUnit by
just changing the extends part of it.
Look at the unit testing guide so you
can see how to build your unit tests for working with coldbox directly.
The base test case has a provided set of
methods that you can use to load of the coldbox app you want to test. Look at
the samples, its pretty easy.
returntype="void" access="private" output="false">
ColdBox Mappings For this Test
setConfigMapping(ExpandPath(instance.AppMapping & "/config/config.xml.cfm"));
//Call the super setup method to setup the app.
//EXECUTE THE APPLICATION START HANDLER: UNCOMMENT IF NEEDED AND FILL IT OUT.
//EXECUTE THE ON REQUEST
START HANDLER: UNCOMMENT IF NEEDED AND FILL IT OUT
As you can see from the sample, just set the
AppMapping and the configLocation of the ColdBox app you want to tap into. Once
you do, you are guaranteed that the unit test will have a controller and
application to work with. So you don't necessary need to test handlers, you can
test plugins, interceptors and much more.
As an Important note:
If you use
relative paths in your application, as for example, where the coldspring.xml is
located = "config/coldspring.xml.cfm" THe unit testing framework will make it
fail, because it actually runs inside of the cfcunit testing framework. So in
order for these to work, just change them to a full path from the root of your
application. If they are in the root then config/coldpsring.xml.cfm will work,
but let's say the app is located at /myApp, then you place
As for best practice, I usually create my
own coldbox.xml.cfm for unit testing and load it up for testing. That way I can
configure my own settings for unit testing and mockups. This is easily done by
the setup method show, just tell it which config file to load.
Let me know
what is not clear.