saladinkzn / gretty

Advanced gradle plugin for running web-apps on jetty and tomcat.
MIT License
2 stars 2 forks source link

Code coverage for server side libraries in integration tests #5

Closed x12a1f closed 8 years ago

x12a1f commented 8 years ago

Hi,

Thanks for continue supporting this.

I have a question about integration tests and coverage and I was hoping you can provide some clues on how to do this.

I have a server project setup using gretty and jacoco which work fine. This server is using a library (in the same gradle project) which I would like to have tested through the integration test but I'm having difficulties to configure this.

How can I include coverage for a library in the server side code coverage report?

I used the settings as provided in the gretty documentation to setup the integration tests:

dependencies {
    compile project(":serverlib")   // <-- these classes are also tested by the integrationTest
                                    //     and should also appear in the coverage report
                                    //     but I don't know how to do this
}

task('integrationTest', type: Test) {
    include '**/*IT.*'
}

tasks.test {
        exclude '**/*IT.*'
}

gretty {
  afterEvaluate {
      tasks.appBeforeIntegrationTest.jacoco {
          append = false
          destinationFile = project.file("$project.buildDir/jacoco/integrationTestServer.exec")
      }
      tasks.appAfterIntegrationTest.finalizedBy tasks.integrationTestServerReport
}

task('integrationTestServerReport', type: JacocoReport) {
        executionData { tasks.appBeforeIntegrationTest.jacoco.destinationFile }

        sourceDirectories = files(sourceSets.main.allSource.srcDirs)
        classDirectories = sourceSets.main.output

        def reportDir = reporting.file("jacoco/integrationTest_server/html")
        reports {
            html.destination = reportDir
        }
    }

I hope you can provide some hints on how to do this. Thanks!

saladinkzn commented 8 years ago

Hello

I think the issue is with your JacocoReport task setup. By providing


    sourceDirectories = files(sourceSets.main.allSource.srcDirs)
    classDirectories = sourceSets.main.output

You're limiting your report to your web project's classes. Try specifying


additionalSourceDirs=project(':serverLib').sourceSets.main.allSource.srcDirs
x12a1f commented 8 years ago

Ah, thanks!

Adding both

additionalSourceDirs = files(project(':libs-server').sourceSets.main.allJava.srcDirs)
additionalClassDirs = project(':libs-server').sourceSets.main.output   

seems to do the trick.

Many thanks for the hint!