JaCoCo beats Cobertura when it comes to Java 8 support
I’ve recently reached out for Cobertura to add test coverage reporting to one of my project. One of the first challenges I’ve face was integrating the plugin into a project powered by Gradle. Turns out there is a Gradle version of the plugin available (credit: Steve Saliman).
https://gist.github.com/zezutom/8526e229a4ab01d7a69f
The problem I was unable to work around when using Cobertura was the lack of support for all features of Java 8. For instance, Cobertura won’t recognize Lambda expressions Let me use an example from my previous post.
The Lambda expression at line 6 in the code excerpt below …
public List<Count> count(String text) { return text .toLowerCase() .chars() .distinct() .mapToObj(i -> new Count((char) i, text.toLowerCase() .chars() .filter(j -> j == i) .count())) .sorted() .collect(Collectors.toList()); } ..
… will result into a failure when running Cobertura, see below.
Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " ">" "> "" at line 6, column 46. Was expecting one of: "assert" ... "boolean" ... "byte" ... "char" ... "double" ... "enum" ... "false" ... "float" ... "int" ... "long" ... "new" ... "null" ... "short" ... "super" ... "this" ... "true" ... "void" ... <INTEGER_LITERAL> ... <FLOATING_POINT_LITERAL> ... <CHARACTER_LITERAL> ... <STRING_LITERAL> ... <IDENTIFIER> ... "(" ... "!" ... "~" ... "++" ... "--" ... "+" ... "-" ...
As far as I can tell, there is no fix available just yet, feel free to follow this discussion to see the latest. Meanwhile, I found out that JaCoCo does about the same job as Cobertura and, more importantly, supports Java 8 out of the box. Adding the JaCoCo plugin into a Gradle build is very easy, see the Gist below.
https://gist.github.com/zezutom/453c6db042e6cacf83d9