0

I have one separate project for main source code and one for test cases. Now while running test project in jenkins job , i want to capture code coverage report for main source code.

I found similar question asked here is:- Java code coverage for other source code repository

Please suggest some answer or else what should be the project structure to generate code coverage report for unit test cases.

Shivani
  • 51
  • 1
  • 9

1 Answers1

0

The JaCoCo plugin adds a JacocoReport task to your project. You can configure the additionalClassDirs and additionalSourceDirs properties on that task.

Eg:

apply plugin: 'jacoco' 
tasks.withType(JacocoReport) {
   additionalClassDirs = ... 
   additionalSourceDirs = ... 
} 
lance-java
  • 25,497
  • 4
  • 59
  • 101
  • How i can do it in jenkins?? – Shivani Nov 21 '19 at 03:38
  • Same as when building locally, you'll need to make the above changes to your `build.gradle` – lance-java Nov 21 '19 at 17:43
  • tasks.withType(JacocoReport) { print("Hiiiiiiiiiiiiiiiiiiii") def mainSrc = "C:/re-engg/demo-testng/demo-settings-test/src/test/java" def mainMainSrc = "C:/re-engg/demo/demo-settings/src/main/java" sourceDirectories = files([mainSrc]) additionalSourceDirs = files([mainMainSrc]) executionData = files "${projectDir}/demo-settings-test/build/jacoco/testDebugUnitTest.exec" reports { xml.enabled = true html.destination = file("${projectDir}/demo-settings-test/build/jacoco/html") } } – Shivani Nov 25 '19 at 10:08
  • I tried to implement it the way u suggested bu still m not ale to get it.Please help me. – Shivani Nov 25 '19 at 10:09