There have been a couple of questions on the Google FlexUnit list recently about how to structure a project for unit testing. I’m putting my response here so that I can point others at this post in the future.

If you’re interested in doing testing as part of an automated build script, one of the best resources is Antennae. Antennae is an Allurent open source project and does much more than automated testing (compiling, etc.) but it provides a good example of one way to structure a project.

Also, I use a “modified antennae” approach for the Visual FlexUnit (VFU) project. Wheres Antennae tends to use Allurent-standard folder naming (“flex2″, etc.), I decided to use more standard folder names (“src”, etc.) for VFU, so that non-Allurent users would find it a bit easier to incorporate into their projects.

BTW, you might also want to take a look at my Testing, Debugging & Agile Methods page – you’ll find a lot of related links there, and I update it regularly.

HTH! :)

Visual FlexUnit (VFU) is a FlexUnit extension that allows you to do automated testing of components’ visual appearance using “visual assertions”. In a nutshell, a visual assertion asserts that a component’s appearance is identical to a stored baseline image file. These visual tests can be run in either a GUI or an Ant-based build process.

I created VFU during my recent internship at Allurent. We’re releasing it as open source on Google Code under the MIT license. Its home page is here.

Why should you be interested in VFU? Here’s an extract from its main documentation page:

Why Is This Useful?

Regression Testing

By adding visual tests to your build process you can be assured that any changes to your codebase, or to the Flex/Flash framework, that effect the appearance of your components will be noticed immediately.

Testing For Cross-Platform Rendering Differences

While Adobe has done a great job of making Flash & Flex a write-once / deploy-anywhere platform, there may be differences in how images render:

  • Between the Flash Player and the AIR runtime
  • Between Windows, Mac, and Linux
  • And, of course, between the many combinations of these variables

To date our limited testing has only detected a) differences that aren’t visually noticeable, and b) differences in very unusual cases that you would never use in the real world. Still, it doesn’t hurt to check. By running regression tests on multiple platforms you can be assured that any unseemly differences in component rendering will be brought to your attention quickly.

(end of extract)

We invite you to play with VFU and would love to get your feedback. You can either enter issues into Google Code or add a comment to this post. While it looks as though this could be a very useful tool, at this point we haven’t worked with it enough to assert that visual assertions belong in your toolkit. :) Let us know what you think!

The following people contributed greatly to this project, and made my work on VFU both easier and extremely educational. Thank you!:

Finally, I should mention that Allurent is an extremely smart and competent company, at the forefront of Flex development, and a really nice group of people. I learned an incredible amount working there, including a great deal about using Ant to implement automated build processes. (I’ll be blogging shortly about the Ant build process that I’ve included with VFU.) If you get an opportunity to work with Allurent, I suggest that you grab it.

It’s been a goal of mine for some time to learn how to implement unit testing, test driven development and continuous integration. I’ve understood these concepts in the abstract but, as a freelance programmer working on my own, the barriers to entry have been a bit too high for me to take the plunge.

With Allurent‘s release of their Antennae Ant-based build framework all this has changed. Antennae provides a framework that automates the entire build/test/deploy process. Its use can speed you on your way to one of the holy grails of software development – the one-click build – for your Flex projects.

Here are a few of its features:

  • You can build multiple projects with, of course, one click
  • Projects can contain sub-projects
  • Some of your projects can be code libraries, and you can specify which libraries each project uses.
  • Antennae compiles projects using mxmlc, and libraries using compc…
  • And runs unit tests using FlexUnit

Above I said that Antennae will ‘speed you on your way’. Well, speed is a relative thing. If you’re fairly new to Ant (as I was) you’ll still have some studying to do. I invested a good deal of time studying the Ant manual and Antennae’s code. What Antennae did for me was to move my goal from the realm of “I’d like to do this, but where do I start?” to “I can do this!”

As part of my process I decided that I should get a good overview of Ant. I learn best by taking notes so I ended up developing – not precisely an ‘Ant cheat sheet’ – but more of an ‘Ant reminder sheet’. Simply stated, it’s a list of much of what Ant can do in ‘somewhat organized’ format. I don’t know how helpful it would be to others, but you’re welcome to take a look. Here’s a download link (right click & “save link as”):

AntRef.doc

It’s a Word doc consisting of three pages of fairly fine print, which says something about Ant’s extensive capabilities. Also, be aware that it’s oriented towards Flex developers and omits some of Ant’s extensive Java-related capabilities.

I’m still far from an Ant expert but at least I’ve got an overview. And I’m happy to report that I’ve now implemented the Antennae framework for my own projects and am happily doing one-click builds. :)