Skip to content

Commit 73abca3

Browse files
committed
Coverage minima: Add integration tests to check it
1 parent 09226c5 commit 73abca3

File tree

13 files changed

+265
-0
lines changed

13 files changed

+265
-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 2"
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 2"
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 2", HelloService1.hello)
12+
}
13+
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
</configuration>
25+
<executions>
26+
<execution>
27+
<goals>
28+
<goal>check</goal>
29+
</goals>
30+
</execution>
31+
</executions>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
36+
</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 3"
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 3", HelloService1.hello)
12+
}
13+
14+
}

src/it/test_coverage_minima/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
<failOnMinimumCoverage>false</failOnMinimumCoverage>
52+
</configuration>
53+
<executions>
54+
<execution>
55+
<goals>
56+
<goal>check</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.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] 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+
checkModule(logText, "module03",
31+
"""
32+
|[INFO] Statement coverage.: 100.00%
33+
|[INFO] Branch coverage....: 100.00%
34+
|[INFO] 100% Coverage !
35+
|""".stripMargin()
36+
)
37+
38+
return true
39+
40+
} catch (Throwable e) {
41+
e.printStackTrace()
42+
return false
43+
}

0 commit comments

Comments
 (0)