Skip to content

Commit 1f37dd0

Browse files
authored
Coverage minima: add more fine-grained control (#55)
1 parent 09226c5 commit 1f37dd0

File tree

15 files changed

+439
-26
lines changed

15 files changed

+439
-26
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scove
335335
<artifactId>scoverage-maven-plugin</artifactId>
336336
<version>${scoverage.plugin.version}</version>
337337
<configuration>
338-
<minimumCoverage>80</minimumCoverage>
338+
<minimumCoverage>95</minimumCoverage>
339+
<minimumCoverageBranchTotal>90</minimumCoverageBranchTotal>
340+
<minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage>
341+
<minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage>
342+
<minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile>
343+
<minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile>
339344
<failOnMinimumCoverage>true</failOnMinimumCoverage>
340345
</configuration>
341346
<executions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean scoverage:check site -e -ntp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<parent>
6+
<groupId>it.scoverage-maven-plugin</groupId>
7+
<artifactId>test_coverage_minima</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>module01</artifactId>
14+
<name>Test SCoverage Coverage Minima : Module 1</name>
15+
16+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pkg01
2+
3+
class HelloService1
4+
{
5+
def hello =
6+
{
7+
"Hello from module 1"
8+
}
9+
10+
}
11+
12+
object HelloService1 extends HelloService1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package pkg01
2+
3+
import org.junit.Test;
4+
import org.junit.Assert.assertEquals
5+
6+
class HelloServiceTest
7+
{
8+
@Test
9+
def test1()
10+
{
11+
assertEquals("Hello from module 1", HelloService1.hello)
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<parent>
6+
<groupId>it.scoverage-maven-plugin</groupId>
7+
<artifactId>test_coverage_minima</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>module02</artifactId>
14+
<name>Test SCoverage Coverage Minima : Module 2</name>
15+
16+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pkg01
2+
3+
class HelloService1
4+
{
5+
def hello =
6+
{
7+
"Hello from module 2"
8+
}
9+
10+
}
11+
12+
object HelloService1 extends HelloService1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pkg02
2+
3+
class HelloService1
4+
{
5+
def hello =
6+
{
7+
"Hello from module 2"
8+
}
9+
10+
}
11+
12+
object HelloService1 extends HelloService1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package pkg01
2+
3+
import org.junit.Test;
4+
import org.junit.Assert.assertEquals
5+
6+
class HelloServiceTest
7+
{
8+
@Test
9+
def test1()
10+
{
11+
assertEquals("Hello from module 2", HelloService1.hello)
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<parent>
6+
<groupId>it.scoverage-maven-plugin</groupId>
7+
<artifactId>test_coverage_minima</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>module03</artifactId>
14+
<name>Test SCoverage Coverage Minima : Module 3</name>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>@project.groupId@</groupId>
20+
<artifactId>@project.artifactId@</artifactId>
21+
<configuration>
22+
<aggregate>true</aggregate>
23+
<minimumCoverage>100</minimumCoverage>
24+
<minimumCoverageBranchTotal>100</minimumCoverageBranchTotal>
25+
<minimumCoverageStmtPerPackage>100</minimumCoverageStmtPerPackage>
26+
<minimumCoverageBranchPerPackage>100</minimumCoverageBranchPerPackage>
27+
<minimumCoverageStmtPerFile>100</minimumCoverageStmtPerFile>
28+
<minimumCoverageBranchPerFile>100</minimumCoverageBranchPerFile>
29+
</configuration>
30+
<executions>
31+
<execution>
32+
<goals>
33+
<goal>check</goal>
34+
</goals>
35+
</execution>
36+
</executions>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
41+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package pkg01
2+
3+
class HelloService1
4+
{
5+
def hello =
6+
{
7+
"Hello from module 3"
8+
}
9+
10+
}
11+
12+
object HelloService1 extends HelloService1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package pkg01
2+
3+
import org.junit.Test;
4+
import org.junit.Assert.assertEquals
5+
6+
class HelloServiceTest
7+
{
8+
@Test
9+
def test1()
10+
{
11+
assertEquals("Hello from module 3", HelloService1.hello)
12+
}
13+
14+
}

src/it/test_coverage_minima/pom.xml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>it.scoverage-maven-plugin</groupId>
9+
<artifactId>integration_tests_parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../integration_tests_parent/pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>test_coverage_minima</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>pom</packaging>
17+
<name>Test Scoverage coverage minima</name>
18+
<description>Test Scoverage coverage minima</description>
19+
20+
<properties>
21+
<scala.compat.version>2.13</scala.compat.version>
22+
<scala.minor.version>12</scala.minor.version>
23+
</properties>
24+
25+
<modules>
26+
<module>module01</module>
27+
<module>module02</module>
28+
<module>module03</module>
29+
</modules>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
</plugin>
37+
<plugin>
38+
<groupId>net.alchim31.maven</groupId>
39+
<artifactId>scala-maven-plugin</artifactId>
40+
</plugin>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-surefire-plugin</artifactId>
44+
</plugin>
45+
<plugin>
46+
<groupId>@project.groupId@</groupId>
47+
<artifactId>@project.artifactId@</artifactId>
48+
<configuration>
49+
<aggregate>true</aggregate> <!-- for aggregated report -->
50+
<minimumCoverage>95</minimumCoverage>
51+
<minimumCoverageBranchTotal>90</minimumCoverageBranchTotal>
52+
<minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage>
53+
<minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage>
54+
<minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile>
55+
<minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile>
56+
<failOnMinimumCoverage>false</failOnMinimumCoverage>
57+
</configuration>
58+
<executions>
59+
<execution>
60+
<goals>
61+
<goal>check</goal>
62+
</goals>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def checkModule(logText, module, coverageLog) {
2+
assert new File(basedir, module + "/target/scoverage.xml").exists()
3+
assert new File(basedir, module + "/target/site/scoverage/index.html").exists()
4+
def entry = logText.find {
5+
it.startsWith("scoverage") &&
6+
it.contains(":check (default-cli) @ " + module + " ---\n")
7+
}
8+
assert entry != null
9+
assert entry.endsWith(" @ " + module + " ---" + coverageLog.replaceAll("\r\n", "\n") + "[INFO] ")
10+
}
11+
12+
try {
13+
// check coverage minima
14+
def logText = (new File(basedir, "build.log")).text.replaceAll("\r\n", "\n").split(/\n\[INFO\] \-\-\- /)
15+
16+
checkModule(logText, "module01",
17+
"""
18+
|[INFO] Coverage is 100%: Statement:Total!
19+
|[INFO] Coverage is 100%: Branch:Total!
20+
|""".stripMargin()
21+
)
22+
checkModule(logText, "module02",
23+
"""
24+
|[ERROR] Coverage is below minimum [50.00% < 95.00%]: Statement:Total
25+
|[INFO] Coverage is 100%: Branch:Total!
26+
|[ERROR] Coverage is below minimum [0.00% < 90.00%]: Statement:Package:pkg02
27+
|[ERROR] Coverage is below minimum [0.00% < 85.00%]: Branch:Package:pkg02
28+
|[ERROR] Coverage is below minimum [0.00% < 85.00%]: Statement:File:HelloService1.scala
29+
|[ERROR] Coverage is below minimum [0.00% < 80.00%]: Branch:File:HelloService1.scala
30+
|""".stripMargin()
31+
)
32+
checkModule(logText, "module03",
33+
"""
34+
|[INFO] Coverage is 100%: Statement:Total!
35+
|[INFO] Coverage is 100%: Branch:Total!
36+
|""".stripMargin()
37+
)
38+
39+
return true
40+
41+
} catch (Throwable e) {
42+
e.printStackTrace()
43+
return false
44+
}

0 commit comments

Comments
 (0)