Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage minima: add more fine-grained control #55

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scove
<artifactId>scoverage-maven-plugin</artifactId>
<version>${scoverage.plugin.version}</version>
<configuration>
<minimumCoverage>80</minimumCoverage>
<minimumCoverage>95</minimumCoverage>
<minimumCoverageBranchTotal>90</minimumCoverageBranchTotal>
<minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage>
<minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage>
<minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile>
<minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile>
<failOnMinimumCoverage>true</failOnMinimumCoverage>
</configuration>
<executions>
Expand Down
1 change: 1 addition & 0 deletions src/it/test_coverage_minima/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean scoverage:check site -e -ntp
16 changes: 16 additions & 0 deletions src/it/test_coverage_minima/module01/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<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">

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>test_coverage_minima</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module01</artifactId>
<name>Test SCoverage Coverage Minima : Module 1</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg01

class HelloService1
{
def hello =
{
"Hello from module 1"
}

}

object HelloService1 extends HelloService1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pkg01

import org.junit.Test;
import org.junit.Assert.assertEquals

class HelloServiceTest
{
@Test
def test1()
{
assertEquals("Hello from module 1", HelloService1.hello)
}

}
16 changes: 16 additions & 0 deletions src/it/test_coverage_minima/module02/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<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">

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>test_coverage_minima</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module02</artifactId>
<name>Test SCoverage Coverage Minima : Module 2</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg01

class HelloService1
{
def hello =
{
"Hello from module 2"
}

}

object HelloService1 extends HelloService1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg02

class HelloService1
{
def hello =
{
"Hello from module 2"
}

}

object HelloService1 extends HelloService1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pkg01

import org.junit.Test;
import org.junit.Assert.assertEquals

class HelloServiceTest
{
@Test
def test1()
{
assertEquals("Hello from module 2", HelloService1.hello)
}

}
41 changes: 41 additions & 0 deletions src/it/test_coverage_minima/module03/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>

<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">

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>test_coverage_minima</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module03</artifactId>
<name>Test SCoverage Coverage Minima : Module 3</name>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<aggregate>true</aggregate>
<minimumCoverage>100</minimumCoverage>
<minimumCoverageBranchTotal>100</minimumCoverageBranchTotal>
<minimumCoverageStmtPerPackage>100</minimumCoverageStmtPerPackage>
<minimumCoverageBranchPerPackage>100</minimumCoverageBranchPerPackage>
<minimumCoverageStmtPerFile>100</minimumCoverageStmtPerFile>
<minimumCoverageBranchPerFile>100</minimumCoverageBranchPerFile>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg01

class HelloService1
{
def hello =
{
"Hello from module 3"
}

}

object HelloService1 extends HelloService1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pkg01

import org.junit.Test;
import org.junit.Assert.assertEquals

class HelloServiceTest
{
@Test
def test1()
{
assertEquals("Hello from module 3", HelloService1.hello)
}

}
68 changes: 68 additions & 0 deletions src/it/test_coverage_minima/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>integration_tests_parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../integration_tests_parent/pom.xml</relativePath>
</parent>

<artifactId>test_coverage_minima</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Test Scoverage coverage minima</name>
<description>Test Scoverage coverage minima</description>

<properties>
<scala.compat.version>2.13</scala.compat.version>
<scala.minor.version>12</scala.minor.version>
</properties>

<modules>
<module>module01</module>
<module>module02</module>
<module>module03</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<aggregate>true</aggregate> <!-- for aggregated report -->
<minimumCoverage>95</minimumCoverage>
<minimumCoverageBranchTotal>90</minimumCoverageBranchTotal>
<minimumCoverageStmtPerPackage>90</minimumCoverageStmtPerPackage>
<minimumCoverageBranchPerPackage>85</minimumCoverageBranchPerPackage>
<minimumCoverageStmtPerFile>85</minimumCoverageStmtPerFile>
<minimumCoverageBranchPerFile>80</minimumCoverageBranchPerFile>
<failOnMinimumCoverage>false</failOnMinimumCoverage>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
44 changes: 44 additions & 0 deletions src/it/test_coverage_minima/validate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def checkModule(logText, module, coverageLog) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome tests! Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you added the tests, i just duplicated :)

assert new File(basedir, module + "/target/scoverage.xml").exists()
assert new File(basedir, module + "/target/site/scoverage/index.html").exists()
def entry = logText.find {
it.startsWith("scoverage") &&
it.contains(":check (default-cli) @ " + module + " ---\n")
}
assert entry != null
assert entry.endsWith(" @ " + module + " ---" + coverageLog.replaceAll("\r\n", "\n") + "[INFO] ")
}

try {
// check coverage minima
def logText = (new File(basedir, "build.log")).text.replaceAll("\r\n", "\n").split(/\n\[INFO\] \-\-\- /)

checkModule(logText, "module01",
"""
|[INFO] Coverage is 100%: Statement:Total!
|[INFO] Coverage is 100%: Branch:Total!
|""".stripMargin()
)
checkModule(logText, "module02",
"""
|[ERROR] Coverage is below minimum [50.00% < 95.00%]: Statement:Total
|[INFO] Coverage is 100%: Branch:Total!
|[ERROR] Coverage is below minimum [0.00% < 90.00%]: Statement:Package:pkg02
|[ERROR] Coverage is below minimum [0.00% < 85.00%]: Branch:Package:pkg02
|[ERROR] Coverage is below minimum [0.00% < 85.00%]: Statement:File:HelloService1.scala
|[ERROR] Coverage is below minimum [0.00% < 80.00%]: Branch:File:HelloService1.scala
|""".stripMargin()
)
checkModule(logText, "module03",
"""
|[INFO] Coverage is 100%: Statement:Total!
|[INFO] Coverage is 100%: Branch:Total!
|""".stripMargin()
)

return true

} catch (Throwable e) {
e.printStackTrace()
return false
}
Loading