The ColdFusion Koans project is intended to teach ColdFusion syntax, techniques, structure, and tips and tricks through unit tests. Even if you are a seasoned ColdFusion developer the Koans can be a fun exercise to keep your skills sharpened. The Koans concept is nothing new, in fact, the Ruby Koans project is quite mature. Recently other languages, such as JavaScript, have also implement the technique.
What is great about the Koans concept is that not only do they teach the language but they also help promote a culture of unit testing. By teaching the language through a series of unit tests developers will hopefully develop good habits early into their ColdFusion programming careers. In a recent blog entry, I called out the community to help promote better practices in the ColdFusion community. This project is my attempt at doing something to help.
How Do They Work?
**If you don't want to read all this you can watch a short screencast (4 min) here.**
Getting started is simple. First and foremost you must have a development environment running ColdFusion 9 or newer (if anyone has a Railo or OpenBD server running and would like to test the Koans on them I'd love to hear if the project works on those servers as well). Once you have your development environment setup the next step is to download the Koans from GitHub at https://github.com/bittersweetryan/ColdFusion-Koans and copy the unzipped ColdFusion-Koans folder into your webroot. **Note, even if you have already mxunit installed its important to use the one that is packaged with the Koans project as it will run the test suites in the proper order. This custom mxunit does require the ability to create Java objects!** Once the Koans are in your webroot the next step is to open your browser and goto http://localhost/ColdFusion-Koans (this is assuming you are running a local development environment). If you are using a remote ColdFusion development environment then you'll want to go to http://yoururl/ColdFusion-Koans.
Getting started is simple. First and foremost you must have a development environment running ColdFusion 9 or newer (if anyone has a Railo or OpenBD server running and would like to test the Koans on them I'd love to hear if the project works on those servers as well). Once you have your development environment setup the next step is to download the Koans from GitHub at https://github.com/bittersweetryan/ColdFusion-Koans and copy the unzipped ColdFusion-Koans folder into your webroot. **Note, even if you have already mxunit installed its important to use the one that is packaged with the Koans project as it will run the test suites in the proper order. This custom mxunit does require the ability to create Java objects!** Once the Koans are in your webroot the next step is to open your browser and goto http://localhost/ColdFusion-Koans (this is assuming you are running a local development environment). If you are using a remote ColdFusion development environment then you'll want to go to http://yoururl/ColdFusion-Koans.
When you first load the Koans page all of the unit tests will fail. Your job is to go into the Koans/About___.cfc files and make those tests pass. This is typically done by filling in a value in a unit test assertion. For example, in the following test is in the AboutAsserts.cfc file:
public void function testStringsShouldBeEqual(){
var result = "Foo";
//in the koans __ represents a value that you need to fill in to make the test return true
//in some cases you'll want to keep the "" and in some you wont (see next example)
assertEquals(result,"__");
}
In this case you'd replace the "__" with "Foo" in the assertEquals() function.
In some cases you'll have to modify some code in the function itself to make the test pass. If you see an assertEquals() statement without a blank value ("__") that typically means that you'll have to modify some code in order to make the test pass. I've tried to add comments in the code to help you along the way.
Please Contribute!
I strongly urge anyone who has an idea for a test to please fork the Koans project, add your tests, and send me a pull request. I'd like to see some more intermediate to advanced concepts introduced so if you have an idea please don't hesitate to add it! The Ruby Koans project has been so successful because it has had a lot of community involvement. I've even seen a number of Ruby user groups devote talks on working through the Koans.

I think this is a great idea! I know, at my workplace, unit testing our ColdFusion is seriously lacking. I'm eager to dig into your Koans to share with my team.
ReplyDeleteRelated, I'm a big fan of Open BlueDragon, and your Koans don't currently work on them. However, I'm working on a pull request to help make this project more cross-engine friendly.
@m!les - thanks for the comment, and thanks a bunch for helping out with openBD, I've actually JUST push a fix for Railo but I couldn't get that patch to run on openBD 2.0 either.
ReplyDeleteThanks for your work on this project! I learned several cool new things going through them.
ReplyDeleteCouple questions:
In AboutFunctions.cfc's 'testAttrubutesCollection' fn you have:
var myStruct = switchParams( attributeCollection = aCollection);
Did you mean that to be 'argumentCollection'?
var myStruct = switchParams( argumentCollection = aCollection);
In AboutComponentTags.cfc you have:
It was complaining it couldn't find the TestComponent.cfc component since the case was off in the invocation (probably works in Windows but will be a problem for any Unices). Here's the fixed invoke.
Thanks again...
Eric P.
Here's that second item again (hopefully escaped properly this time):
ReplyDeleteIn AboutComponentTags.cfc you have:
<cfinvoke component="Components.testComponent" method="get#i#" returnvariable="retVar" />
It was complaining it couldn't find the TestComponent.cfc component since the case was off in the invocation (probably works in Windows but will be a problem for any Unices). Here's the fixed invoke.
<cfinvoke component="Components.TestComponent" method="get#i#" returnvariable="retVar" />
Hi Eric,
ReplyDeleteThanks for the comments. The attributescollection test was was actually written by somebody else and they have said that they will be fixing that soon. Thanks for the reminder to follow up.
Thanks for fixing that case issue. I was developing on Windows when I wrote the Koans, but I'm on a Mac now so I'll catch those things now. Do you want to submit a pull request for the correction and get some credit for it? If not I can make the change and list you on the contributors readme.
Ryan,
ReplyDeleteYou can go ahead and make the change.
I do hope in the future to find some time to contribute some helpful koans of my own. I'll try to stay mindful of potential koans whilst I pound away at the keyboard. I really like the idea/approach for this project.
Thanks again,
Eric P.
Hi Ryan,
ReplyDeleteDo you know about Maven pom.xml?
I am messing around with Railo in Jelstic and it can use Maven to pull in a GIT repo, but it needs a pom.xml