1

We have been running coverage using the v2.0.3-3 of code-coverage plugin on Grails 2.4.4.

Consider a simple controller code like below:

class TestController {

    def index() {}

}

And a simple spock test for the same as below:

@TestFor(TestController)
class TestControllerSpec extends Specification {

    def "test index"() {
        when:
        controller.index()

        then:
        response != null
    }
}

The coverage report getting generated is as below:

<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>

Why is it reported as 1/10 conditions are only covered?

NOTE: I have used the DisableOptimizationsTransformation-0.1-SNAPSHOT.jar as mentioned in here: Grails / Cobertura report - conditional coverage doesn't make sense

Community
  • 1
  • 1
raVan
  • 296
  • 2
  • 15

1 Answers1

0

I had the same issue as you have here. I was able to add that jar you mentioned (DisableOptimizationsTransformation-0.1-SNAPSHOT.jar) to my lib folder and it solved the problem.

Perhaps I would double check to make sure you got a good copy of the jar and that it is in the appropriate lib folder for your project. I might also try a grails clean before running the tests with coverage to ensure a fresh compile.

Side note: This jar disables the grails AST optimization and that may not be something you want to disable for your project in production. Luckily there is a way you can remove this jar from the build when the war is created.

Add this to your BuildConfig.groovy to remove the jar before the war is created:

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

Caleb Thornton
  • 524
  • 4
  • 8
  • We have used the jar in the same way you posted, but in vain. It still shows the above. Also, we have used the jar only for test jobs and have skipped for the main build. – raVan Jul 28 '16 at 07:28
  • The only other option I can think of only applies if you are using JDK 1.7 or higher. If you are using that JDK then you can use a command line option for groovy (-indy) that enables invokeDynamic. Here is a link with more details about it: [link](http://groovy-lang.org/indy.html) – Caleb Thornton Jul 28 '16 at 12:45