Integration tests in the jacoco-it directory

I have integration tests and they performed fine, but Jacoco treats them as unit tests. How to tell Jacoco to see them as integration tests and display their graph coverage, not in the jacoco-ut directory, but this is the jacoco-it directory?

Here in the Maven configuration:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <argLine>${surefireArgLine}</argLine> <excludes> <exclude>**/it/java/*.java</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.10</version> <executions> <execution> <id>add-test-source</id> <phase>process-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/it/java</source> </sources> </configuration> </execution> <execution> <id>add-test-resource</id> <phase>generate-test-resources</phase> <goals> <goal>add-test-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/it/resources</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>add-it-resources</id> <phase>pre-integration-test</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/it-classes</outputDirectory> <resources> <resource> <directory>src/it/resources</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>${failsafeArgLine}</argLine> <testSourceDirectory>src/it/java</testSourceDirectory> <testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory> </configuration> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.6.201602180812</version> <configuration> <skip>${maven.test.skip}</skip> <output>file</output> <append>true</append> <excludes> <exclude>**/config/*</exclude> <exclude>**/dialect/*</exclude> </excludes> </configuration> <executions> <execution> <id>pre-unit-test</id> <phase>process-test-classes</phase> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> <propertyName>surefireArgLine</propertyName> <includes><include>**/ut/*</include></includes> </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> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <goals> <goal>prepare-agent-integration</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile> <propertyName>failsafeArgLine</propertyName> <includes><include>**/it/*</include></includes> </configuration> </execution> <execution> <id>post-integration-test</id> <phase>post-integration-test</phase> <goals> <goal>report-integration</goal> </goals> <configuration> <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> </configuration> </execution> </executions> </plugin> 

UPDATE: I was absent from this plugin in the maven-failover plugin plugin:

 <executions> <execution> <goals> <goal>integration-test</goal> </goals> </execution> </executions> 

After adding it as:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>${failsafeArgLine}</argLine> <includes> <include>**/it/**</include> </includes> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> </goals> </execution> </executions> </plugin> 

integration test report shows integration tests.

Final full configuration:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <argLine>${surefireArgLine}</argLine> <includes> <include>**/ut/**</include> </includes> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.10</version> <executions> <execution> <id>add-test-source</id> <phase>process-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/it/java</source> </sources> </configuration> </execution> <execution> <id>add-test-resource</id> <phase>generate-test-resources</phase> <goals> <goal>add-test-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/it/resources</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>${failsafeArgLine}</argLine> <includes> <include>**/it/**</include> </includes> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.6.201602180812</version> <configuration> <skip>${maven.test.skip}</skip> <output>file</output> <append>true</append> <excludes> <exclude>**/config/*</exclude> <exclude>**/dialect/*</exclude> </excludes> </configuration> <executions> <execution> <id>pre-unit-test</id> <phase>process-test-classes</phase> <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> <execution> <id>pre-integration-test</id> <phase>pre-integration-test</phase> <goals> <goal>prepare-agent-integration</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile> <propertyName>failsafeArgLine</propertyName> </configuration> </execution> <execution> <id>post-integration-test</id> <phase>post-integration-test</phase> <goals> <goal>report-integration</goal> </goals> <configuration> <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> </configuration> </execution> </executions> </plugin> 
0
maven integration-testing jacoco jacoco-maven-plugin
May 27 '16 at 13:46
source share
1 answer

You misunderstood the template for the include maven-failafe-plugin tag. The template is used to name the class package in the test path (see also https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html ).

The build-helper-maven plugin includes all classes in src/it/java in the test class path. Then, the include tag template in both test plugins (surefire, failafe) filters the classes inside this test path. These filtered classes are executed by test plugins.

So the workflow

  • Build-Helper-Plugin extends the set of test classes that need to be compiled and executed. Therefore, the source directive is used. The path location specified in this source directive is associated with a Maven project project.
  • The compiler plugin compiles java classes.
  • Jacoco-Plugin must measure coverage in production classes using unit tests. Therefore, a normal agent must be prepared before the tests are completed. You can specify which production code should be included or excluded in the measurement of coverage (include / exclude directive). The template in these directives is based on packages (tricks are used instead of labels).
  • Surefire-Plugin runs tests whose full name matches the template of the include directive. The pattern uses slashes instead of dots.
  • Jacoco-Plugin should now measure coverage in production classes with integration tests. Therefore, the integration agent must be prepared before the tests are completed. And again, you can specify which production code should be included or excluded in the coverage dimension (include / exclude directive). The template in these directives is based on packages (tricks are used instead of labels).
  • The same goes for the Failsafe-Plugin. It runs tests whose full name matches the template of the include directive. The pattern uses slashes instead of dots.
+1
May 28 '16 at 19:48
source share



All Articles