0

我正在使用jacoco代理運行surefire測試。當我運行mvn verify時,生成jacoco.exec文件。爲什麼運行單個測試時沒有生成jacoco.exe - 但是它在所有測試運行時都會生成?

當我運行mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false時,沒有生成jacoco.exec文件。

這是我的surefire配置。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
    </configuration> 
    <executions> 
     <execution> 
      <phase>test</phase> 
      <id>testconfig</id> 
      <configuration> 
       <argLine>${test.jvm.options} ${jacoco.agent.argLine}</argLine> 
       <skip>false</skip> 
      </configuration> 
      <goals><goal>test</goal></goals> 
     </execution> 
    </executions> 
</plugin> 

這裏是我的jacoco配置

<plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <version>0.7.5.201505241946</version> 
    <configuration> 
     <properties> 
      <property> 
       <name>listener</name> 
       <value>org.sonar.java.jacoco.JUnitListener</value> 
      </property> 
     </properties> 
    </configuration> 
    <executions> 
     <execution> 
      <id>unit_agent</id> 
      <phase>initialize</phase> 
      <goals> 
       <goal>prepare-agent</goal> 
      </goals> 
      <configuration> 
       <propertyName>jacoco.agent.argLine</propertyName> 
      </configuration> 
     </execution>       
    </executions> 
</plugin> 

我的問題是:爲什麼沒有當運行一個測試生產jacoco.exe - 但是當所有的測試運行中產生?

+0

也許'-Pci'應該是責怪?這是什麼配置文件,它有什麼作用? – Tunaki

+0

謝謝 - 這很有幫助 - 我澄清了這個問題。 – hawkeye

+0

我無法重現該問題(從給定配置中刪除'test.jvm.options',因爲它沒有定義)。 – Tunaki

回答

0

登錄的mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false執行的顯示類似的信息(我使用的Apache Maven的3.3.9):

[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ example --- 
[INFO] Surefire report directory: /private/tmp/jacoco-example/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.org.MyTest 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in com.org.MyTest 

Results : 

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 

[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (testconfig) @ example --- 
[INFO] Skipping execution of surefire because it has already been run for this configuration 

注意maven-surefire-plugin執行兩次 - 一次與ID default-test與ID testconfig另一個執行實際上被跳過了,而只有編號爲testconfig的配置使用${jacoco.agent.argLine}。定義爲maven-surefire-plugin

變化

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
     <argLine>${jacoco.agent.argLine}</argLine> 
    </configuration> 
</plugin> 

解決了這個問題。

+0

這是否產生一個jacoco.exec? – hawkeye

+0

@hawkeye是的它確實 – Godin

+0

非常棒 - 謝謝你 – hawkeye

相關問題