Cobertura, TestNG and Maven play well together. However, I had problems when I started migrating some tests to the Spock framework. Long story short, Spock uses JUnit internally, not TestNG, and the surefire plugin only triggers tests for one of those frameworks at a time. Therefore, if you mix TestNG with Spock, you’ll run with problems where your Spock tests won’t be started automatically by Maven, and eventually, Cobertura will never generate test coverage for the corresponding classes.
I have found different proposals for fixing this problem, but only one worked for me, so here’s my working pom.xml :
The trick is to add two executions of the surefire plugin, as indicated here, but forcing the plugin version to 2.7.1. Also, adding two dependencies to the surefire plugin, as suggested by Kristian Rosenvold didn’t work for me. My pom.xml file also includes the necessary configuration for GMaven to work with Groovy 1.7 instead of 1.6 by default.