[Testbox] How do you test a Coldbox plugin with Testbox?

I have an existing mxunit test and the setup() function contains…

getController().getPlugin(‘PluginName’,true,true)

…which of course fails because there is no getController.

If I dump variables and arguments, there’s nothing obvious for linking to a Coldbox application.

The docs at http://wiki.coldbox.org/wiki/TestBox.cfm don’t say either way whether this is possible.

Can it be done?

Most likely are you extending from our ColdBox base testing clases?

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Luis wrote:

Most likely are you extending from our ColdBox base testing clases?

I can extend whatever I need to make it work.

The original testcase was extending coldbox.system.testing.BaseTestCase but the Testbox wiki page said extending isn’t necessary, so the file is looking like this:

component
{
function setup()
{
Variables.MathsUtils = getController().getPlugin(‘MathsUtils’,true,true);
}

function test_Percent()
{
$assert.isEqual( MathsUtils.Percent(0) , ‘0%’ );

}
}

I tried changing the test to testbox.system.testing.BaseTestCase and mxunit complains:

The COMPONENTNAME parameter to the startTest function is required but was not passed in.

That’s from {webroot}/mxunit/framework/TestCase.cfc : line 131 where it is set to testResult.startTest(this); so maybe a bug in mxunit, if it’s not obeying its own contracts?

I created a copy of the BaseTestCase file and changed the mxunit reference in that to the compat folder and then extended this new file, but line 111 fails:

Could not find the ColdFusion component or interface testbox.system.testing.mock.web.MockController.

Because that file doesn’t exist in testbox, it only exists in coldbox, so seems like it’s a bug/missing file in Testbox?

To see what would happen, I copied that one file across from Coldbox (creating appropriate directories), and I now get errors that seem to be Application/Coldbox config related - obviously don’t want to start looking into those without confirming whether this is a valid approach.

It seems Testbox/Coldbox isn’t correctly initialising Wirebox.

The variable wireboxdsl.scanLocations is an empty array in ioc.config.Binder when called via Testbox (but correctly reads values from config/Wirebox.cfc when going via the main application).

If I manually specify the appropriate config values in the Binder.cfc, the tests then run (using the copied MockController and modified BaseTestCase mentioned in previous message).

However there is an overhead for every CFC which seems equivalent to fwreinit being performed.

This means a set of tests that should take <1 second to run now takes ~12 seconds.

What’s peculiar is that just one of them doesn’t have this overhead - it runs in <15ms every time.

The fast running one is for the sole plugin we have that extends an existing plugin instead of extending coldbox.system.plugin - no idea if that’s related or just a coincidence, but AFAICT it’s the only significant difference I can see between this testcase/plugin and the others that have the slowdown.

No idea whether this is related to the way I’ve hacked things together, or a separate issue.

Also, there doesn’t appear to be a Testbox project on the Ortus Jira:
https://ortussolutions.atlassian.net/secure/BrowseProjects.jspa#10000
?

Slight progress - I figured out I can get Wirebox settings working by adding this to config/Coldbox.cfc

wirebox = {binder:‘config.wirebox’};

Again, this is not needed normally, and the config wiki page ( http://wiki.coldbox.org/wiki/ConfigurationCFC.cfm#wirebox ) claims it is the default, so it shouldn’t need specifying, but manually specifying it does seem to ensure the Wirebox settings are picked up.

What’s odd is that, after this change (and reverting the respective hack), ALL files now exhibit the overhead (including the one that previously ran faster).

So to summarise:

  • No changes to files within Coldbox and Testbox directories.
  • Copy {approot}/coldbox/system/testing/mock/web/MockController.cfc to {approot}/testbox/system/testing/mock/web/MockController.cfc
  • Copy {approot}/testbox/system/testing/BaseTestCase.cfc to {approot}/testbox/system/testing/CustomBaseTestCase.cfc
  • Change CustomBaseTestCase.cfc line 35 from “mxunit.framework.TestCase” to “compat.framework.TestCase”
  • Change CustomBaseTestCase.cfc line 43 to include the appMapping for the application to test.
  • All test CFCs extend “testbox.system.testing.CustomBaseTestCase”.

The tests are currently stored alongside testbox and executed with this code:

<cfset TestRunner = new testbox.system.testing.Testbox
( directory: { recurse:true , mapping:’/testbox/tests’ }
) />
#TestRunner.run()#

There are a few problems with some of the specific tests, but basically the are running.

The issue stopping me move forward is that it takes 12+ seconds to run the tests.

Also, there doesn’t appear to be a Testbox project on the Ortus Jira:

Can you try this direct URL:
https://ortussolutions.atlassian.net/browse/TESTBOX

Luis may need to make the product public still.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ok, updated the projects.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano