Wednesday, June 13, 2007

All together now: FlexUnit, Cassini, WatiN and MbUnit

Last week I decided to work on being a little bit more sophisticated about testing my ActionScript 3 code. I was extracting a bunch of stuff out of my Odin project to add to the Castle.FlexBridge client-side components (including the Inversion of Control container I mentioned earlier).

As always, having some automated tests is always better than having none! So I tried out FlexUnit. It's a minimalistic port of JUnit for ActionScript with a simple Flex-based test runner. Works like a charm. See Adobe's article for more information.

So then the tricky thing was to make sure I could run the tests all of the time. Unfortunately, there isn't a nice command you can easily integrate into your build tool chain to run your FlexUnit tests. No problem! I'll just write an MbUnit test that starts Cassini to host the SWF file, fires up a browser with WatiN, runs the tests and reports the results. Easy as pie!

And when I'm done the results end up in my MbUnit report. It's not very sophisticated but it works!

 5906.401ms 224.96 Kb, 1 
Console Output
1) [PASS] testEmptyClass (castle.flexbridge.tests.reflection::ReflectionUtilsTest)
2) [PASS] testKitchenSinkClass (castle.flexbridge.tests.reflection::ReflectionUtilsTest)
3) [PASS] testKitchenSinkInterface (castle.flexbridge.tests.reflection::ReflectionUtilsTest)
4) [PASS] testEmptyInterface (castle.flexbridge.tests.reflection::ReflectionUtilsTest)
5) [PASS] testDefaultComponentModelBuilder (castle.flexbridge.tests.kernel::DefaultKernelTest)
6) [PASS] testSingletonWithConstructorDependencies (castle.flexbridge.tests.kernel::DefaultKernelTest)
// --- snip --- //

If you want to see how this all gets plumbed together, check out the Castle FlexBridge source. See here for more details: Castle.FlexBridge.

No comments: