Skip to content

Commit 092c440

Browse files
authored
Merge pull request #2 from bitcoder/add_jacoco
add jacoco with unit and integration test analysis
2 parents 5bcd23a + d4fb090 commit 092c440

File tree

3 files changed

+178
-3
lines changed

3 files changed

+178
-3
lines changed

.github/workflows/maven.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ jobs:
4040
run: mvn -B package --file pom.xml
4141
- name: Run integration tests
4242
run: mvn -B failsafe:integration-test failsafe:verify --file pom.xml
43+
- name: Add code coverage information to PR
44+
id: jacoco-pr
45+
uses: madrapps/jacoco-report@v1.7.1
46+
if: github.event_name == 'pull_request'
47+
with:
48+
paths: |
49+
${{ github.workspace }}/**/target/site/jacoco-merged-test-coverage-report/jacoco.xml
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
min-coverage-overall: 80
52+
min-coverage-changed-files: 80
4353
- name: Push results to Xray on Jira Cloud
4454
if: always()
4555
env:
4656
XRAYCLOUD_CLIENT_ID: ${{ secrets.XRAYCLOUD_CLIENT_ID }}
4757
XRAYCLOUD_CLIENT_SECRET: ${{ secrets.XRAYCLOUD_CLIENT_SECRET }}
48-
XRAYCLOUD_TEST_PLAN_KEY: ${{ secrets.XRAYCLOUD_TEST_PLAN_KEY }}
58+
XRAYCLOUD_TEST_PLAN_KEY: ${{ vars.XRAYCLOUD_TEST_PLAN_KEY }}
4959
REVISON: ${{ github.ref_name}}
5060
TEST_ENVIRONMENT: java${{ matrix.java }}
5161
run: mvn -Dxray.clientId=${{ env.XRAYCLOUD_CLIENT_ID }} -Dxray.clientSecret=${{ env.XRAYCLOUD_CLIENT_SECRET }} -Dxray.testEnvironment=${{ env.TEST_ENVIRONMENT }} -Dxray.testPlanKey=${{ env.XRAYCLOUD_TEST_PLAN_KEY }} -Dxray.revision=${{ env.REVISON }} xray:import-results

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target/
22
reports/
3-
.vscode/
3+
.vscode/
4+
merged.coverage.file

pom.xml

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
<maven.compiler.target>${java.version}</maven.compiler.target>
2121
<junit-jupiter.version>5.10.2</junit-jupiter.version>
2222
<xray-junit-extensions.version>0.7.3</xray-junit-extensions.version>
23-
<xray-maven-plugin.version>0.7.4</xray-maven-plugin.version>
23+
<xray-maven-plugin.version>0.8.0</xray-maven-plugin.version>
24+
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
25+
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
26+
<jacoco.version>0.8.13</jacoco.version>
27+
<unit.coverage.file>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</unit.coverage.file>
28+
<it.coverage.file>${project.build.directory}/jacoco-output/jacoco-it-tests.exec</it.coverage.file>
29+
<merged.coverage.file>${project.build.directory}/jacoco-output/merged.exec</merged.coverage.file>
30+
<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>
2431
</properties>
2532
<dependencies>
2633
<dependency>
@@ -93,6 +100,163 @@
93100

