这最近的一篇博客由托马斯·桑德博格包含利用蚂蚁的呼叫的Cobertura,而不是使用maven的插件的Cobertura部分解决这一问题的方法。
它依赖于以下具有专用pom.xml和build.xml文件的基本方法:
首先在父pom上进行典型的maven编译,该编译将编译子模块中的所有类。
mvn clean compile # maven-compile-plugin called for compiling
然后检测所有模块类:
ant instrument # cobertura called for instrumentation
然后调用测试的maven-surefire-plugin,以使用检测到的类进行测试,并将cobertura作为测试依赖项
mvn test
然后使用自定义报告调用从不同的模块中提取所有结果:
ant report # cobertura called for reporting
ant build.xml文件的关键元素是分别检测所有模块,然后在合并结果后报告所有模块。在他的示例中,需要为每个模块调用此函数:
<target name="instrumentAModule"> <property name="classes.dir" value="target/classes"/> <cobertura-instrument todir="./${module}/${classes.dir}"> <fileset dir="./${module}/target/classes"> <include name="**cobertura.ser"/> </fileset> </cobertura-merge></target>可以使用antrun插件将ant组件集成到maven中,但是我对阶段/生命周期不够熟悉,无法知道在哪里放置不同的调用。
这对我非常有用,因为我在api模块中编写了抽象测试类,然后在lib模块中为它们提供了实现。到目前为止,cobertura和emma都无法处理这种设计,因此我的代码覆盖率通常为0或个位数。



