Skip Navigation
Resources Blog Flex Test Coverage Kept Simple with Flexmojos

Flex Test Coverage Kept Simple with Flexmojos

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.

Picture of Marvin Froeder

Written by Marvin Froeder

Over the past 11 years, Marvin has worked for several startups, most notably at The Last Pickle, ContaAzul, and Sonatype, where he was a Java Developer.