Skip to content

Commit

Permalink
add integration tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcoder committed Mar 10, 2024
1 parent ff27fcc commit 504e0c8
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 27 deletions.
127 changes: 100 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@
<maven-project.version>2.2.1</maven-project.version>
<maven-plugin-plugin.version>3.6.4</maven-plugin-plugin.version>
<maven-site-plugin.version>3.12.0</maven-site-plugin.version>
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- <maven.version>3.8.4</maven.version> -->
<itf.version>0.11.0</itf.version>
<junit.version>5.8.2</junit.version>
<itf.version>0.13.1</itf.version>
<junit.version>5.10.2</junit.version>
<jacoco.version>0.8.11</jacoco.version>
<unit.coverage.file>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</unit.coverage.file>
<it.coverage.file>${project.build.directory}/jacoco-output/jacoco-it-tests.exec</it.coverage.file>
<merged.coverage.file>${project.build.directory}/jacoco-output/merged.exec</merged.coverage.file>
<jacoco.maven.opts>-javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${it.coverage.file},append=true</jacoco.maven.opts>
</properties>

<dependencies>
Expand Down Expand Up @@ -96,16 +102,6 @@
<version>3.4.1</version>
</dependency>

<!-- Test Dependencies -->
<!--
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
-->

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
Expand Down Expand Up @@ -159,44 +155,116 @@

<build>
<plugins>



<!-- Jacoco runner to inspect code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<version>${jacoco.version}</version>


<executions>
<execution>
<id>before-unit-test-execution</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${unit.coverage.file}</destFile>
<propertyName>surefire.jacoco.args</propertyName>
</configuration>
</execution>
<execution>
<id>after-unit-test-execution</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${unit.coverage.file}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-test-coverage-report</outputDirectory>
</configuration>
</execution>

<execution>
<id>before-integration-test-execution</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</destFile>
<destFile>${it.coverage.file}</destFile>
<propertyName>failsafe.jacoco.args</propertyName>
<classDumpDir>${project.build.directory}/jacoco-dump</classDumpDir>
<append>true</append>
</configuration>
</execution>

<execution>
<id>after-integration-test-execution</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-test-coverage-report</outputDirectory>
<dataFile>${it.coverage.file}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it-coverage-report</outputDirectory>
</configuration>
</execution>

<execution>
<id>merge-unit-and-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}/jacoco-output/</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>merged.coverage.file</destFile>
</configuration>
</execution>
<execution>
<id>create-merged-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>merged.coverage.file</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report</outputDirectory>
</configuration>
</execution>

</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>${surefire.jacoco.args}</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down Expand Up @@ -238,7 +306,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<!--
check if the following ones are actually needed or not to run the integration tests
Expand All @@ -248,13 +316,18 @@
<maven.home>${maven.home}</maven.home>
</systemProperties>

<!--
<includes>
<include>**/*IT.java</include>
</includes>
-->
<argLine>${failsafe.jacoco.args}</argLine>
<includes>
<include>**/*IT.java</include>
</includes>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>

<!-- based on https://github.com/khmarbaise/maven-it-extension/discussions/328 , to be able to track coverage of IT tests -->
<environmentVariables>
<MAVEN_OPTS>${jacoco.maven.opts}</MAVEN_OPTS>
</environmentVariables>
</configuration>
<executions>
<execution>
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/app/getxray/xray/DummyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.getxray.xray;

import org.junit.jupiter.api.Test;

import app.getxray.xray.XrayResultsImporter.CloudBuilder;

public class DummyTest {

@Test
public void resultsImporterBuilderTest() {
CloudBuilder xrayImporterBuilder = new XrayResultsImporter.CloudBuilder("clientId", "clientSecret");
xrayImporterBuilder.build();
}
}

0 comments on commit 504e0c8

Please sign in to comment.