94101
<build>
95102
<plugins>
103+
104+
<!-- Jacoco runner to inspect code coverage -->
105+
<plugin>
106+
<groupId>org.jacoco</groupId>
107+
<artifactId>jacoco-maven-plugin</artifactId>
108+
<version>${jacoco.version}</version>
109+
110+
<executions>
111+
<execution>
112+
<id>before-unit-test-execution</id>
113+
<goals>
114+
<goal>prepare-agent</goal>
115+
</goals>
116+
<configuration>
117+
<destFile>${unit.coverage.file}</destFile>
118+
<propertyName>surefire.jacoco.args</propertyName>
119+
</configuration>
120+
</execution>
121+
<execution>
122+
<id>after-unit-test-execution</id>
123+
<phase>test</phase>
124+
<goals>
125+
<goal>report</goal>
126+
</goals>
127+
<configuration>
128+
<dataFile>${unit.coverage.file}</dataFile>
129+
<outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-test-coverage-report</outputDirectory>
130+
</configuration>
131+
</execution>
132+
133+
<execution>
134+
<id>before-integration-test-execution</id>
135+
<phase>pre-integration-test</phase>
136+
<goals>
137+
<goal>prepare-agent-integration</goal>
138+
</goals>
139+
<configuration>
140+
<destFile>${it.coverage.file}</destFile>
141+
<propertyName>failsafe.jacoco.args</propertyName>
142+
<classDumpDir>${project.build.directory}/jacoco-dump</classDumpDir>
143+
<append>true</append>
144+
</configuration>
145+
</execution>
146+
<execution>
147+
<id>after-integration-test-execution</id>
148+
<phase>post-integration-test</phase>
149+
<goals>
150+
<goal>report</goal>
151+
</goals>
152+
<configuration>
153+
<dataFile>${it.coverage.file}</dataFile>
154+
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it-coverage-report</outputDirectory>
155+
</configuration>
156+
</execution>
157+
158+
<execution>
159+
<id>merge-unit-and-integration</id>
160+
<phase>post-integration-test</phase>
161+
<goals>
162+
<goal>merge</goal>
163+
</goals>
164+
<configuration>
165+
<fileSets>
166+
<fileSet>
167+
<directory>${project.build.directory}/jacoco-output/</directory>
168+
<includes>
169+
<include>*.exec</include>
170+
</includes>
171+
</fileSet>
172+
</fileSets>
173+
<destFile>merged.coverage.file</destFile>
174+
</configuration>
175+
</execution>
176+
<execution>
177+
<id>create-merged-report</id>
178+
<phase>post-integration-test</phase>
179+
<goals>
180+
<goal>report</goal>
181+
</goals>
182+
<configuration>
183+
<dataFile>merged.coverage.file</dataFile>
184+
<outputDirectory>${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report</outputDirectory>
185+
</configuration>
186+
</execution>
187+
188+
</executions>
189+
</plugin>
190+
191+
192+
<plugin>
193+
<groupId>org.apache.maven.plugins</groupId>
194+
<artifactId>maven-surefire-plugin</artifactId>
195+
<version>${maven-surefire-plugin.version}</version>
196+
<configuration>
197+
<argLine>${surefire.jacoco.args}</argLine>
198+
<includes>
199+
<include>**/*Test.java</include>
200+
</includes>
201+
<excludes>
202+
<exclude>**/*IT.java</exclude>
203+
</excludes>
204+
205+
<testFailureIgnore>false</testFailureIgnore>
206+
<disableXmlReport>true</disableXmlReport>
207+
<useFile>false</useFile>
208+
</configuration>
209+
</plugin>
210+
211+
<plugin>
212+
<groupId>org.apache.maven.plugins</groupId>
213+
<artifactId>maven-failsafe-plugin</artifactId>
214+
<version>${maven-failsafe-plugin.version}</version>
215+
<configuration>
216+
<!--
217+
check if the following ones are actually needed or not to run the integration tests
218+
-->
219+
<systemProperties>
220+
<maven.version>${maven.version}</maven.version>
221+
<maven.home>${maven.home}</maven.home>
222+
</systemProperties>
223+
224+
<argLine>${failsafe.jacoco.args}</argLine>
225+
<includes>
226+
<include>**/*IT.java</include>
227+
</includes>
228+
<excludes>
229+
<exclude>**/*Test.java</exclude>
230+
</excludes>
231+
232+
<!-- based on https://github.com/khmarbaise/maven-it-extension/discussions/328 , to be able to track coverage of IT tests -->
233+
<environmentVariables>
234+
<MAVEN_OPTS>${jacoco.maven.opts}</MAVEN_OPTS>
235+
</environmentVariables>
236+
237+
<properties>
238+
<configurationParameters>
239+
<!--
240+
these are the default values, but we want to make sure that they are not changed by the user
241+
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/junit-platform.html
242+
-->
243+
junit.jupiter.execution.parallel.enabled = false
244+
junit.jupiter.execution.parallel.mode.default = same_thread
245+
junit.jupiter.execution.parallel.mode.classes.default = same_thread
246+
</configurationParameters>
247+
</properties>
248+
249+
</configuration>
250+
<executions>
251+
<execution>
252+
<goals>
253+
<goal>integration-test</goal>
254+
<goal>verify</goal>
255+
</goals>
256+
</execution>
257+
</executions>
258+
</plugin>
259+
96260
<plugin>
97261
<groupId>org.springframework.boot</groupId>
98262
<artifactId>spring-boot-maven-plugin</artifactId>

0 commit comments

Comments
 (0)