I’ve been getting into unit testing and test-driven development a lot lately. Flash Builder has pretty nice support for FlexUnit, which I find to be the easiest way to include testing in my development workflow.
However, one problem is that Flash Builder ships on a different schedule than FlexUnit, so when a new FlexUnit version comes out Flash Builder doesn’t include it until at least the next major release. This has turned out to be a problem for me. Flash Builder 4.5 includes FlexUnit 4. However, FlexUnit 4 has a bug that makes it so you can’t run more than a certain number of tests. (I can’t remember how many exactly, and it probably varies a bit, but it’s something like 25 or 30.) If you’re doing TDD you’re going to hit that limit. This bug is fixed in FlexUnit 4.1…but of course since FlexUnit 4.1 is still a “release candidate” it isn’t included with Flash Builder 4.5.
Fortunately, the Flash Builder team realized that they can’t depend on being in sync with FlexUnit for every release. There’s a new feature in Flash Builder 4.5 that lets you specify an alternate FlexUnit framework to use instead of the one that’s bundled with Flash Builder.
To specify your alternative FlexUnit is easy:
- Open Flash Builder Preferences > Flash Builder > FlexUnit
- In the “Alternative Framework Settings” section check the “Use alternative framework” box
- In the “Framework directory” field browse to the folder where you put your alternative FlexUnit sdk
The trick is knowing how to set up your FlexUnit framework folder. Flash Builder expects certain SWCs to be in certain places. Unfortunately the names and setup of the built-in framework folder in Flash Builder don’t match the download from the FlexUnit site, so you have to do a little manual rearranging.
Here’s how to lay out your FlexUnit framework directory:
- Create the top-level directory
Inside that directory, create three subdirectories with the following names:
- Browse to the FlexUnit download page
- Download the “full project download” “4.1 SDK” version
- Unzip the download and open the folder
- Copy the FlexUnit AS3 SWC (currently “flexunit-4.1.0-8-as3_22.214.171.12476.swc”) into the “ASProject” folder in your FlexUnit framework directory.
- Copy the FlexUnit Flex SWC (currently “flexunit-4.1.0-8-flex_126.96.36.19976.swc”) into the “FlexProject” folder you created.
- Copy the “turnkey/libs/hamcrest-as3-flex-1.1.3.swc” file into the “Common” folder you created.
If you use other extensions with FlexUnit, copy those SWCs into the “Common” folder also.
For example, I use Mockolate with some of my tests, so I downloaded Mockolate and put the SWC (currently “mockolate-0.10.0.swc”) in the “Common” folder.
Update: Mockolate has now been updated to version 0.11.0, and in the new download it has separate “as3” and “flex” SWCs. Since there are separate SWCs it’s probably best to put them in their respective folders instead of the “Common” folder, but I haven’t had a chance to test this and verify it.
- Tell Flash Builder to use your FlexUnit framework instead of the built-in one, as described above.
I think it’s great that Flash Builder lets you specify your own FlexUnit framework now. The biggest problem I ran into was just confusion on how to set up the custom framework folder, especially the question of which SWCs go where. I’ve talked to Adobe and to Mike Labriola (representing FlexUnit) about this and they have said they definitely want to make things easier. Ideally (from my perspective at least) they’ll make a drop-in “Flash Builder” download bundle that’s all set up for use in Flash Builder.