我们已经在Grails 2.4.4上使用代码覆盖插件的v2.0.3-3运行覆盖。Cobertura覆盖grails
考虑像下面一个简单的控制器代码:
class TestController {
def index() {}
}
和简单的斯波克测试下同:
@TestFor(TestController)
class TestControllerSpec extends Specification {
def "test index"() {
when:
controller.index()
then:
response != null
}
}
如何产生的覆盖报告如下:
<class name="package.TestController" filename="package/TestController.groovy" line-rate="1.0" branch-rate="0.1" complexity="0.0">
<methods>
<method name="index" signature="()Ljava/lang/Object;" line-rate="1.0" branch-rate="0.1">
<lines>
<line number="8" hits="1" branch="true" condition-coverage="10% (1/10)">
<conditions>
<condition number="0" type="jump" coverage="50%"/>
<condition number="1" type="jump" coverage="0%"/>
<condition number="2" type="jump" coverage="0%"/>
<condition number="3" type="jump" coverage="0%"/>
<condition number="4" type="jump" coverage="0%"/>
</conditions>
</line>
</lines>
</method>
</methods>
<lines>
<line number="8" hits="1" branch="true" condition-coverage="10% (1/10)">
<conditions>
<condition number="0" type="jump" coverage="50%"/>
<condition number="1" type="jump" coverage="0%"/>
<condition number="2" type="jump" coverage="0%"/>
<condition number="3" type="jump" coverage="0%"/>
<condition number="4" type="jump" coverage="0%"/>
</conditions>
</line>
</lines>
</class>
为什么报告为1/10条件只包括在内?
注:我已经使用了DisableOptimizationsTransformation-0.1-SNAPSHOT.jar在这里提到: Grails/Cobertura report - conditional coverage doesn't make sense
我们已经用在您发布相同的方式罐子,但不成功。它仍然显示以上。 此外,我们仅将jar用于测试作业,并跳过了主版本。 – raVan
我能想到的唯一其他选项仅适用于使用JDK 1.7或更高版本的情况。如果您使用的是JDK,那么您可以使用启用invokeDynamic的groovy(-indy)的命令行选项。这里有一个更详细的链接:[link](http://groovy-lang.org/indy.html) –