Partial EMMA code coverage in Scala Case class for IntelliJ IDEA 10.5

I am using IntelliJ IDEA 10.5 with the Scala v0.4.1338 plugin updated August 14th and Scala 2.9.0.1. I recently started using the EMMA coverage testing tool in IDEA to generate coverage reports.

I can’t determine why the constructor line of my Scala class class shows only partial (yellow) coverage. I looked at the EMMA FAQ and researched the question online without success. Does anyone know how I can achieve 100% coverage of the case class?

+6
source share
2 answers

case class A(a: Any) create for you several techniques, including:

  • A#equals
  • A#canEqual
  • A#hashCode
  • A#toString
  • A#productPrefix
  • A#productElement
  • A#productArity
  • A#productIterator
  • A#copy
  • A.unapply
  • A.apply

Most of them will be indicated in bytecode in the same line number as the class definition.

You can write a reflective utility to call all of these methods in each unit test for your case classes, fix the code coverage tool to ignore this line, or just put up with it.

+4
source

I know this is a very old question, but the problem still stands today to some extent. Given a simple class of cases, in order to get a full coverage report from IntelliJ, you also need to test the unapply method.

 // Code final case class Foo(symbol: String, name: String) // Test val myFoo = Foo("TheSymbol", "TheName") Foo.unapply(myFoo).get should be(("TheSymbol", "TheName")) 

Without this, I got 50% coverage for a base case class like this.

0
source

Source: https://habr.com/ru/post/895186/


All Articles