For integration tests I use the spring-boot-maven-plugin where I run 'start' in the phase 'pre-integration-test' to start the spring boot application and then 'stop' in the pase 'post-integration-test' to shut it down again.
There
is no issue with the unit tests, however when running integration
tests, the coverage from tests sending requests to the running
webservice application is not recorded. I don't see any error message.
My pom.xml contains these relevant sections:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>com/mycompany/generated/**/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize-ut</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-initialize-it</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<arguments>
<argument>--integration-test</argument>
</arguments>
<maxAttempts>3</maxAttempts>
<wait>10000</wait>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<groups>${integrationTestGroups}</groups>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
As seen here I am sticking pretty much to the defaults.
Any idea what I am doing wrong?
Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test.
By default it will set "argLine" property, but spring-boot-maven-plugin doesn't take into account this property by default and you're not passing it explicitly , hence spring-boot-maven-plugin starts JVM without JaCoCo agent.
Also setting of JVM arguments for spring-boot-maven-plugin should be as easy as described in their documentation - https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-debug.html
i.e. No plugin name explicitly set.
Is there any way to get this together?
Excuse me for repetition, but: if you can provide minimalistic example demonstrating your issue, then I can have a look at it. Otherwise, not being a daily user of spring-boot, cost to build something similar to your setup is pretty high (web services, spring-boot, testng, etc) and without guarantees to see the exact same behavior as you experience.Presence of example/reproducer always speeds-up things - as examples: https://github.com/jacoco/jacoco/pull/462 and https://github.com/jacoco/jacoco/issues/394