Testing a Plugin

Hi all,

I need to be able to test a plugin which needs some information from
the event. Namely the current module.

I can't for the life of me work out how I can test this plugin, and
mock the current event without actually running the event as I just
want to unit test the plugin and this one function.

Any pointers gratefully received.



Good question Kev, I'd be interested on ideas for this too.

I currently use an integration tests to hit handler methods to test it.


I would try to create an instance of “coldbox.system.web.Context.RequestContext” using MockBox and mock the result you need to test. But, I don’t think ColdBox will check the type of object you pass, so, you actually can probably get away with just using a stub"

MockBox = new coldbox.system.testing.MockBox();

SUT = new plugin_to_test();

MockEventObject = MockBox.createStub(false);



Something like this from the What's new should help, if you need more info
please let me know.

<cfcomponent extends="coldbox.system.testing.BasePluginTest"
function testaddAssetJS(){
  var mockEvent = getMockRequestContext();
  mockRequestService.$("getContext", mockEvent);
  // mock the plugin's htmlhead method
  // Call method to test
  debug( plugin.$callLog().$htmlhead);
  // test duplicate call
  assertEquals('<script src="test.js"
type="text/javascript"></script><script src="luis.js"
type="text/javascript"></script>' , plugin.$callLog().$htmlhead[1][1] );
  assertEquals(1, arrayLen(plugin.$callLog().$htmlHead) );

function testTableORM(){
  data = entityLoad("User");
  str = plugin.table(data=data,includes="firstName");



Andrew Scott

Andrew hit it on the spot. You now have targeted tests for each part of ColdBox: plugin, model, handler, etc. In the what’s new you can find more information.