Skip to content

Commit

Permalink
Code: added test coverage reports by JaCoCo lib (generate by command …
Browse files Browse the repository at this point in the history
…like "mvn install -Djacoco.skip=false");

Code: added test coverage support for Sonar reports;
  • Loading branch information
JayDi85 committed Aug 27, 2021
1 parent 389a019 commit d481172
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Mage.Client/target
Mage.Common/target

# Mage.Plugins
Mage.Plugins/target
Mage.Plugins/Mage.Card.Plugin/target
Mage.Plugins/Mage.Counter.Plugin/target
Mage.Plugins/Mage.Theme.Plugin/target
Expand Down
3 changes: 0 additions & 3 deletions Mage.Tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
3 changes: 0 additions & 3 deletions Mage.Verify/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
52 changes: 52 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,52 @@
</archive>
</configuration>
</plugin>

<!-- JaCoCo Code Coverage report generation -->
<!-- Examples: http://tdongsi.github.io/blog/2017/09/23/jacoco-in-maven-project/ -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<!-- prepare command line to inject in java agent (collect code executing stats) -->
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<!-- generate current module's report -->
<id>generate-code-coverage-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<!-- generate combined report (current and dependency modules) -->
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<!--
for compatible with jacoco code coverage - argLine moved to properties section
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
-->
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -99,8 +135,24 @@

<properties>
<mage-version>1.4.49</mage-version>
<argLine>-Dfile.encoding=UTF-8</argLine>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>

<!--
JaCoCo code coverage disabled by default. If you need to generate
execute stats and reports then run tests by maven command
like "mvn install -Djacoco.skip=false".
Stats:
- load coverage data for IntelliJ IDEA from ./target/jacoco.exec
- web report in ./target/site/jacoco/index.html
- for sonar support see below
-->
<jacoco.skip>true</jacoco.skip>

<!-- Sonar settings for code coverage. Must be only one report for all modules (use report-aggregate goal report from JaCoCo) -->
<aggregate.report.dir>Mage.Verify/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<dependencyManagement>
Expand Down

2 comments on commit d481172

@JayDi85
Copy link
Member Author

@JayDi85 JayDi85 commented on d481172 Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current code coverage by unit tests: 40%

JaCoCo reports example from \target\site\jacoco-aggregate\mage-sets\index.html:
shot_210827_205330

Sonar reports example:
shot_210827_201556

P.S. Sonar report can be found online here: https://sonarcloud.io/dashboard?id=JayDi85_mage (I update it sometime).

@JayDi85
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntelliJ IDEA also support to view generated code coverage report in the editor:

shot_210827_120235
shot_210827_120204
shot_210827_120403

Please sign in to comment.