Проверка JaCoCo без сбоев Сборка мультимодульного проекта AEM ниже порогового покрытия - PullRequest
2 голосов
/ 25 марта 2019
  • Я пытаюсь настроить проверку jaCoCo в моем многомодульном проекте AEM 6.4.
  • Я написал тестовые классы для расширений JUnit5, которые хорошо компилируются.
  • Я вижу отчетпубликуется также на моем Sonar Server, покрытие составляет 45,9% - Не удалось.
  • Когда я развертываю проект Maven через maven Run Configurations: mvn clean verify, он всегда показывает все модули, развернутые с SUCCESS.

Объявление переменных корневых POM:

<properties>

    <!-- Sonar --> 
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
<sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths>
    <sonar.language>java</sonar.language>

    <!-- JaCoCo -->        
    <jacoco.percentage.instruction>0.98</jacoco.percentage.instruction>

</properties>

Настройка корневых модулей POM Maven Surefire, Fail-safe и JaCoCo

<build>
    <plugins>
        <!-- Maven Surefire Plugin -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <argLine>${jacocoArgLine} -Xmx256m</argLine>
        </configuration>
    </plugin>               

    <!-- Maven Failsafe Plugin -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.22.0</version>
    </plugin>

    <!--  JaCoCo Plugin for Code Coverage -->
    <plugin>

        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.3</version>

        <configuration>
            <destFile>${sonar.jacoco.reportPaths}</destFile
            <dataFile>${sonar.jacoco.reportPaths}</dataFile>
            <append>true</append>
        </configuration>

        <executions>
            <execution>
                <id>prepare-agent</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
                <configuration>
                    <propertyName>jacocoArgLine</propertyName>
                </configuration>
            </execution>

            <execution>
                <id>check</id>
                <phase>verify</phase>
                <goals>
                    <goal>check</goal>
                </goals>
                <configuration>
                    <dataFile>${sonar.jacoco.reportPaths}</dataFile>
                    <rules>
                        <rule implementation="org.jacoco.maven.RuleConfiguration">
                          <element>PACKAGE</element>
                <limits>
                   <limit implementation="org.jacoco.report.check.Limit">
                                   <counter>INSTRUCTION</counter>
                       <value>COVEREDRATIO</value>
                                   <minimum>0.80</minimum>
                </limit>
                </limits>
              </rule>
               </rules>
             </configuration>
          </execution>
       </executions>
    </plugin>
    </plugins>
</build>

Обратите внимание, что я не настроил плагин на ядреили файлы POM модуля it.tests.

Вывод из журналов - Базовая комплектация:

[INFO] Building Test - Core 0.0.1-SNAPSHOT                [2/5]
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ test.core ---
[INFO] Deleting C:\Apps\Workspace\git\test-bitbucket\core\target
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ test.core ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.3:prepare-agent (prepare-agent) @ test.core ---
[INFO] jacocoArgLine set to -javaagent:C:\\Users\\Public\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.3\\org.jacoco.agent-0.8.3-runtime.jar=destfile=C:\\Apps\\Workspace\\git\\test-bitbucket\\core\\..\\target\\jacoco.exec,append=true
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ test.core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Apps\Workspace\git\test-bitbucket\core\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ test.core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 20 source files to C:\Apps\Workspace\git\test-bitbucket\core\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ test.core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Apps\Workspace\git\test-bitbucket\core\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ test.core ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ test.core ---
[INFO] No tests to run.
[INFO] 
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.3:check (check) @ marketing-garage.core ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\Apps\Workspace\git\test-bitbucket\core\..\target\jacoco.exec

Вывод из журналов - Комплект тестов:

[INFO] Building Test - Integration 0.0.1-SNAPSHOT      [5/5]
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ test.it.tests ---
[INFO] Deleting C:\Apps\Workspace\git\test-bitbucket\it.tests\target
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ test.it.tests ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.3:prepare-agent (prepare-agent) @ test.it.tests ---
[INFO] jacocoArgLine set to -javaagent:C:\\Users\\Public\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.3\\org.jacoco.agent-0.8.3-runtime.jar=destfile=C:\\Apps\\Workspace\\git\\test-bitbucket\\it.tests\\..\\target\\jacoco.exec,append=true
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ test.it.tests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Apps\Workspace\git\test-bitbucket\it.tests\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ test.it.tests ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ test.it.tests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ test.it.tests ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to C:\Apps\Workspace\git\test-bitbucket\it.tests\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ test.it.tests ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.test.it.tests.LogoutServletTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.603 s - in com.test.it.tests.LogoutServletTest
[INFO] Running com.test.it.tests.SocialFeedsServiceTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.731 s - in com.test.it.tests.SocialFeedsServiceTest
[INFO] 
[INFO] Results:
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] --- maven-bundle-plugin:4.1.0:bundle (default-bundle) @ test.it.tests -
[WARNING] Bundle com.test:test.it.tests:bundle:0.0.1-SNAPSHOT : The JAR is empty: The instructions for the JAR named com.test.it.tests did not cause any content to be included, this is likely wrong
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.3:check (check) @ test.it.tests ---
[INFO] Loading execution data file C:\Apps\Workspace\git\test-bitbucket\it.tests\..\target\jacoco.exec
[INFO] Analyzed bundle 'test.it.tests' with 0 classes
[INFO] All coverage checks have been met.
[INFO] -----------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] test 0.0.1-SNAPSHOT ................ SUCCESS [  2.091 s]
[INFO] Test - Core ........................ SUCCESS [ 15.467 s]
[INFO] Test - UI apps ..................... SUCCESS [ 55.583 s]
[INFO] Test - UI content .................. SUCCESS [ 47.815 s]
[INFO] Test - Integration 0.0.1-SNAPSHOT SUCCESS [ 36.362 s]
[INFO] -----------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------------
[INFO] Total time: 02:41 min
[INFO] Finished at: 2019-03-25T11:08:31+05:30
[INFO] -----------------------------------------------------------------------

Я ожидал сборкипотерпеть неудачу, если охват ниже 80%, но эта конфигурация передает все сборки с точки зрения Maven Build.

...