Tuesday, August 11, 2009

FlexUnit Plugin for Eclipse

Since we intend to do unit testing in our Flex+Java development, I have been playing with FlexUnit and have found an eclipse plugin that makes it easier to use (also, in plugin central). Here's a summary and lessons learned on how to start with the plugin

Installation
Follow the installation instructions from here. Once installed, open the plugin's help in Eclipse and configure it. A few points:
  • Download FlexUnit and FlexUnit extension for the plugin.
  • You will need to have Flex Builder 3.
  • You will need a debugger version of Flash Player (I used version 10). A standalone player used by the plugin comes with Flex Builder (directory: player)
  • Follows instructions from Adobe on how to enable logging and error output for Flash Player. When you follow them, after you create a mm.cfg file, you will need to restart all instances of Flash Player for the Logs folder to show up.
Using The Plugin
To use a plugin:
  • Create a unit test using Flex Builder's wizard. I recommend keeping them in another source folder, so they can be easily skipped when releasing the app. For example, keep the flex source in flex-src and flex tests in flex-test. The server code put in java-src and java-test, or whatever language you use for the middle-tier.
  • Create a harness. Right click in the test file in the project navigator, find FlexUnit menu and select Create Harness. This will create a small mxml file for your test. However, if you use FlexUnit 0.9, the code needs a correction. Replace:
    EclipsePluginTestRunner.runTests( new Array(AccountTest.suite()) );
    with
    EclipsePluginTestRunner.run( AccountTest.suite() );
  • Run the test. Right click on the harness file and select Run from the FlexUnit menu. Observer the test results on the nice eclipse viewer.
I had the problem that the test launch process never finishes in eclipse. But it doesn't seem to be harmful. Just ignore it.

Summary
It's a great plugin. It could do quite a bit more, but it's a great start. It worked for me with a FlexUnit 4, when I used the syntax of FlexUnit 0.9. When I switched to FlexUnit 4 syntax, I didn't have to apply the correction mentioned above to the auto-generated harness to compile. However, I didn't get my tests executed. So, I guess, for now, using the FlexUnit 0.9 is a better option. However, I have heard from the plugin author that he intends to do another release of the plugin.

No comments: