Testbox to test model and handlers

Hello-

I was at Into the Box and got fired up about implementing Testbox. However I find myself stuck getting started….I am trying to test a method in a cfc using this: http://wiki.coldbox.org/wiki/TestBox-unit-primer.cfm I cannot find where to tell it what cfc it should be testing and how to have access to that model. I thought it was slick how the mxUnit worked (http://wiki.coldbox.org/wiki/Testing.cfm#Model_Object_Testing) and just am wondering if I am missing something with TestBox or if I just need to use mockbox or wirebox to bring in the object to call methods on ? Or do I still use the http://wiki.coldbox.org/wiki/Testing.cfm#Model_Object_Testing style? Any examples you have up would be great as I could not find any on any of the Testbox primers… Thanks!!

My current code for testbox….my cfc is called UDFs and the method I am trying to test is addNumbers:

component displayName=“UDFsTest” {

/*********************************** LIFE CYCLE Methods ***********************************/

function beforeTest(){

}

function afterTest(){

structClear( application );

}

function setup(){

}

/*********************************** TDD SUITES ***********************************/

function testaddNumbers(){

$assert.isEqual( 4, addNumbers(3) );

}

}

From the UDFs cfc:

component output=“false” displayname=“UDFS” hint=“I contain user defined functions” {

public any function init(){

return this;

}

public numeric function addNumbers ( required numeric num ){

return 2 + num;

}

}

I’m a little surprised when I looked at the docs and saw the sample tests use Wirebox to load the object being tested. It’s my understanding that dependencies should be mocked, so you’re truly only testing the code within the object you’re testing. A simple new() (or createObject()) in the setup() method is how I’ve always done it. Something like…

function setup(){

variables.theObject = new myObject();

}

function testaddNumbers(){

$assert.isEqual( 5, variables.theObject.addNumbers(3) );

}

The 'Box stuff generally has hidden gems with annotations (like the “model” attribute on the component signature) but I tend to gravitate to regular ole explicit CFML. It’s not much more code and it seems easier for a non-Box’r to follow.

This is a very old post, as TestBox has changed a lot since this post, but it should give you some direction.

http://www.andyscott.id.au/blog/coldfusion-unit-testing-and-using-mockbox

That is what I was looking for…thanks guys!