Start using the FlexUnit 4 beta today

22.06.09

Filed Under: Flex

I’ve been playing around with the beta of FlexUnit 4 and I must say that it is exceeding my expectations. The single most painful thing to do in FlexUnit is to perform unit testing of user interactions. With the amount of code and pain involved in doing so not many people used the framework. However with FlexUnit 4 it’s so much easier, thanks to the inclusion of the Fluint framework into FlexUnit.

You should upgrade now!

There is no reason why you should not upgrade today. FlexUnit 4 is backwards compatible and you can migrate each unit test whenever you would like. With the introduction of Fluint and it’s support for Sequences it is possible to unit test user interface interactions without having to write tons of code to accomplish it. You get to write less code and another very important aspect is that you can actually understand what your tests do some time later because of the simpler syntax of testing.

FlexUnit 4 is a huge step from the old versions and it is now on the same level as JUnit and other test frameworks. Especially with the easier configuration of test runners, unit testing and continuous integration will be so much easier in the future. I am also over the moon about the FlexUnit plug-in which is coming to Flash Builder.

Upgrading to FlexUnit4

I have a few projects with unit tests using FlexUnit 0.9 and upgrading to FlexUnit 4 is very simple. All your tests can still be reused and all that is required is that you change the way you setup the test runner.
Here is how little I had to change in one of my projects:

private function onCreationComplete():void {
       testRunner.test = createSuite();
       testRunner.startTest();
}
private function createSuite():TestSuite {
       var testSuite:TestSuite = new TestSuite();
       testSuite.addTestSuite(SomeModelClassTest);
       testSuite.addTestSuite(SomeUIComponentTest);
       return testSuite;
}
....
<flexUnitUIRunner:TestRunnerBase id="testRunner"/>

With FlexUnit 4 this is actually made simpler, just have a look:

private var core:FlexUnitCore;
private function onCreationComplete():void {
       core = new FlexUnitCore();
       core.addListener(new UIListener(testRunner));
       core.run(SomeModelClassTest, SomeUIComponentTest);
}
....
<flexUnitUIRunner:TestRunnerBase id="testRunner"/>

What else is new?

I assume you have read the post FlexUnit 4 feature overview which gives a hint at what you can expect. Besides this one page the documentation is pretty much non-existing, but you can have a look in the source tree in the branch 4.x for samples of how to use the new features.
One would expect that it would be possible to see all the new features documented as unit tests, however it does not seem as if the FlexUnit team believe in dog food as the unit tests are far and few between.

Go download the FlexUnit 4 Beta 1 now!

5 Responses to “Start using the FlexUnit 4 beta today”

  1. Michael Labriola

    The only unit tests currently in the framework are the ones migrated from Fluint of FlexUnit1 to show as examples.

    You are looking at an early beta, and as this is an open source project being developed purely by volunteers, you might need to give us just a bit more time before you get to see the unit tests and decide if we practice what we preach.

    Incidentally, that is one of the reasons we chose to release the initial version as a turnkey and not just point people to the source; we weren’t quite ready yet.

    However, feel free to join the project and help us. We always appreciate an extra set of hands.

  2. leftieFriele

    I didn’t mean to offend you or in any way put down the team working on FlexUnit. You’re doing a great job and the framework is really looking great. Keep up the good work Michael!

  3. Unit testing and Flex, what’s stopping you? « compactcode

    [...] guys over at Adobe are doing some great work on a major new release of Flex Unit. A new version of Flex Builder is looming around the corner with some very promising [...]

  4. StanB

    I’m not able to find how to structure a project the will have my Flex app, test and the test runner in the same Eclipse project. It seems, an Flex project in Eclipse, using Flex Builder can have only one main app. So, it’s either my application or the test runner. How do I solve this problem? It seems an simple issue and people must have solved it if they use flexunit for their production development, but I’m not sure how to do it.

  5. leftieFriele

    StanB: You can have multiple applications in your Flex Projects, but as you mention you can only have one “main application”. Main application only means the default when launching from FB, other than that there’s no difference.
    You can have the testrunner(s) and the main application in the same source tree without problems. All you need to do is to select the testrunner app and choose to run/debug it as opposed to just running the project.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feed (this is global, not just for this entry)

Categories