【问题标题】:How to exclude method in class from scoverage report?如何从覆盖报告中排除类中的方法?
【发布时间】:2023-02-23 04:58:37
【问题描述】:
在我的 scala play 框架应用程序中,我想从覆盖报告中排除的方法很少。有什么办法可以做到这一点?对于 Jacoco 0.8.2 版本,可能类似于对要排除的方法使用 @Generated 注释。
例子:
class TestClass {
@Generated
def methodN = {}
}
或者可以在中使用excludeMethods += "TestClass.methodN, TestClass.methodX"之类的东西构建.sbt文件?
【问题讨论】:
标签:
scala
playframework
sbt
code-coverage
scoverage
【解决方案1】:
来自the docs 我会说,在不更改源代码的情况下,您可以从构建工具中仅排除类/包/文件
// examples of scalac options from the docs
-P:scoverage:excludedPackages:.*.utils..*;.*.SomeClass;org.apache..*
-P:scoverage:excludedFiles:.*/two/GoodCoverage;.*/three/.*
但是如果你可以修改源代码,你可以通过在它周围放置正确的 cmets 来排除你想要的任何东西
// $COVERAGE-OFF$
def methodIWantToIgnore = 2 + 2
// $COVERAGE-ON$