G'day:
This article is more an infrastructure discussion, rather than examining more actual testing stuff. The ever-growing
*Box empire has recently borged into yet another part of the CFML community: testing. They're released another box...
TestBox. TestBox is interesting to me as it has a different approach to testing than MXUnit has... rather than
xUnit style assertion-based testing, instead favouring a
BDD approach. I've not done a lick of BDD, but people keep banging on about it, so I shall be looking at it soon. -ish. First I need to switch to TestBox.
One appealing thing I had heard about TestBox is that it's backwards compatible with MXUnit, so this should mean that I can just do the switch and continue with my current approach to testing, and ease my way into BDD as I learn more about it. So the first thing I decided to examine is how well this stands up, and how many changes I need to make to my existing tests to get them to run. Realistically, nothing is every completely backwards compatible... not even say between different versions of the same software (ColdFusion 9 to ColdFusion 10), let along a second system emulating another system (eg: Railo and ColdFusion). This is fine. I don't expect this migration to be seamless.
Here's what I worked through this morning to get up and running (spoilers:
kinda running) on TestBox.
I preface this with the fact that I have always found Ortus's documentation to be a bit impenetrable (there's too much of it, it waffles too much), so I was hesitant about how long this would all take.
Locating, downloading and installing
Finding it
I
googled "testbox", and the first link was the
ColdBox Platform Wiki - TestBox. This is promising. Within a paragraph (and a to-the-point paragraph which just intros the product, so maybe the docs have got some improved focus: cool) there were download links. TestBox requires ColdFusion 10 / Railo 4.1, btw. I presume it uses closure or something? I'm not sure. But that's cool, I use CF10 and Railo [latest] for my work for this blog. It does preclude me from
really giving it a test our with our 3000 unit tests at work though (which is a shame), because we're still on CF9 and will be for the foreseeable future.
Installing it
The installation instructions threw me a bit. The default suggestion is to put the
testbox dir into the web root, but that's poor advice: only files specifically intended to be web browseable should ever be in your web root. Fortunately the also mention one can stick 'em anywhere, and map them in with a
/testbox mapping. I wish this was their default suggestion. In fact I wish it was their only suggestion. They should not encourage poor practice.
There's a caveat with this though (and this is where I had problems), is that TestBox does have some web assets which need to be web browseable, so it does actually need a web mapping, not just a CF mapping. They do caveat this further down the page.
The first pitfall I had was which directory they're actually talking about. The zipfile has this baseline structure:
/testbox_1.0.0/
testbox-1.0.0.00062-201312171237
apidocs/
browser/
runner/
runner-template/
samples/
testbox/
license.txt
mockbox.txt
testbox.txt
So I homed this lot in my CF root (not web root, CF root) as
/frameworks/testbox/1.0.0/, and added a
/testbox CF mapping to that location.
WARNING (if you're following along and doing this at the same time): this is not the correct thing to do. Keep reading...
I then had a look around for which directory I needed to add a web server virtual directory for, and found web-servable assets in the following locations:
/apidocs/
/browser/
/runner/
/samples/
/testbox/system/testing/reports/assets/
(I searched for images, JS, CSS, HTML and index.cfm files; not perfect, but will give me an idea).
OK, so I figured he apidocs and samples are separate from the TestBox app, but that still leaves three disconnected (and laterally displaced) directories which need to be web browseable. This ain't great. So basically it looks like I need to make the entire
/testbox dir web browseable. That's a bit shit, and a bit how we might have set up our CFML-driven websites... ten years ago. Oh well.
Configuring Tomcat
Here's a challenge (cue: Sean to get grumpy). I have no idea how to set up a virtual directory on Tomcat's built-in web server. Fortunately that's what Google is for, so I googled "
tomcat web server virtual directories", and the very first link is a ColdFusion-10-specific document: "
Getting Started with Tomcat in ColdFusion 10". I shuddered slightly that this is just in the ColdFusion Blog, rather than in the CF docs where it belongs, but it'll do. Fortunately the info in there is accurate, which is good.
Basically there's a file
server.xml located at
<ColdFusion_Home>/runtime/conf/server.xml, where
<ColdFusion_Home> is the
cfusion dir in your ColdFusion install directory. For me the
conf dir is at:
C:\apps\adobe\ColdFusion\10\cfusion\runtime\conf.
In there there's an XML note like this:
<Context
path = "/"
docBase = "<cf_home>\wwwroot"
WorkDir = "<cf_home>\runtime\conf\Catalina\localhost\tmp"
>
</Context>
It's commented out by default. All the instructions one needs are in the file itself, but basically it's uncomment it, put actual paths in, and add an
aliases attribute:
<Context
path = "/"
docBase = "C:\apps\adobe\ColdFusion\10\cfusion\wwwroot"
WorkDir = "C:\apps\adobe\ColdFusion\10\cfusion\runtime\conf\Catalina\localhost\tmp"
aliases = "/testbox=C:\webroots\frameworks\testbox\1.0.0"
>
</Context>
I restarted CF and browsed to
http://localhost:8500/testbox, and I got the files in my
C:\webroots\frameworks\testbox\1.0.0 directory listing, so that worked. Good to know. I'll now forget about
server.xml and
aliases and stuff as I won't need to do it again for another six months. Shrug.
ColdFusion config
I put a mapping to the same place in my test app's Application.cfc:
// Application.cfc
component {
this.mappings = {
"/cflib" = getDirectoryFromPath(getCurrentTemplatePath()),
"/testbox" = expandPath("/testbox") // CF will use the virtual directory to resolve that. This is slightly cheating, but hey
};
}