2

我无法让 sbt-scoverage 发现和分析我们的测试。我们应该有很好的测试覆盖率(至少 80%);所有测试都运行并通过。但覆盖率报告显示几乎为零的覆盖率(~ 3%)。

我唯一能想到的是,我们正在使用 specs2(以及 scalacheck)。我见过的大多数示例都使用 ScalaTest。

例如:我们在模型包中有四个类。即使测试结果表明它们已经过彻底测试,它们的覆盖率也为零:

[info] Compiling 5 Scala sources to /Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/test-classes...
[info] TestCreditModel
[info]    + Given a credit
[info]      When validation is performed
[info]      Then credits between 1 and 60 should be acceptable
[info]    + And credits less than 1 or greater than 60 should not
[info]
[info]    + Given a category and attribute credits
[info]      When validation is performed
[info]      Then we should get validated category credits
[info]    + And we should get validated attribute credits
[info]    + And invalid category credits should not pass validation
[info]    + And invalid attribute credits should not pass validation
[info]
[info] Total for specification TestCreditModel
[info] Finished in 86 ms
[info] 6 examples, 600 expectations, 0 failure, 0 error
[info]
[info] TestCategoryModel
[info]    + Given a well formed category
[info]      When validation is performed
[info]      Categories with good abbreviations and descriptions should be valid
[info]    + And those with invalid abbreviations should not
[info]    + And those with invalid descriptions should not
[info]
[info]
[info] Total for specification TestCategoryModel
[info] Finished in 167 ms
[info] 3 examples, 300 expectations, 0 failure, 0 error

但我看到覆盖率肯定在运行:

[info] Compiling 11 Scala sources and 1 Java source to /Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/classes...
[info] [info] Cleaning datadir [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-data]
[info] [info] Beginning coverage instrumentation
[info] [info] Instrumentation completed [31 statements]
[info] [info] Wrote instrumentation file [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-data/scoverage.coverage.xml]
[info] [info] Will write measurement data to [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-data]

但是覆盖率报告显然没有选择我们正在测试的类:

[IDC] $ coverageReport
[info] Waiting for measurement data to sync...
[info] Reading scoverage instrumentation [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-data/scoverage.coverage.xml]
[info] Reading scoverage measurements...
[info] Generating scoverage reports...
[info] Written Cobertura report [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/coverage-report/cobertura.xml]
[info] Written XML coverage report [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-report/scoverage.xml]
[info] Written HTML coverage report [/Users/zbeckman/Projects/Accenture/Trident_IDC_Training/target/scala-2.11/scoverage-report/index.html]
[info] Statement coverage.: 3.23%
[info] Branch coverage....: 100.00%
[info] Coverage reports completed
[error] Coverage is below minimum [3.23% < 80.0%]
[trace] Stack trace suppressed: run last *:coverageReport for the full output.
[error] (*:coverageReport) Coverage minimum was not reached
[error] Total time: 1 s, completed Aug 25, 2016 1:11:27 PM

查看报告时,我看到模型包中的四个类完全未经测试。

我们的built.sbt 中有以下内容:

coverageEnabled := true

coverageMinimum := 80

coverageFailOnMinimum := true

显然,由于我们有上述设置,并且由于 scoverage 无法找到测试,我们会遇到构建失败:

[error] Coverage is below minimum [3.23% < 80.0%]
[error] (*:coverageReport) Coverage minimum was not reached
[error] Total time: 1 s, completed Aug 25, 2016 1:39:12 PM
4

0 回答 0