简体   繁体   English

用于 IntelliJ IDEA 10.5 的 Scala 案例 Class 中的部分 EMMA 代码覆盖

[英]Partial EMMA code coverage in Scala Case Class for IntelliJ IDEA 10.5

I'm using IntelliJ IDEA 10.5 with the Scala plugin v0.4.1338 updated on August 14th, and Scala 2.9.0.1.我正在使用 IntelliJ IDEA 10.5 和 8 月 14 日更新的 Scala 插件 v0.4.1338 和 Scala 2.9.0.1。 I recently began using the EMMA test coverage utility in IDEA to generate coverage reports.我最近开始使用 IDEA 中的 EMMA 测试覆盖率实用程序来生成覆盖率报告。

I cannot determine why the constructor line of my Scala case class is only showing partial (yellow) coverage.我无法确定为什么我的 Scala 案例 class 的构造函数行仅显示部分(黄色)覆盖。 I have looked in the EMMA FAQs and researched the matter online with no success.我查看了 EMMA 常见问题解答并在线研究了此事,但没有成功。 Does anyone have any idea how I can reach 100% coverage on a case class?有谁知道如何在 class 案例上达到 100% 的覆盖率?

case class A(a: Any) generate a number of methods for you, among them: case class A(a: Any)为您生成多种方法,其中:

  1. A#equals
  2. A#canEqual
  3. A#hashCode
  4. A#toString
  5. A#productPrefix
  6. A#productElement
  7. A#productArity
  8. A#productIterator
  9. A#copy
  10. A.unapply
  11. A.apply

Most of these will be reported in the bytecode at the same line number as the class definition.其中大部分将在与 class 定义相同的行号的字节码中报告。

You could write a reflective utility to call all of these methods in each unit test for your case classes, patch the code coverage tool to ignore that line, or just put up with it.您可以编写一个反射实用程序来为您的案例类在每个单元测试中调用所有这些方法,修补代码覆盖工具以忽略该行,或者只是忍受它。

I know this is a very old question, but the problem still stands today to some extent.我知道这是一个非常古老的问题,但这个问题在某种程度上仍然存在。 Given a simple case class, in order to get a full coverage report from IntelliJ you need to test the unapply method as well.给定一个简单的案例 class,为了从 IntelliJ 获得完整的覆盖率报告,您还需要测试unapply方法。

// Code

final case class Foo(symbol: String, name: String)

// Test

val myFoo = Foo("TheSymbol", "TheName")

Foo.unapply(myFoo).get should be(("TheSymbol", "TheName"))

Without it I got 50% coverage for a basic case class like that.没有它,我得到了 50% 的基本案例 class 的覆盖率。

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

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