Skip to content

Commit aa9fef2

Browse files
committed
Coverage minima: Add integration tests to check it
1 parent e81c12d commit aa9fef2

File tree

10 files changed

+200
-0
lines changed

10 files changed

+200
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean scoverage:check site -e -ntp
Lines changed: 16 additions & 0 deletions
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>
Lines changed: 12 additions & 0 deletions
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
Lines changed: 14 additions & 0 deletions
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+
}
Lines changed: 16 additions & 0 deletions
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>
Lines changed: 12 additions & 0 deletions
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
Lines changed: 12 additions & 0 deletions
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 1"
8+
}
9+
10+
}
11+
12+
object HelloService1 extends HelloService1
Lines changed: 14 additions & 0 deletions
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+
}

src/it/test_coverage_minima/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
</modules>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
</plugin>
36+
<plugin>
37+
<groupId>net.alchim31.maven</groupId>
38+
<artifactId>scala-maven-plugin</artifactId>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-surefire-plugin</artifactId>
43+
</plugin>
44+
<plugin>
45+
<groupId>@project.groupId@</groupId>
46+
<artifactId>@project.artifactId@</artifactId>
47+
<configuration>
48+
<aggregate>true</aggregate> <!-- for aggregated report -->
49+
<minimumCoverage>95</minimumCoverage>
50+
<minimumCoverageBranchTotal>90</minimumCoverageBranchTotal>
51+
<minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage>
52+
<minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage>
53+
<minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile>
54+
<minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile>
55+
<failOnMinimumCoverage>false</failOnMinimumCoverage>
56+
</configuration>
57+
<executions>
58+
<execution>
59+
<goals>
60+
<goal>check</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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-maven-plugin:") &&
6+
it.contains(":check (default-cli) @ " + module + " ---\n")
7+
}
8+
assert entry != null
9+
assert entry.endsWith(" @ " + module + " ---" + coverageLog + "[INFO] ")
10+
}
11+
12+
try {
13+
// check coverage minima
14+
def logText = (new File(basedir, "build.log")).text.split(/\n\[INFO\] \-\-\- /)
15+
16+
checkModule(logText, "module01",
17+
"""
18+
|[INFO] Statement coverage.: 100.00%
19+
|[INFO] Branch coverage....: 100.00%
20+
|[INFO] Coverage is above minimum [100.00% >= 95.00%]
21+
|""".stripMargin()
22+
)
23+
checkModule(logText, "module02",
24+
"""
25+
|[INFO] Statement coverage.: 50.00%
26+
|[INFO] Branch coverage....: 100.00%
27+
|[ERROR] Coverage is below minimum [50.00% < 95.00%]
28+
|""".stripMargin()
29+
)
30+
31+
return true
32+
33+
} catch (Throwable e) {
34+
e.printStackTrace()
35+
return false
36+
}

0 commit comments

Comments
 (0)