简体   繁体   English

从覆盖率报告中排除 sbt 覆盖率的测试

[英]Excluding tests from coverage report with sbt coverage

I have a test that is non-functional, so I do not want it to affect the coverage report.我有一个没有功能的测试,所以我不希望它影响覆盖率报告。 Other than putting it in a separate project, is there a way to exclude it from the report when running除了把它放在一个单独的项目中,有没有办法在运行时将它从报告中排除

sbt clean coverage test coverageReport

As it stands, it is obscuring missing coverage by other tests.就目前而言,它正在掩盖其他测试的缺失覆盖范围。

To explain better I've made a sample project in GitHub .为了更好地解释,我在 GitHub 中做了一个示例项目 There are two test classes - MainSpec and DoubleSpec.有两个测试类 - MainSpec 和 DoubleSpec。 I've commented out the test in DoubleSpec to show that the test in MainSpec gives 100% coverage.我已经注释掉了 DoubleSpec 中的测试,以表明 MainSpec 中的测试提供了 100% 的覆盖率。 However, it's obscuring that DoubleSpec is "broken".然而,它掩盖了 DoubleSpec 是“坏了”。 MainSpec is not testing the functionality, only checking the return type. MainSpec 不测试功能,只检查返回类型。

The example is contrived.这个例子是人为的。 I have a much more complex example which I cannot share.我有一个更复杂的例子,我无法分享。

I've tried using coverageExcludedFiles but this only excludes source from coverage, not tests.我试过使用coverageExcludedFiles但这只会从覆盖范围中排除源,而不是测试。

Consider creating a ScalaTest tag考虑创建一个 ScalaTest标签

import org.scalatest.Tag
object ExcludeFromCoverage extends Tag("ExcludeFromCoverage")

based on which to exclude particular tests only when running coverage基于它仅在运行覆盖时排除特定测试

  "double" should "return an Int" taggedAs ExcludeFromCoverage in {
    ...
  }

so now executing using testOnly like so所以现在像这样使用testOnly执行

sbt clean coverage  "testOnly * -- -l ExcludeFromCoverage" coverageReport

will exclude "double" should "return an Int" from the coverage report.将从覆盖率报告中排除"double" should "return an Int" Note you can still execute all tests with sbt test .请注意,您仍然可以使用sbt test执行所有测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM