0

I'm running surefire tests with a jacoco agent. When I run mvn verify a jacoco.exec file is produced.

When I run mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false then no jacoco.exec file is produced.

Here is my surefire config.

<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>

Here is my jacoco config

<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>

My question is: Why no jacoco.exec produced when a single test is run - but it is produced when all tests are run?

hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • Perhaps the `-Pci` is to blame? What is this profile and what does it do? – Tunaki Jan 24 '17 at 11:28
  • Thanks - that's helpful - I've clarified the question. – hawkeye Jan 24 '17 at 11:56
  • I can't reproduce the problem (removing `test.jvm.options` from the given configuration as it isn't defined). – Tunaki Jan 24 '17 at 12:15
  • 1
    If you change the ID in the surefire plugin execution from testconfig to default-test does that make any difference? As you have it, I think multiple executions of surefire might run. – user944849 Jan 24 '17 at 15:28

1 Answers1

0

Log of execution of mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false shows something like (I'm using 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

Notice that maven-surefire-plugin executed two times - one time with id default-test and another execution with id testconfig is actually skipped, while only configuration with id testconfig uses ${jacoco.agent.argLine}.

Change of definition for maven-surefire-plugin on

<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>

solves the issue.

Godin
  • 9,801
  • 2
  • 39
  • 76