Zasięg Jacoco Unit i testy integracyjne - indywidualne i ogólne [zamknięte]

Mam projekt (ProjectA), który zawiera testy jednostkowe i testy integracyjne.

Poniżej znajduje się struktura.

ProjectA - src / java (kod źródłowy java)
- test / java (testy jednostkowe Junita)
- test / zasoby (zasoby wymagane do testów Junit Unit)
- src / java-test (testy integracyjne)
- conf (zawiera pliki .xml wymagane do budowania / testowania / kompilacji)

Uruchamiam następujące polecenia - Wszystkie działają, ale mam wątpliwości co do tego, jak konfiguracje, które mam w plikach gradle build.gradle / GRADLE_HOME / init.d / *. Wpływają na to, co otrzymuję.

Wygląda na to, że coś mi brakuje i nie dostaję tego, czego chcę.

Polecenia:
- stopniowa czysta budowa - działa dobrze
- gradle clean build jacocoTestReport - działa dobrze.
- gradle clean build integrationTest jacocoTestReport - działa poprawnie (jeśli mam instancję tomcat działającą w innym oknie kit dla tego samego ProjectA).

Po zakończeniu trzeciej operacji punktora widzę dodatkowy folder „build” i jego podfoldery (inne niż te, które zostały wyewidencjonowane z kontroli źródła / wersji) w obszarze roboczym zadań Jenkins.

tj. pod - JenkinsWorkspace
/budować
- klasy (zawiera pliki .class dla następujących, które są wymienione jako jedna z sekcji zestawów źródłowych)
---- test integracyjny
---- Główny
---- test

