2

I am trying to configure code coverage reporting for our Grails application when running Spock-based unit tests. I am able to generate the reports, but the coverage is 0.

I have tried playing with various options (e.g. Sampling vs. Tracing), but the results are always the same: the total number of classes/methods/lines shown is correct, but the coverage is always 0, e.g.:

Class,%: 0%(0/2)

Method,%: 0%(0/4)

Line,%: 0%(0/16)

Which is clearly bogus, since the relevant code can be modified in such a way that the tests fail.

The setup:

  • OS X Yosemite 10.10.2
  • IntelliJ IDEA Ultimate 14.1.3
  • Grails 2.4.4
  • Spock 0.7
  • Groovy 2.4.3
  • Java 1.8.0-31
malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87

3 Answers3

2

I wrote to JetBrains support and they pointed me to the following issue:

https://youtrack.jetbrains.com/issue/IDEA-137285

In short, the resolution is to specify

grails.project.fork = [
  test: false
]

in BuildConfig.groovy .

Also, see IntelliJ IDEA Debugger isn't working on a Grails Project - there is some useful info there on when/how/why use fork mode.

Community
  • 1
  • 1
malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87
  • This will slow down your test case execution tremendously in some scenarios. I am currently facing the slowness issue after this. – Vinay Prajapati Dec 17 '15 at 10:09
1

I also faced similar problem couple of months back. I was using STS and written Spock based test cases.

The plugin for the code coverage which you are using is not considering Spock based test cases as the actual test cases. It considers only JUinit test cases.

So the solution here would be look for other code coverage plugin compatible with IntelliJ. I couldn't suggest you the plugin which I used for STS since It may or may not work well for IntelliJ.

I hope at-least I made it clear what's the problem.

1

I ran into this error today. I eventually found that you should not use "run application with coverage" from the toolbar, but "Run 'Test in 'application'' with Coverage" from the project context menu.

When you run a test in IntelliJ, a JUnit test is created in the 'Run/Debug Configurations' these can be used from the toolbar (e.g. for re-running).