2015-12-09 74 views
1

我們已經在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

回答

0

我有同樣的問題,因爲你在這裏。我能夠將你提到的那個jar(DisableOptimizationsTransformation-0.1-SNAPSHOT.jar)添加到我的lib文件夾中,並且它解決了這個問題。

也許我會仔細檢查一下,以確保你有一個好的jar副本,並且它在你的項目的適當lib文件夾中。在運行覆蓋測試之前,我可能還會嘗試grails clean,以確保全新編譯。

旁註: 這個jar禁用的Grails AST優化,這可能不是你想要禁用生產項目的東西。幸運的是,有一種方法可以在創建戰爭時從構建中移除該jar。

添加到您的BuildConfig.groovy去除罐子創建戰前:

grails.war.resources = { stagingDir -> delete(file:"${stagingDir}/WEB-INF/lib/DisableOptimizationsTransformation-0.1-SNAPSHOT.jar") }

+0

我們已經用在您發佈相同的方式罐子,但不成功。它仍然顯示以上。 此外,我們僅將jar用於測試作業,並跳過了主版本。 – raVan

+0

我能想到的唯一其他選項僅適用於使用JDK 1.7或更高版本的情況。如果您使用的是JDK,那麼您可以使用啓用invokeDynamic的groovy(-indy)的命令行選項。這裏有一個更詳細的鏈接:[link](http://groovy-lang.org/indy.html) –

相關問題