Flex Test Coverage Kept Simple with Flexmojos


April 28, 2010 By Marvin Froeder

If you take testing seriously as I do, you most likely know test code coverage tools.  And in the Flex Universe the de facto standard is Flex Cover.  Now let’s be honest here, the tool does the job but it isn’t simple.  Using it requires a special compiler to run code on Flex projects, which is the main reason why test code coverage never got into Flexmojos.  The available tool was too complex to use, and so I never gave it any serious thought.

Since day one, Flexmojos has tried to follow the KISS philosophy (Keep It Simple Stupid Smartguy).  With that in mind, Flexmojos is proud to announce state of the art test code coverage support.

How does it work

Flexmojos test code coverage support is extremely easy to use.  You just need to set coverage to true.

Flexmojos uses Apparat - a framework that optimizes ABC, SWC and SWF files.  Apparat allows people to manipulate actionscript bytecode; and instrument flex test code without a custom compiler.  Taking the lead of Apparat author Joa Ebert, who made it possible to instrument the Flexmojos test runner SWF, I made the changes to Flexmojos to collect the code usage flag by Apparat.

Once the code usage information is collected, Flexmojos uses Cobertura to process information and generate reports. This allows Flexmojos to generate html, xml and/or summaryXml. For more on this, click here.

I shoud point out that this feature is only available on Flexmojos 4. So if you never thought about Maven 3, that may be the time.

Sample project

To show how simple it is to enable test code coverage on Flexmojos 4.x, we will edit a Flexunit sample project to enable code coverage. The project can be found here. Once you get the sources, edit pom.xml. There are just two simple changes to make:

  1. change the %{flexmojos.version} property to 4.0-SNAPSHOT;
  2. add <coverage>true</coverage> to flexmojos configuration section;

Next, running $mvn clean install will produce the following report:

The original report can be found here.

And so, with just a few simple changes you can enable test code coverage on Flexmojos.

  • http://twitter.com/oooJamesooo James Setaro

    Wow, this is just what I was looking for today so pretty good timing.

    Haven’t looked at Maven 3.0-beta-1, but maybe now is the time. Looks like a GREAT feature to have built in.

    • http://twitter.com/velobr Marvin Froeder

      We have being using maven 3 SNAPSHOT for a few months now and it is quite stable.

      Some bugs the currectly bother people on flexmojos 3.x just got fixed if you switch to maven 3, so I do recomend it =D