We have an issue with our test setup and I’m having troubles nailing down which bit we haven’t got quite right yet.
We have an application.cfc in our test directory that extends our regular coldbox app’s application.cfc and we’ve set the wsdl in the MXUnit properties on our project to point to our test directory per the docs. We can even run the unit tests ok. Once. After you run a test once then you can try to run it again and we get this exception:
(500)Element cbController is undefined in a Java object of type class coldfusion.runtime.ApplicationScope.
Oddly enough, if you then go hit one of the coldbox app’s pages in a browser and then try running the unit test again it runs fine. Once. For now we’ve been working around the issue by doing just that - hitting a page in the browser just prior to running each test. Obviously this isn’t ideal if we want to automate our tests.
I’ve traced down the issue to BaseTestCase’s afterTests() function which looks like it removes the coldbox instance from the application scope. In our MyAppBaseTestCase that extends the coldbox BaseTestCase I’ve added in an empty afterTests function that doesn’t call super, and now I can run unit tests repeatedly without having the exception thrown. Still not ideal (feels very much hacky), and you still have to hit the app once before starting to run tests locally. I think this will also still not work well with an automated testing setup.
When I restart the ColdFusion server and then try to run the tests without hitting any pages (which would do all of the onApplicationStart stuff) I get a server 500 error w/o any more specific info from MXUnit in CFBuilder. The details say to hit the WSDL&method=ping in a browser, which I do and it looks like that is (due to our test application.cfc extending our app’s application.cfc) running into issues where the session scope doesn’t exist yet. (Do we need to not extend the regular application.cfc?)
Mainly I’m looking for anything to try or any obvious stuff I may have missed (or read in the docs but misunderstood). Any help would be greatly appreciated.
thanks!
P.S.
Some additional info:
- we’re bootstrapping coldbox in our application.cfc
then in onApplicationStart():
<cfset super.onApplicationStart() />
<cfset application.cbBootstrap = CreateObject(“component”, “coldbox.system.Coldbox”).init(COLDBOX_CONFIG_FILE, COLDBOX_APP_ROOT_PATH, COLDBOX_APP_KEY, COLDBOX_APP_MAPPING) />
<cfset application.cbBootstrap.loadColdbox() />
When I inspect the application scope after hitting a page I see cbBootstrap and cbController containing Coldbox and Controller instances respectively. In our onRequestStart we check for application.cbBootstrap and create it if it doesn’t exist.