If you’ve been keeping up with my blog over the last couple months, then you already know that I’ve been experimenting with test driven development. I love the work flow, the way it makes me view my code, and the peace of mind…I just don’t know that it will pay off in my work environment. Hence the experimentation.
Most of my TDD dabbling up to this point has been done in Ruby. I’ve finally gotten around to messing around with some of the major ColdFusion testing frameworks: cfunit, cfcUnit and finally MXUnit.
After doing small projects with each of them, I’ve finally decided to settle down with MXUnit. It’s got decent docs, a nice work around for private methods, I dig the web interface, the eclipse plug-in is great and creating my own stubs for the generator was a snap!
In short: Two thumbs up!
Here’s my test. I’m still really new to this sort of thing, so I’d love feedback should you feel so inclined:
function Setup() {
this.cfc = CreateObject( "component" , "BaseObject" );
this.cfc = this.cfc.init();
makePublic( this.cfc, "SetInstance" );
makePublic( this.cfc, "Set" );
makePublic( this.cfc, "Has" );
makePublic( this.cfc, "Get" );
makePublic( this.cfc, "OnMissingMethod" );
}
function TestSetInstance() {
var value = "a";
AssertEquals( value, this.cfc.SetInstance( value ) );
value = StructNew();
AssertEquals( value, this.cfc.SetInstance( value ) );
}
function TestGetInstance() {
var value = "a";
this.cfc.SetInstance( value );
AssertEquals( value, this.cfc.GetInstance() );
value = "b";
this.cfc.SetInstance( value );
AssertEquals( value, this.cfc.GetInstance() );
}
function Testinit() {
var value = "a";
this.cfc = this.cfc.init( value );
AssertEquals( value, this.cfc.GetInstance() );
this.cfc = this.cfc.init();
AssertEquals( StructNew(), this.cfc.GetInstance() );
}
function TestSet() {
var field = "a";
var value = "1";
AssertEquals( value, this.cfc.Set( field, value ) );
field = "w";
value = "2";
AssertEquals( value, this.cfc.Set( field, value ) );
}
function TestHas() {
var field = "a";
var value = "1";
AssertEquals( false, this.cfc.Has( field ) );
this.cfc.Set( field, value );
AssertEquals( true, this.cfc.Has( field ) );
field = "w";
value = "2";
AssertEquals( false, this.cfc.Has( field ) );
}
function TestGet() {
var field = "a";
var value = "1";
this.cfc.Set( field, value );
AssertEquals( value, this.cfc.Get( field ) );
field = "w";
value = "2";
this.cfc.Set( field, value );
AssertEquals( value, this.cfc.Get( field ) );
}
function OnMissingMethod() {
var value = "a";
AssertEquals( value, this.cfc.SetSomething( value ) );
AssertEquals( value, this.cfc.GetSomething() );
}
Click to download the component I’m testing and the file above. Now.