ColdBox Framework Forums Notification: Post to Using getPlugin() in cfcUnit creates error with coldbox controller (coldspring)

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?
Conference: ColdBox
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.
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbUnitTestingHandlersGuide#
TheBaseTestCase

IN Summary,

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.

[code]
<cffunction name="setUp"
returntype="void" access="private" output="false">
  <cfscript>
  //Setup
ColdBox Mappings For this Test
setAppMapping("/applications/coldbox/ApplicationTemplate");
setConfigMapping(ExpandPath(instance.AppMapping & "/config/config.xml.cfm"));
//Call the super setup method to setup the app.
  super.setup();
//EXECUTE THE APPLICATION START HANDLER: UNCOMMENT IF NEEDED AND FILL IT OUT.
//getController().runEvent("main.onAppInit");

  //EXECUTE THE ON REQUEST
START HANDLER: UNCOMMENT IF NEEDED AND FILL IT OUT
//getController().runEvent("main.onRequestStart");
  </cfscript>
</cffunction>
[/code]

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
/myApp/config/coldspring.xml.cfm.

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.
http://forums.coldboxframework.com/index.cfm?event=ehMessages.dspMessages&threadid=8A6EC886-FF65-CEF6-65606CFA2E50F4BA