Плагины Jacoco + Surefire Maven всегда показывают 0% покрытие - PullRequest
0 голосов
/ 16 июня 2020

У меня есть многомодульный проект maven, в котором я хочу создать отчет jacoco с охватом модуля. В настоящее время я использую плагины arqullian surefire и jacoco maven, которые определены только в одном модуле. Тесты выполняются на JBoss EAP 7.2

Хотя отчет jacoco создается, я всегда получаю 0% покрытие для всех моих тестовых классов, которые развернуты как архив org.jboss.shrinkwrap.api. spe c .WebArchive на моем сервере JBoss, хотя есть несколько методов, охватываемых модульными тестами.
Важно : другие модульные тесты, выполняемые без развертывания, действительно показывают некоторое покрытие report

enter image description here

Ниже приведена моя конфигурация maven

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.2</version>
      <configuration>
         <skip>${skipTests}</skip>
         <argLine>${surefireArgLine}</argLine>
      </configuration>
   </plugin>
   <plugin>
      <artifactId>maven-surefire-report-plugin</artifactId>
      <version>2.22.2</version>
   </plugin>
   <plugin>
      <groupId>org.jacoco</groupId>
      <artifactId>jacoco-maven-plugin</artifactId>
      <version>0.8.5</version>
      <executions>
         <execution>
            <id>pre-unit-test</id>
            <goals>
               <goal>prepare-agent</goal>
            </goals>
            <configuration>
               <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
               <propertyName>surefireArgLine</propertyName>
            </configuration>
         </execution>
         <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
               <goal>report</goal>
            </goals>
            <configuration>
               <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
            </configuration>
         </execution>
      </executions>
   </plugin>
</plugins>

Ниже используются мои зависимости:

<dependency>
    <groupId>org.dbunit</groupId>
    <artifactId>dbunit</artifactId>
    <version>2.7.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-api-maven</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-spi</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-core</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-container</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.protocol</groupId>
    <artifactId>arquillian-protocol-servlet</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>org.jacoco.core</artifactId>
    <version>0.8.5</version>
    <scope>test</scope>
</dependency>

Arqulian XML

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian         http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
   <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
   <defaultProtocol type="Servlet 3.0" />
   <!-- Example configuration for a remote JBoss EAP 7 instance -->
   <container qualifier="jboss" default="true">
      <!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
      <configuration>
         <!--   <property name="javaVmArguments">${jacoco.agent}</property>  -->
      </configuration>
   </container>
</arquillian>

В одной из моих конфигураций (не выше) я помню, что видел предупреждение о том, что $ {jacoco.agent} не использовался. Так что я снова прокомментировал это.

При выполнении цели чистой установки mvn в моих журналах консоли я вижу следующие переменные, установленные на surefireArgLine

[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) @ alis-ejb ---
[INFO] surefireArgLine set to -javaagent:C:\\Users\\user\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.5\\org.jacoco.agent-0.8.5-runtime.jar=destfile=c:\\Projects\\Projectname\\ejb-module\\target\\coverage-reports\\jacoco-ut.exec

Все мои тесты выполняются нормально, и я возможность генерировать команду отчета surefire с отчетом surefire, в котором перечислены все выполненные модульные тесты. Я думаю, если мне не хватает цели mvn для jacoco, которая рассчитывает покрытие, но похоже, что мне все еще что-то не хватает

Обновление 1 : я начинаю полагать, что проблема возникла из-за к использованию Arquilian, и вместо этого я должен использовать этапы предварительного тестирования. Но еще не уверен.

Обновление 2 : Я только что заметил, что для одного из моих модульных тестов я вижу некоторое покрытие. Разница между этим модульным тестом и остальными заключается в том, что один класс, содержащий тесты, покрытие которых, как показано, являются простыми модульными тестами, тогда как для остальных моих тестовых классов я не получаю отчета о покрытии от Jacoco a org.jboss.shrinkwrap.api.spe c .WebArchive развертывание создано. Еще немного подробностей по этому поводу. 90% моих тестов имеют такую ​​структуру. Веб-архив создается и развертывается на JBoss EAP 7.

...