Jacoco coverage is misleading testing grails 3 controllers

606 views Asked by At

I have a grails 3.1.x project with lots of controllers and I use spock for testing the controllers.

I use a command pattern for my controllers so each action takes a command object.

An example for such a controller :

class PlaygroundController {

    public Object pg(PgCO pgco) {
        String s = null
        if (pgco.one) {
            s = pgco.one
        }

        if (pgco.two) {
            s = pgco.two
        }

        render view: 'pg', model: [resultat: s]
    }
}

I have a simple spock test case:

void "pg"() {
        given:
        PgCO pgCO = new PgCO()
        pgCO.one = 'TEST'

        when:
        controller.pg(pgCO)

        then:
        view == '/playground/pg'
        model
        model.resultat == 'TEST'
    }

This test runs fine, but when i run a jacocoTestReport it shows that my coverage is way below 50% , it's fine that it's not fully covered since I'm only covering one branch.

But the report contains loads of "missed instructions" on methods that I have no source code for.. specially there is a shadow pg() method that doesn't take any parameters. Grails injects this method, but I will never call that method from my tests since I use the command object version of the same method. this method but also a lot of other methods coming from grails controller framework.

Isn't there anyw ay to tell jacoco that it's only the "source code" that needs to be checked for coverage ?

I've tried specifying exact source dirs, but this doesn't help

Here's an image of the coverage report: coverage report

I have a daily simple project just enabling the jacoco plugin, and running latest jacoco :

jacoco {
    toolVersion = "0.7.5.201505241946"
}

Have anyone else a solution to this ?

0

There are 0 answers