- zasoby (zawiera wszystkie pliki .properties / .xml, które znajdowały się w folderze „conf” w kontroli źródła.

- raporty (zawiera pliki .xml / .html dla wyników PMD / CheckStyle / Findbugs i Tests dla testów jednostkowych lub IT, ale NIE dla obu). ---- checkstyle
---- znaleziska
---- pmd
---- jacoco
---- testy (Uwaga: jest to liczba mnoga, tzn. nie jest to „test”, który jest zdefiniowany jako jeden wpis w zestawach źródłowych)

- jacoco (Zawiera 2 pliki .exec, tj. Test.exec i integrationTest.exec oba mają inny rozmiar pliku)
---- test.exec
---- integrationTest.exec

- jacocoHtml (Ten folder zawiera wiele folderów (zawierających pliki .html) i głównie „index.html” pod nim.
---- somexxxfolders
---- ---- somexxfolder's.html pliki
---- index.html
---- inne pliki / foldery itp

- Wyniki testów (Zawiera niektóre pliki .xml ALE tylko dla testów jednostkowych lub testów integracyjnych - alenie dla obu typów testów w danym czasie).

tzn. jeśli uruchomię „gradle clean build”, zobaczysz pliki .xml związane z testem jednostkowym, a jeśli uruchomię „gradle clean build integrationTest”, wówczas pliki .xml testu jednostkowego zostaną nadpisane, a pliki .xml, które widzę, są powiązane tylko do / generowane przez zadanie integrationTest.


Poniżej znajduje się jeden z typowych stopni (plik GRADLE_HOME / init.d / some.common.gradle)

//
//Extra file can hold global Gradle settings so that these dont have to be inserted in project
//specific build.gradle file.
//Filename: extraN.common<anyname>.gradle
allprojects {
   apply plugin: 'java'
   apply plugin: 'pmd'
   apply plugin: 'findbugs'
   apply plugin: 'checkstyle'
   apply plugin: 'jacoco'
   apply plugin: 'sonar-runner'
   tasks.withType(Compile) {
     options.debug = true
     options.compilerArgs = ["-g"]
   }
   sourceSets {
      main {
         java {
            // MOTE: If your project's build.gradle specify the sourceSet section, the following
            // values will be overwritten by what project's build.gradle will set.
            //
            // If you project's sourceSet structure if different in each project, then in this
            // global common .gradle file, you can define srcDir for main or other sections like
            // test, integrationTest etc as shown below -- commented out. If that's the case, 
            // then uncomment the below line and comment out using // -- srcDir 'src/java' line
            // for sourceSets.main.java section. This rule applies to other sections as well.
            // srcDir 'no_src_dir_set_yet'

            srcDir 'src/java'
         }
         resources {
            srcDir 'conf'
         }
      }
      test {
         java {
            srcDir 'test/java'
         }
         resources {
            srcDir 'test/resources'
            srcDir 'conf'
         }
      }
      integrationTest {
         java {
            srcDir 'src/java-test'
         }
         resources {
            srcDir 'conf'
         }
      }
   }
   def sonarServerUrl = "dev.sandbox.server.com"
   sonarRunner {
      sonarProperties {
         property "sonar.host.url", "http://$sonarServerUrl:9000"
         property "sonar.jdbc.url", "jdbc:h2:tcp://$sonarServerUrl:9092/sonar"
         property "sonar.jdbc.driverClassName", "org.h2.Driver"
         property "sonar.jdbc.username", "sonar"
         property "sonar.jdbc.password", "sonar"
         properties ["sonar.sources"] += sourceSets.main.allSource.srcDirs
         //properties ["sonar.tests"] += sourceSets.test.java.srcDirs
         properties ["sonar.tests"] += sourceSets.integrationTest.allSource.srcDirs
      }
   }
   checkstyle {
        configFile = new File(rootDir, "config/checkstyle.xml")
        ignoreFailures = true
        //sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest]
        sourceSets = [sourceSets.main]
   }
   findbugs {
        ignoreFailures = true
        sourceSets = [sourceSets.main]
   }
   pmd {
        ruleSets = ["basic", "braces", "design"]
        ignoreFailures = true
   }
   jacoco {
      toolVersion = "0.6.2.201302030002"
      reportsDir = file("$buildDir/customJacocoReportDir")
   }
   task testReport(type: TestReport) {
      destinationDir = file("$buildDir/reports/allTests")
   }
   test {
        jacoco {
            //destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
            destinationFile = file("$buildDir/jacoco/test.exec")
            //classDumpFile = file("$buildDir/jacoco/classpathdumps")
            classDumpFile = file("$buildDir/build/classes/test")
        }
   }
   jacocoTestReport {
         group = "Reporting"
         description = "Generate Jacoco coverage reports after running tests."
         reports {
                xml{
                    enabled true
                    destination "${buildDir}/reports/jacoco/jacoco.xml"
                }
                csv.enabled false
                html{
                    enabled true
                    destination "${buildDir}/jacocoHtml"
                }
        }
        additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
        //additionalSourceDirs = files([sourceSets.main.allJava.srcDirs, xxxx, 'xxxxyyyy' ])
   }
}

build.gradle plik wygląda tak:

import com.tr.ids.gradle.CustomFileUtil
apply plugin: 'CustomSetup'
apply plugin: 'java'
apply plugin: 'customJarService'
apply plugin: 'customWarService'
sourceSets {
   main {
      java {
         srcDir 'src/java'
      }
   }
   test {
      java {
         srcDir 'test/java'
      }
      resources {
         srcDir 'test/resources'
         srcDir 'conf'
      }
   }
   integrationTest {
      java {
         srcDir 'src/java-test'
      }
   }
}
// Read dependency lists from external files. Our custom plugin reads a dep-xxx.txt file for compile/test/war related .jar file entries
// where each entry is like: groupid:artifactid:x.x.x
// and these artifact jars are available in Artifactory
List depListCompile = customFileUtil.readIntoList( "$projectDir/dep-compile.txt" )
List depListTest = customFileUtil.readIntoList( "$projectDir/dep-testArtifacts.txt" )
List depListWar = customFileUtil.readIntoList( "$projectDir/dep-war.txt" )
// Define dependencies
dependencies {
   // Compilation
   compile  depListCompile
   // Unit Tests
   testCompile depListTest
   // Integration tests
   // Everything from compile and testCompile targets
   integrationTestCompile configurations.compile
   integrationTestCompile configurations.testCompile
   // Output of compiling "main" files
   integrationTestCompile sourceSets.main.output
   // Additional dependencies from war and others
   integrationTestCompile depListTest, depListWar
   // All configuration files
   integrationTestRuntime files( 'conf' )
}
task deployTomcat( type: Copy, dependsOn: [ jar, compileIntegrationTestJava, warService ] ) {
   from "$buildDir/customWar/${project.name}.war"
   into "$projectDir/tomcat/webapps"
}
build {
  dependsOn deployTomcat
}
task integrationTest( type: Test, dependsOn: cleanTest ) {
   jacoco {
      //destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
      destinationFile = file("$buildDir/jacoco/integrationTest.exec")
      //classDumpFile = file("$buildDir/jacoco/classpathdumps")
      classDumpFile = file("$buildDir/classes/integrationTest")
   }
   testClassesDir = sourceSets.integrationTest.output.classesDir
   classpath = sourceSets.integrationTest.runtimeClasspath
}
apply plugin: 'eclipse'
eclipse.classpath {
   // Define output directory so Eclipse does not accidentally clobber /bin
   defaultOutputDir = file( 'out/classes' )
   // Add integration test
   plusConfigurations += configurations.integrationTestCompile
   // Remove unnecessary files
   file.whenMerged { classpath ->
      classpath.entries.removeAll { entry -> ( entry.path.indexOf( '/build/classes/main' ) > 0 ) }
      classpath.entries.removeAll { entry -> ( entry.path.indexOf( '/build/resources/main' ) > 0 ) }
   }
}

Moje pytania:

1) Dlaczego „gradle clean build integrationTest” - działający z powodzeniem, zastępuje wyniki testów w folderach build / reports / tests i build / test-results.

2) Nie ma znaczenia, jaką nazwę podam dla pliku .exec w ramach wspólnego pliku gradle dla testu, oraz w zadaniu build.gradle for integrationTest dla jacoco, zawsze tworzy plik test.exec i integrationTest.exec, ale wynikowy folder build / jacocoHtml plik index.html nie pokazuje pokrycia / plików związanych z testami jednostek / integracji. Aby to udowodnić, jeśli uruchomię "gradle clean build integrationTest jacocoTestReport sonarRunner", zobaczę obszar roboczy dla zadania, teraz zawiera folder ".sonar" i folder build / reports / sonar, który zawiera inny plik o nazwie "overall-xxx.exec „jakiś plik, ale rozmiar pliku nie jest zbliżony do„ sumy ”rozmiaru pliku unit.test.exec i IT integrationTest.exec. Choć jest większy niż rozmiar pliku test.exec o kilka bajtów.

3) Jaką konfigurację mogę ustawić, aby uzyskać całkowite pokrycie zarówno dla testów jednostkowych, jak i IT, tj. Ogólnie ... plik exec ma dobry rozmiar (po uruchomieniu zadania sonarRunner). Podczas zadania sonarRunner widzę, że „krok jacocoSensor” zadania SonarRunner wyświetla zarówno pliki UT, jak i pliki .exec oraz cały plik .exec automatycznie (dobra funkcja Sonar).

questionAnswers(2)

yourAnswerToTheQuestion