2015-03-17 3 views
8

Ho provato a ottenere la copertura del codice in un progetto spring-gradle usando il plugin gradle jacoco.gradle jacocoTestReport non funziona?

Il build.gradle contiene il seguente

apply plugin: "jacoco" 

    jacoco { 
     toolVersion = "0.7.1.201405082137" 
     reportsDir = file("$buildDir/customJacocoReportDir") 
    } 

    jacocoTestReport { 
    reports { 
     xml.enabled false 
     csv.enabled false 
     html.destination "${buildDir}/jacocoHtml" 
    } 
} 

Allora ho fatto funzionare

gradle test jacocoTestReport 

Se dopo solo il file test.exec viene generato nella cartella build/report.

Oltre a ciò non succede nulla.

Come posso ottenere il rapporto HTML?

risposta

5

Seguito aiutato. la sua in campioni/test/jacaco di gradle-2.3-all.zip

apply plugin: "java" 

apply plugin: "jacoco" 

jacoco { 
    toolVersion = "0.7.1.201405082137" 
    reportsDir = file("$buildDir/customJacocoReportDir") 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 
    testCompile "junit:junit:4.+" 
} 

test { 
    jacoco { 
     append = false 
     destinationFile = file("$buildDir/jacoco/jacocoTest.exec") 
     classDumpFile = file("$buildDir/jacoco/classpathdumps") 
    } 
} 


jacocoTestReport { 
    reports { 
     xml.enabled false 
     csv.enabled false 
     html.destination "${buildDir}/jacocoHtml" 
    } 
} 
+0

controlla anche questo: http://csiebler.github.io/blog/2014/02/09/multi-project-code-coverage-using-gradle-and-jacoco/ –

1

Non hai configurare reportsDir/destinationFile

Perché jacoco ha valori di default per loro.

build.gradle:

plugins { 
    id 'java' 
    id 'jacoco' 
} 

jacocoTestReport { 
    reports { 
     xml.enabled true 
     html.enabled true 
     csv.enabled true 
    } 
} 

repositories { 
    jcenter() 
} 

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.12' 
} 

Run gradle test jacocoTestReport

È possibile trovare il rapporto di prova in ./build/reports/jacoco/test directory.

L'output HTML è nella directory ./build/reports/jacoco/test/html.