sbt-jacoco icon indicating copy to clipboard operation
sbt-jacoco copied to clipboard

Unable to run code coverage for integration tests in Play 2.4.2 project

Open kangastalo opened this issue 9 years ago • 10 comments

We are upgrading from Play 2.1.4 to Play 2.4.2 and we would like to start using jacoco code coverage for integration tests. I have added latest jacoco plugin to plugins.sbt (addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")) and then defined itJacoco in build.scala (itJacoco.settings) as instructed in https://github.com/sbt/jacoco4sbt/wiki.

Now as I try to compile my project, I get these errors below. If I remove the itJacoco setting from build.scala, then my project compiles ok. Jacoco for unit tests is working ok, just this itJacoco is giving me a slight headache. Can you please help?

Stack trace below:

References to undefined settings:

my_project/it:fullClasspath from my_project/it-jacoco:fullClasspath ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:84)

my_project/it:definedTests from my_project/it-jacoco:definedTests ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:91)

my_project/it:definedTestNames from my_project/it-jacoco:definedTestNames ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:92)

at sbt.Init$class.Uninitialized(Settings.scala:265)
at sbt.Def$.Uninitialized(Def.scala:10)
at sbt.Init$class.delegate(Settings.scala:191)
at sbt.Def$.delegate(Def.scala:10)
at sbt.Init$class.compiled(Settings.scala:138)
at sbt.Def$.compiled(Def.scala:10)
at sbt.Init$class.make(Settings.scala:144)
at sbt.Def$.make(Def.scala:10)
at sbt.Load$.apply(Load.scala:135)
at sbt.Load$.defaultLoad(Load.scala:36)
at sbt.BuiltinCommands$.doLoadProject(Main.scala:481)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$.process(Command.scala:92)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.State$$anon$1.process(State.scala:184)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.MainLoop$.next(MainLoop.scala:98)
at sbt.MainLoop$.run(MainLoop.scala:91)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:70)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:65)
at sbt.Using.apply(Using.scala:24)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:65)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:48)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:32)
at sbt.MainLoop$.runLogged(MainLoop.scala:24)
at sbt.StandardMain$.runManaged(Main.scala:53)
at sbt.xMain.run(Main.scala:28)
at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
at xsbt.boot.Launch$.run(Launch.scala:109)
at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
at xsbt.boot.Launch$.launch(Launch.scala:117)
at xsbt.boot.Launch$.apply(Launch.scala:18)
at xsbt.boot.Boot$.runImpl(Boot.scala:41)
at xsbt.boot.Boot$.main(Boot.scala:17)
at xsbt.boot.Boot.main(Boot.scala)
[error] References to undefined settings:
[error]
[error]   my_project/it:fullClasspath from my_project/it-jacoco:fullClasspath ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:84)
[error]
[error]   my_project/it:definedTests from my_project/it-jacoco:definedTests ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:91)
[error]
[error]   my_project/it:definedTestNames from my_project/it-jacoco:definedTestNames ((de.johoop.jacoco4sbt.JacocoPlugin.SharedSettings) JacocoPlugin.scala:92)
[error]  

kangastalo avatar Oct 16 '15 10:10 kangastalo

Is there a solution I get the same issues

anildes avatar Feb 14 '16 04:02 anildes

same here too

maxkremer avatar Feb 18 '16 19:02 maxkremer

same here

hsupunw avatar May 13 '16 07:05 hsupunw

Currently happening with plugin version 2.2.0

gomes-rocket avatar Apr 10 '17 10:04 gomes-rocket

same here too

qyf404 avatar Jul 15 '17 17:07 qyf404

same here too with jacoco4sbt plugin version 2.3.0 and 2.1.6

gsaad avatar Jul 19 '17 08:07 gsaad

Looks like play project requires additional IntegrationTest configuration:

  1. lazy val root = (project in file(".")).configs(IntegrationTest)
  2. Then, set next settings:
Defaults.itSettings ++ Seq(
   unmanagedSourceDirectories in IntegrationTest <+= baseDirectory(_ / "tests" / "shared"),
   sourceDirectories          in IntegrationTest <+= baseDirectory(_ / "tests" / "integration"),
   javaSource                 in IntegrationTest <<= baseDirectory(_ / "tests" / "integration"),
   resourceDirectory          in IntegrationTest <<= baseDirectory(_ / "tests" / "resources"),
   resourceDirectories        in IntegrationTest <+= baseDirectory(_ / "tests" / "resources")
) ++ jacoco.settings ++ itJacoco.settings

In general, there's no need to use itJacoco.settings in play 2, jacoco.settings should be enough. Using jacoco.settings only, you are able to generate (jacoco:cover) and aggregate (jacoco:aggregateReport) report (reports => when multi modules => add.aggregate(project1, project2)) without problems.

UnknownNPC avatar Sep 08 '17 16:09 UnknownNPC

@UnknownNPC I tried using your method, I am getting the following error

[error] [/xxx/build.sbt]:125: illegal start of simple expression [error] [/xxx/build.sbt]:129: ')' expected but eof found.

karthikkbaalaji avatar Sep 14 '17 08:09 karthikkbaalaji

@karthikkbaalaji ah, true. Try to remove comma char: replace resourceDirectories in IntegrationTest <+= baseDirectory(_ / "tests" / "resources"), with this resourceDirectories in IntegrationTest <+= baseDirectory(_ / "tests" / "resources")

UnknownNPC avatar Sep 14 '17 08:09 UnknownNPC

Cool it worked, @UnknownNPC

I have following setup: test/UT test/IT

configuring this I can run it tests using itJacoco:cover However, when I do jacoco:cover it runs both UT and IT

Is there a way to prevent jacoco:cover to not run IT Tests?

(Apologize if it's hijacking this thread)

karthikkbaalaji avatar Sep 14 '17 09:09 karthikkbaalaji