Am running the integration test using following sbt command
sbt clean coverage it:test coverageReport
This command runs integration tests, instruments it and generates report as well.
Build.sbt has following:
coverageMinimum in IntegrationTest := 21.0
coverageFailOnMinimum in IntegrationTest := true
Output looks like:
[info] Statement coverage.: 20.16%
[info] Branch coverage....: 12.00%
[info] Coverage reports completed
[info] All done. Coverage was [20.16%]
Output result has 20.16% code coverage but the limits in build.sbt are not enforcing the limit.
If I change build.sbt to following it works:
coverageMinimum := 21.0
coverageFailOnMinimum := true
Wanted to know what am I missing for specifying limits specifically for Integration tests
Version Information:
sbt : 0.13.17
sbt-scoverage : 1.5.1
As a Developer or Tester, you can absolutely include Integration Testing in Code Coverage, if you have integrated code scripts.
Code Coverage is a metric that measures what percentage of your code has been executed during unit and integration tests. JaCoCo is a great open-source toolkit for code coverage measurements. JaCoCo was originally written for Java and runs on the JVM, but because it's bytecode-based it works for Scala too.
sbt-scoverage is an sbt plugin that offers support for Scala code coverage using scoverage. This plugin supports Scala 2.12, 2.13, and 3. NOTE: that ScalaJS and Scala Native support is limited to Scala 2.
The following two workarounds seem to work on my machine (sbt-scoverage 1.5.1, sbt 1.1.1, scala 2.12.5)
Workaround 1 - Use inConfig
to scope to a configuration:
inConfig(IntegrationTest)(ScoverageSbtPlugin.projectSettings),
inConfig(IntegrationTest)(Seq(coverageMinimum := 21, coverageFailOnMinimum := true))
Now executing sbt clean coverage it:test it:coverageReport
throws Coverage minimum was not reached
.
Workaround 2 - Modify coverageMinimum
setting within a custom command:
def itTestWithMinCoverage = Command.command("itTestWithMinCoverage") { state =>
val extracted = Project extract state
val stateWithCoverage = extracted.append(Seq(coverageEnabled := true, coverageMinimum := 21.0, coverageFailOnMinimum := true), state)
val (s1, _) = Project.extract(stateWithCoverage).runTask(test in IntegrationTest, stateWithCoverage)
val (s2, _) = Project.extract(s1).runTask(coverageReport in IntegrationTest, s1)
s2
}
commands ++= Seq(itTestWithMinCoverage)
Now executing sbt itTestWithMinCoverage
throws Coverage minimum was not reached
. Note after executing itTestWithMinCoverage
the state
is discarded so coverageMinimum
should be back to default value, and thus not affect unit tests.
It seems the issue is (besides my lack of understanding how scopes exactly work) checkCoverage
picks up default value of coverageMinimum
even after setting coverageMinimum in IntegrationTest
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With