java - Why when I unit test do I get coverage points with `final lazy val` but not `final val`? -


i have code (project source available here - https://github.com/natemurthy/testing-final-vals):

object main extends app {   final val name = "foo" } 

and i'm using scalatest , sbt coverage plugin test code so:

import org.scalatest.{flatspec,matchers}  class maintest extends flatspec matchers {   should "have name" in {     main.name shouldbe "foo"   } } 

but reason coverage points when include lazy modifier in expression:

enter image description here

enter image description here

why case?

my guess coverage tool counts executed lines.

final val name = "foo"is compiled constant inline value in bytecode private static final in java. when accessing variable read value bytecode constant. more info on inlining constant values during compiling

final lazy val name = "foo"on other hand compiles lazy construction method since there no lazy values in jvm. if access variable lazy construction method executed. more info on scala lazy value bytecode generation


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -