Home » Questions » Computers [ Ask a new question ]

How can I unit test Flex applications from within the IDE or a build script?

How can I unit test Flex applications from within the IDE or a build script?

"I'm currently working on an application with a frontend written in Adobe Flex 3. I'm aware of FlexUnit but what I'd really like is a unit test runner for Ant/NAnt and a runner that integrates with the Flex Builder IDE (AKA Eclipse). Does one exist?

Also, are there any other resources on how to do Flex development ""the right way"" besides the Cairngorm microarchitecture example?"

Asked by: Guest | Views: 447
Total answers/comments: 4
Guest [Entry]

"The dpUint testing framework has a test runner built with AIR which can be integrated with a build script.

There is also my FlexUnit automation kit which does more or less the same for FlexUnit. It has an Ant macro that makes it possible to run the tests as a part of an Ant script, for example:

<target name=""run-tests"" depends=""compile-tests"">
<flexunit swf=""${build.home}/tests.swf"" failonerror=""true""/>
</target>"
Guest [Entry]

"On my project we're using Maven to build both our Flex RIA and the Java-based back end. In order to build and test the Flex app we use the flex-mojos maven plugins. They do a great job for us and I would highly recommend using Maven over Ant.

That being said, if you're already using Ant it can be a little tricky to transition over to Maven. So if you're in that position I would recommend using the flexunit tasks available here: Ant Task

Both of these libraries do basically the same thing, they launch a generated flexunit test runner mxml application in a window and open a socket connection back to the build process using a JUnit test runner. Amazingly enough it works pretty well. The only problem is that you can't run it headless so if you want to run the build from a CI server you have to make sure that process has the ability to launch new windows otherwise it won't work."
Guest [Entry]

"About how to develop Flex applications the right way, I wouldn't look too much at the Cairngorm framework. It does claim to show ""best practice"" and so on, but I would say that the opposite is true. It's based around the use of global variables, and other things you should try to avoid. I've outlined some of the problems on my blog.

I would suggest that you look at the Mate framework instead, which has good documentation and good examples to get you going. It uses Flex to its full potential, doesn't rely on global variables as Cairngorm and PureMVC, and it makes it possible to write much more decoupled code."
Guest [Entry]

An alternative to FlexUnit is the AsUnit testing tools. There are versions for actionscript 2 and 3. It also has good integration with Project Sprouts, which is a build tool for Flex and Flash similar to ant, however it uses ruby rake tasks and includes excellent dependency management along the lines of maven.