Test coverage support
If you take testing seriously as I do, you most likely know test code coverage tools. And on Flex Universe the de facto standard and unique alternative is Flex Cover. But let's be honest here, the tool does the job, but isn't simple. Requiring a special compiler made me dislike the idea of running code coverage on Flex projects. And mainly that was why test code coverage never got into Flexmojos. The available tool was too complex to use, making it so complicated to automate that I never gave it any serious thought.
Since day ZERO, Flexmojos has as master goal to KISS (Keep It Simple Stupid Smartguy). With that in mind, Flexmojos is proud to announce a state of art test code coverage support.
Flexmojos test code coverage support is really, really easy to use. Just need to set coverage to true.http://repository.sonatype.org/content/sites/flexmojos-site/4.0-SNAPSHOT/test-compile-mojo.html#coverage
How does it work
Flexmojos is using Apparat. Apparat is a framework to optimize ABC, SWC and SWF files.
Better than that, Apparat allows people to manipulate actionscript bytecode. So this was the way to go. Instrument flex test code w/o a custom compiler. So I start to talk to Joa Ebert, Apparat author. He made changes on apparat side to make possible to instrument the Flexmojos test runner SWF and 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 handle that information and to genarate reports. This allows Flexmojos to generate html, xml and/or summaryXml. http://repository.sonatype.org/content/sites/flexmojos-site/4.0-SNAPSHOT/test-run-mojo.html#coverageReportFormat
This is only available on Flexmojos 4. So if you never thought about Maven 3... that may be the time.
Note: Only reports line coverage, not branch coverage.
Sample project
To show how simple it is to enable test code coverage on Flexmojos 4.x, we will edit Flexunit sample project to enable code coverage. The project can be found here. Once you get the sources, edit pom.xml. There are just 2 simple changes:
- change the %
flexmojos.version
property to4.0-SNAPSHOT
; - add
<coverage>true</coverage>
to flexmojos configuration section;
The pom with all required changes is available here.
Running $mvn clean install
will produce the following report:
The original report can be found here
Configuration Options
test-compile goal options: https://repository.sonatype.org/content/sites/flexmojos-site/4.0-SNAPSHOT/test-run-mojo.html
test-run goal options http://repository.sonatype.org/content/sites/flexmojos-site/4.0-SNAPSHOT/test-compile-mojo.html