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

ClassCastException when using forked mode tests

Open retronym opened this issue 11 years ago • 6 comments

Example project: https://github.com/retronym/jacoco4sbt-demo/tree/bug/fork

> jacoco:cover
Nov 27, 2013 9:54:56 AM Test$ $jacocoInit
INFO: 2d8b62e0
[error] Test CoverageTest.main failed: java.lang.ExceptionInInitializerError: null
[error]     at CoverageTest.main(CoverageTest.scala:4)
[error]     ...
[error] Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to [Z
[error]     at Test$.$jacocoInit(Source.scala)
[error]     at Test$.<clinit>(Source.scala)
[error]     ... 36 more

retronym avatar Nov 27 '13 09:11 retronym

I can verify that I also have this issue. I'm using:

      testGrouping in jacoco.Config := {
        val original: Seq[Tests.Group] = (testGrouping in jacoco.Config).value

        original.map { group =>
          val forkOptions = ForkOptions(
            bootJars = Nil,
            javaHome = javaHome.value,
            connectInput = connectInput.value,
            outputStrategy = outputStrategy.value,
            runJVMOptions = javaOptions.value,
            workingDirectory = Some(new File(System.getProperty("user.dir"))),
            envVars = envVars.value
          )

          group.copy(runPolicy = Tests.SubProcess(forkOptions))
        }
      }

Which was suggested as a fix for multiproject builds here: https://github.com/playframework/playframework/issues/1834

muymoo avatar Dec 06 '13 20:12 muymoo

It has been stated here that jacoco4sbt will not work when forking. It seems that's still an issue, and I can confirm I have the same error as above.

ncortot avatar Dec 17 '13 00:12 ncortot

Forked tests should work as of version 2.1.4 of the plugin. At least my own tests say so. - Could you please verify?

jmhofer avatar Dec 23 '13 15:12 jmhofer

Same error on 2.1.4 :( Forked or not forked.

leonardschneider avatar Apr 06 '14 07:04 leonardschneider

A sample for a working project configuration with forked tests can be found in the test resources here: https://github.com/sbt/jacoco4sbt/tree/master/src/test/resources/jacocoTestForked - maybe this helps? - Otherwise, could someone with the problem please post a small example where the forked tests fail?

jmhofer avatar May 07 '14 09:05 jmhofer

I recently observed this when trying to use sbt-cucumber with jacoco. See link here: https://github.com/sbt/sbt-cucumber/issues/1

kieranbop avatar Apr 05 '18 12:04 kieranbop