CodeCoverage Plugin

coverage not applied to classes in plugin.groovy

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

This is a problem in plugin version 1.1.8 and 1.1.7. Not sure about others.

Steps To Recreate
1. Create a grails plugin
2. install coverage plugin into pkugin project
3. Create a class (call it ClassUnderTest)
4. Import ClassUnderTest into the XXXPlugin.groovy file. I don't think it matters to the problem whether it is actually used
5. Create a test class to unit test ClassUnderTest, and write a test to test at least one of the methods in ClassUnderTest
6. Do "grails clean" followed by "grails test-app --coverage"

The tests pass, but the code coverage report indicates that ClassUnderTest has not been covered by any tests.

If instead you do the do:
grails clean
grails compile
grails test-app --coverage

Then the cobertura report indicates that ClassUnderTest has been tested.

I.e. it matters whether you have pre-compiled ClassUnderTest before running test-app --coverage

Issue Links

Activity

Hide
Mike Hugo added a comment -

Thanks for the detailed steps to reproduce. I have narrowed this down to the following code in the _GrailsCompile.groovy script that compiles the plugin descriptor.

if (descriptor.lastModified() > classFile.lastModified()) {
        ant.echo(message: "Compiling plugin descriptor...")
        compConfig.setTargetDirectory(classesDir)
        def unit = new CompilationUnit(compConfig, null, new GroovyClassLoader(classLoader))
        unit.addSource(descriptor)
        unit.compile()
    }

Not sure if this is a Grails / Groovy / Cobertura issue but I haven't found a way to automatically resolve this through something in the plugin. In the meantime, the workaround specified in the original description does work:

grails clean
grails compile
grails test-app --coverage

Show
Mike Hugo added a comment - Thanks for the detailed steps to reproduce. I have narrowed this down to the following code in the _GrailsCompile.groovy script that compiles the plugin descriptor.
if (descriptor.lastModified() > classFile.lastModified()) {
        ant.echo(message: "Compiling plugin descriptor...")
        compConfig.setTargetDirectory(classesDir)
        def unit = new CompilationUnit(compConfig, null, new GroovyClassLoader(classLoader))
        unit.addSource(descriptor)
        unit.compile()
    }
Not sure if this is a Grails / Groovy / Cobertura issue but I haven't found a way to automatically resolve this through something in the plugin. In the meantime, the workaround specified in the original description does work: grails clean grails compile grails test-app --coverage

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: