[英]How do you impose scala code coverage specifically for integration tests?
Am running the integration test using following sbt command 我正在使用以下sbt命令运行集成测试
sbt clean coverage it:test coverageReport sbt clean cover it:test coverageReport
This command runs integration tests, instruments it and generates report as well. 此命令运行集成测试,检测它并生成报告。
Build.sbt has following: Build.sbt有以下内容:
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. 输出结果具有20.16%的代码覆盖率,但build.sbt中的限制未强制执行限制。
If I change build.sbt to following it works: 如果我将build.sbt更改为以下它的工作原理:
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:0.13.17
sbt-scoverage : 1.5.1 sbt-scoverage:1.5.1
The following two workarounds seem to work on my machine (sbt-scoverage 1.5.1, sbt 1.1.1, scala 2.12.5) 以下两个解决方法似乎适用于我的机器(sbt-scoverage 1.5.1,sbt 1.1.1,scala 2.12.5)
Workaround 1 - Use inConfig
to scope to a configuration: 解决方法1 - 使用inConfig
到配置范围:
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
. 现在执行sbt clean coverage it:test it:coverageReport
抛出Coverage minimum was not reached
。
Workaround 2 - Modify coverageMinimum
setting within a custom command : 解决方法2 - 在自定义命令中修改coverageMinimum
设置 :
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
. 现在执行sbt itTestWithMinCoverage
抛出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. 注意在执行itTestWithMinCoverage
, state
被丢弃,因此coverageMinimum
应该回到默认值,因此不会影响单元测试。
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
. 似乎问题是(除了我不了解范围如何正常工作) checkCoverage
甚至coverageMinimum in IntegrationTest
设置coverageMinimum in IntegrationTest
后checkCoverage
获取coverageMinimum
默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.