0

빌드 도구 : 메이븐오프라인 계측을 사용하여 Jacoco 통합 테스트 보고서를 생성하는 방법은 무엇입니까?

이유는 오프라인 계측를 사용 : 안전 장치와 확실한 모두 실행 및 보고서가 생성됩니다 제거 Powermock가 옵션

문제 없습니다. 그러나 jacoco.exec는 생성되지만 jacoco-it.exec는 생성되지 않습니다. IT 외에도 오프라인 기기 사용, 적용 범위 및보고가 원활하게 작동합니다.

<plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>default-instrument</id> 
      <goals> 
       <goal>instrument</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>default-restore-instrumented-classes</id> 
      <goals> 
       <goal>restore-instrumented-classes</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>default-report</id> 
      <goals> 
       <goal>report</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>default-report-integration</id> 
      <goals> 
       <goal>report-integration</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.16</version> 
    <configuration> 
     <systemPropertyVariables> 
      <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>2.15</version> 
    <executions> 
     <execution> 
      <id>integration-tests</id> 
      <goals> 
       <goal>integration-test</goal> 
       <goal>verify</goal> 
      </goals> 
      <configuration> 
       <skipTests>${skip.integration.tests}</skipTests> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

난 깨끗한 설치 받는다는을 사용하여 테스트를 실행하려면 :

은 내가 사용하는 받는다는 플러그인 구성입니다. 나는 다음과 같은 출력을 얻을 테스트 실행의 끝에서

:

[INFO] 
[INFO] --- maven-failsafe-plugin:2.15:integration-test (integration-tests) @ elune --- 
[INFO] Skipping execution of surefire because it has already been run for this configuration 
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:report (default-report) @ elune --- 
[INFO] Loading execution data file C:\Projects\elune\target\jacoco.exec 
[INFO] Analyzed bundle 'elune' with 4 classes 
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:report-integration (default-report-integration) @ elune --- 
[INFO] Skipping JaCoCo execution due to missing execution data file. 

또 다른 가능한 포인터가 단위 테스트를 실행하지만, 통합 테스트 전에 후 클래스의 드 계측이 발생하는 것이 될 수 있습니다. 하지만 이것이 옳은지, 틀린 지 나는 모른다 :

[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:restore-instrumented-classes (default-restore-instrumented-classes) @ elune --- 
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ elune --- 
[INFO] Building jar: C:\Projects\elune\target\elune-0.0.1-SNAPSHOT.jar 
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ elune --- 
[INFO] 
[INFO] --- maven-failsafe-plugin:2.15:integration-test (default) @ elune --- 
[INFO] Failsafe report directory: C:\Projects\elune\target\failsafe-reports 

jacoco-it.exec가 보이지 않는 이유는 무엇입니까?

답변

4

failsafe 플러그인을 사용한 계측 테스트는 구워지지 않았다고 생각합니다. 복원 계측 클래스 목표는 통합 테스트 단계 인 http://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html 전에 실행되는 준비 패키지 단계로 기본 설정되어 있습니다. 그 목표를 통합 후 테스트 단계로 옮기십시오.

<execution> 
    <id>default-restore-instrumented-classes</id> 
    <phase>post-integration-test</phase> 
    <goals> 
    <goal>restore-instrumented-classes</goal> 
    </goals> 
</execution> 

이 충분할 수 있습니다. 그렇지 않으면 통합 테스트를 포함하도록 surefire 플러그인의 includes 패턴을 변경할 수 있습니다 (해당되는 경우).

+1

감사합니다. @wemu! 위상을 바꾸는 것이 트릭을 만들었습니다. –

+0

이것은 아주 좋은 트릭입니다. 그것은 나를 도왔습니다 – Makky

0

구문을 설정 한 후 jacoco-it.exec가 표시되지 않습니다. 명령 줄은 다음과 같습니다 MVN 클린 설치 -Djacoco.version = 0.7.8 -DfailOnError = 거짓 -Dmaven.test.failure.ignore = 사실 나는 마침내 문제는 내가 구성 jacoco을 추가하지 않은 것을 알게되었다

maven-failsafe-plugin의 -agent.destfile. 이 rhinoceros.xn @

<plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.16</version> 
     <configuration> 
      <systemPropertyVariables> 
      <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> 
      </systemPropertyVariables> 
     </configuration> 
     </plugin> 

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>2.15</version> 
     <configuration> 
      <systemPropertyVariables> 
      <jacoco-agent.destfile>target/jacoco-it.exec</jacoco-agent.destfile> 
      </systemPropertyVariables> 
     </configuration> 
    <executions> 
     <execution> 
      <id>integration-tests</id> 
      <goals> 
       <goal>integration-test</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

     <plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>${jacoco.version}</version> 
     <executions> 
      <execution> 
      <id>default-instrument</id> 
      <goals> 
       <goal>instrument</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>default-restore-instrumented-classes</id> 
      <phase>post-integration-test</phase> 
      <goals> 
       <goal>restore-instrumented-classes</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
</plugins> 
0

나를 위해 속임수를 썼는지 플러그인 구성입니다. 하지만 이것을 실행하려면 mvn clean install을 사용하십시오.

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>default-instrument</id> 
        <goals> 
         <goal>instrument</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>default-restore-instrumented-classes</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>restore-instrumented-classes</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>default-report</id> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>default-report-integration</id> 
        <goals> 
         <goal>report-integration</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
+0

당신은 매우 친절합니다. 도와 주셔서 감사합니다. 마침내 문제점이 maven-failsafe-plugin에 jacoco-agent.destfile 구성을 추가하지 않았다는 것을 알게되었습니다. –