GithubHelp home page GithubHelp logo

sbt / sbt-jacoco Goto Github PK

View Code? Open in Web Editor NEW
123.0 13.0 67.0 1.81 MB

an sbt plugin for JaCoCo Code Coverage

Home Page: https://scala-sbt.org/sbt-jacoco/

License: Eclipse Public License 1.0

Scala 87.44% HTML 12.56%
sbt sbt-plugin jacoco coverage scala

sbt-jacoco's Introduction

sbt-jacoco - Code Coverage via JaCoCo in sbt

Build Status Release Status SBT 1.0 version

This is an sbt plugin for code coverage analysis via JaCoCo. Supports uploading results to Coveralls, Codecov and Codacy.

Install the plugin by adding the following to project/plugins.sbt:

addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "<version>")

And then execute the plugin with sbt jacoco. This will instrument and run the unit tests and output the coverage metrics:

[info] ------- Jacoco Coverage Report --------
[info]
[info] Lines: 66.67% (>= required 0.0%) covered, 2 of 6 missed, OK
[info] Instructions: 83.54% (>= required 0.0%) covered, 13 of 79 missed, OK
[info] Branches: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Methods: 57.14% (>= required 0.0%) covered, 3 of 7 missed, OK
[info] Complexity: 57.14% (>= required 0.0%) covered, 3 of 7 missed, OK
[info] Class: 50% (>= required 0.0%) covered, 2 of 4 missed, OK
[info]
[info] Check /home/example/jacoco-test/target/scala-2.11/jacoco/report for detailed report

A detailed HTML report will also be generated in the directory shown that includes line level details of coverage.

See the docs for details on configuration options.

sbt-jacoco's People

Contributors

apismensky avatar asflierl avatar benmccann avatar dependabot[bot] avatar diversit avatar ducthienbui97 avatar eatkins avatar eed3si9n avatar emac avatar franciscodua avatar gzoller avatar iadcode avatar jaceklaskowski avatar jmhofer avatar kevin-lee avatar pjfanning avatar retronym avatar scala-steward avatar schleichardt avatar sethtisue avatar stringbean avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-jacoco's Issues

java.lang.OutOfMemoryError: unable to create new native thread when running large jacoco:test-only -- task on OSX 10.10 Yosemite

I have a fairly large project with lots of tests and on my computer only, running sbt "jacoco:test-only --" and Keys.fork in jacoco.Config := true, the task consistently dies at the same place, throwing java.lang.OutOfMemoryError: unable to create new native thread.

After much research, it looks like it may be due to the way the process allocates threads. Mac OSX seems to have a limit of 2048 taskthreads and cannot be changed, and this seems to be the limit that is being hit, but not completely sure.

Version 2.1.3 doesn't generate "classes" directory in "jacoco" output directory

I'm running 2.1.3 in a simple scala project, and the test coverage using jacoco:cover is always 0 in the report, regardless of what tests I have. Dropping the version back to 2.1.2 solves the problem.

With 2.1.2, my target/scala-2.10/jacoco directory contains the "html" and "classes" directories and the jacoco.exec file. With 2.1.3, the "classes" directory is not created - presumably that's the root of the issue.

I've created a toy project at https://github.com/paulmdavies/jacocoTest, which exhibits the issue. It's currently set to use version 2.1.2, and hence works correctly - but changing the version of jacoco4sbt to 2.1.3 in project/plugins.sbt will then exhibit the failure.

Not running @RunWith(MockitoJUnitRunner.class)?

I'm wondering if there's something I'm missing out on here...
I've a Mockito JUnit tests that just won't run under the jacoco4sbt managed tests?

Env:

  • Play 2.2.1
  • Java based app
  • jacoco4sbt 2.1.4

Test is using Mockito 1.9.5 annotations:

@RunWith(MockitoJUnitRunner.class)
public class FacadeTest {
  @Mock
  private Api api;
  @InjectMocks
  private Facade facade;

  @After
  public void after() {
    verifyNoMoreInteractions(api);
  }

  @Test
  public void facade() throws Exception {
  }
}

When running play test

[info] Total for test backend.FacadeTest
[info] Finished in 0.001 seconds
[info] 0 tests, 0 failures, 0 errors
[info] Test ApplicationTest ignored
[info] ApplicationTest
[info] o ApplicationTest
[info]
[info]
[info] Total for test ApplicationTest
[info] Finished in 0.001 seconds
[info] 1 tests, 0 failures, 0 errors
[error] Test backend.FacadeTest.handleConfirmationWhenIgnore failed: java.lang.NullPointerException: null
[error]     at ... backend.FacadeTest.facade(FacadeTest.java:57)
[error]     ...
[info] backend.FacadeTest
[info] x facade
[info]
[info] Total for test backend.FacadeTest
[info] Finished in 0.003 seconds
[info] 2 tests, 1 failures, 0 errors
[error] Failed: Total 45, Failed 1, Errors 0, Passed 42, Skipped 2

When running play jacoco:test

[info] Total for test backend.FacadeTest
[info] Finished in 0.006 seconds
[info] 0 tests, 0 failures, 0 errors
[info] ApplicationTest
[info] Test ApplicationTest ignored
[info] o ApplicationTest
[info]
[info]
[info] Total for test ApplicationTest
[info] Finished in 0.011 seconds
[info] 1 tests, 0 failures, 0 errors
[info] Passed: Total 43, Failed 0, Errors 0, Passed 41, Skipped 2
[success] Total time: 11 s, completed 27.feb.2014 10:00:17

The qa.jacoco.sbt is:

import de.johoop.jacoco4sbt._
import JacocoPlugin._

//----------------------------------------
// Setup Jacoco test coverage.
// Invocation: jacoco:cover
// Results: target/jacoco/html/index.html
// See: https://github.com/sbt/jacoco4sbt
//      project/plugins.sbt
//----------------------------------------

jacoco.settings

parallelExecution      in jacoco.Config := false

jacoco.outputDirectory in jacoco.Config := file("target/jacoco")

jacoco.reportFormats   in jacoco.Config := Seq(XMLReport("utf-8"), HTMLReport("utf-8"))

jacoco.excludes        in jacoco.Config := Seq("views*", "*Routes*", "controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controller*ref*")

Thanks.

Unable to run code coverage using sbt4jacoco

I was following jacoco4sbt wiki to run Junit test cases of my existing project using jacoco. I am getting following exception while running below command.

$ activator jacoco:cover
[info] Loading project definition from /data/test/project
[info] Set current project to test (in build file:/data/test/)
java.io.IOException: Error while instrumenting class Routes$$anonfun$routes$1.class.
    at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:152)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:124)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: play.api.mvc.Handler
    at org.objectweb.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1684)
    at org.objectweb.asm.ClassWriter.getMergedType(ClassWriter.java:1654)
    at org.objectweb.asm.Frame.merge(Frame.java:1426)
    at org.objectweb.asm.Frame.merge(Frame.java:1325)
    at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
    at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1554)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1017)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:693)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
    at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:995)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:84)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:122)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
[error] (jacoco:fullClasspath) java.io.IOException: Error while instrumenting class Routes$$anonfun$routes$1.class.
[error] Total time: 5 s, completed Feb 5, 2015 10:36:58 PM

Please see my build.sbt below

name := "test"

version := "1.0-SNAPSHOT"

playJavaSettings

ebeanEnabled := false

jacoco.settings

playJavaSettings ++ QueryDSLPlugin.queryDSLSettings

val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)

libraryDependencies ++= Seq(
    javaCore,
    cache,
    javaJpa,
    javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
    "org.apache.axis" % "axis" % "1.4",
    "org.apache.axis" % "axis-jaxrpc" % "1.4",
    "commons-discovery" % "commons-discovery" % "0.5",
    "wsdl4j" % "wsdl4j" % "1.6.2",
    "org.springframework" % "spring-context" % "4.1.0.RELEASE",
    "javax.inject" % "javax.inject" % "1",
    "org.springframework.data" % "spring-data-jpa" % "1.7.0.RELEASE",
    "org.springframework" % "spring-expression" % "4.1.0.RELEASE",
    "org.hibernate" % "hibernate-entitymanager" % "4.3.7.Final",
    "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Final",
    "org.apache.httpcomponents" % "httpclient" % "4.3.5",
    "org.json" % "json" % "20090211",
    "org.jasypt" % "jasypt" % "1.9.0",
    "org.mockito" % "mockito-core" % "1.9.5" % "test",
    "com.github.jknack" % "handlebars" % "1.3.2",
    "org.springframework" % "spring-context-support" % "3.2.2.RELEASE",
    "javax.mail" % "mail" % "1.5.0-b01",
    "com.typesafe.akka" % "akka-kernel_2.10" % "2.1.0",
    "org.quartz-scheduler" % "quartz" % "2.2.1",
    "org.quartz-scheduler" % "quartz-jobs" % "2.2.1",
    "com.datastax.cassandra" % "cassandra-driver-core" % "2.1.1",
    "com.datastax.cassandra" % "cassandra-driver-mapping" % "2.1.1",
    "junit" % "junit" % "4.11",
    "com.amazonaws" % "aws-java-sdk" % "1.9.6",
    "com.twilio.sdk" % "twilio-java-sdk" % "3.4.5",
    "com.atlassian.jira" % "jira-rest-java-client-core" % "2.0.0-m25",
    "com.atlassian.jira" % "jira-rest-java-client-api" % "2.0.0-m25",
    "commons-io" % "commons-io" % "2.2",
    "org.apache.commons" % "commons-csv" % "1.0",
    "com.jcraft" % "jsch" % "0.1.50",
    "net.sf.opencsv" % "opencsv" % "2.3",
    "com.google.guava" % "guava" % "18.0"
    )

and /project/plugins.sbt

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

addSbtPlugin("com.code-troopers.play" % "play-querydsl" % "0.1.1")

addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")

I am able see available plugins using following command

$ activator about
[info] Loading project definition from /data/test/project
[info] Set current project to test (in build file:/data/test/)
[info] This is sbt 0.13.0
[info] The current project is {file:/data/test/}current 1.0-SNAPSHOT
[info] The current project is built against Scala 2.10.2
[info] Available Plugins: play.Project, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtNativePackager, QueryDSLPlugin, de.johoop.jacoco4sbt.JacocoPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.

Also, I am able to run the test cases using below command.

$ activator test

itJacoco.settings undefined settings

adding itJacoco.settings to my build.sbt files results in the following error.
jacoco.settings works without problems.

[debug] Running task... Cancelable: false, check cycles: false
[debug]
[debug] Initial source changes:
[debug]     removed:Set()
[debug]     added: Set()
[debug]     modified: Set()
[debug] Removed products: Set()
[debug] Modified external sources: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated sources: Set()
[debug]
[debug] Sources indirectly invalidated by:
[debug]     product: Set()
[debug]     binary dep: Set()
[debug]     external source: Set()
[debug] All initially invalidated sources: Set()
[debug] Copy resource mappings:
[debug]
References to undefined settings:

  *:report from *:report
     Did you mean it-jacoco:report ?

  *:outputDirectory from *:report
     Did you mean jacoco:outputDirectory ?

  *:outputDirectory from *:merge
     Did you mean jacoco:outputDirectory ?

    at sbt.Init$class.Uninitialized(Settings.scala:233)
    at sbt.Def$.Uninitialized(Def.scala:9)
    at sbt.Init$class.delegate(Settings.scala:174)
    at sbt.Def$.delegate(Def.scala:9)
    at sbt.Init$class.compiled(Settings.scala:124)
    at sbt.Def$.compiled(Def.scala:9)
    at sbt.Init$class.make(Settings.scala:130)
    at sbt.Def$.make(Def.scala:9)
    at sbt.Load$.apply(Load.scala:141)
    at sbt.Load$.defaultLoad(Load.scala:40)
    at sbt.BuiltinCommands$.doLoadProject(Main.scala:434)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:428)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:428)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:60)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:60)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:62)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:62)
    at sbt.Command$.process(Command.scala:95)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:87)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:87)
    at sbt.State$$anon$1.process(State.scala:176)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:87)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:87)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.MainLoop$.next(MainLoop.scala:87)
    at sbt.MainLoop$.run(MainLoop.scala:80)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:69)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:66)
    at sbt.Using.apply(Using.scala:25)
    at sbt.MainLoop$.runWithNewLog(MainLoop.scala:66)
    at sbt.MainLoop$.runAndClearLast(MainLoop.scala:49)
    at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:33)
    at sbt.MainLoop$.runLogged(MainLoop.scala:25)
    at sbt.xMain.run(Main.scala:26)
    at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:57)
    at xsbt.boot.Launch$.withContextLoader(Launch.scala:77)
    at xsbt.boot.Launch$.run(Launch.scala:57)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
    at xsbt.boot.Launch$.launch(Launch.scala:65)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Boot$.runImpl(Boot.scala:32)
    at xsbt.boot.Boot$.main(Boot.scala:21)
    at xsbt.boot.Boot.main(Boot.scala)
[error] References to undefined settings:
[error]
[error]   *:report from *:report
[error]      Did you mean it-jacoco:report ?
[error]
[error]   *:outputDirectory from *:report
[error]      Did you mean jacoco:outputDirectory ?
[error]
[error]   *:outputDirectory from *:merge
[error]      Did you mean jacoco:outputDirectory ?
[error]
[error] Use 'last' for the full log.

Treat main project and sub projects as one single project

I did this customization in my fork. Don't know whether it's a valid use case for other users.

For my case, I've been working on a project base on Play! Framework 2.2.x, it has modules, but all tests are in the main project. I don't think it's best practice, but we have to live with that for the time being.

The customization I made is in a hack style which breaks the way it works before. Better abstraction will be needed for publish.

how to add javaOptions to the test task?

I tried

javaOptions in jacoco.Config ++= Seq("-Dlogback.configurationFile=logback-unit-tests.xml")

but my settings are ignored. Actually, I would like to inherit my javaOptions in Test automatically if possible as I have a bunch of other stuff there.

Please deploy 2.1.7

I see there is support for aggregated builds, which I could really use right now. Can we make a deploy sometime soon?

Jacoco running tests in parallel

Hi,

Jacoco is an amazing tool, it wasn't too difficult to get it running. However, we are still strugling with parallel execution. When I use:
sbt test

All runs sequential, but jacoco:check executes tests in parallel.

By in parallel, I mean multiple branches under the same spec2 scala file execute together. Otherwise different spec2 scala files are executing in sequence.

class Test extends Specification {
    "User" should {
        "test case 1" in {
          //Test case 1
                }
        "test case 2" in {
          //Test case 2
                }
        }
}

In the above example, the 2 test cases execute together when used with jacoco.

My configs:

build.sbt:

...
jacoco.settings

qa.jacoco.sbt:

import de.johoop.jacoco4sbt._

import JacocoPlugin._

import scala.util.Try

jacoco.settings

val artifactsDir = Try(scala.sys.env("CIRCLE_ARTIFACTS")).getOrElse("target")

parallelExecution      in jacoco.Config := false

jacoco.outputDirectory in jacoco.Config := file(artifactsDir + "/jacoco")

jacoco.reportFormats   in jacoco.Config := Seq(HTMLReport("utf-8"))

jacoco.excludes        in jacoco.Config := Seq("views*", "*Routes*", "controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controller*ref*")

jacoco.sourceTabWidth  in jacoco.Config := 4

project/plugin.sbt:

// Comment to get more information during initialization
//logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.4")

// BuildInfo available in java
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.4")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-stylus" % "1.0.1")

addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")

SBT 0.12.4 Supported?

I'm still using SBT 0.12.4 and curious to know if it is still supported? Here is I see after adding addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.4")

[info] Resolving de.johoop#jacoco4sbt;2.1.4 ...
[warn] module not found: de.johoop#jacoco4sbt;2.1.4
[warn] ==== typesafe-ivy-releases: tried
[warn] http://repo.typesafe.com/typesafe/ivy-releases/de.johoop/jacoco4sbt/scala_2.9.2/sbt_0.12/2.1.4/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn] http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/de.johoop/jacoco4sbt/scala_2.9.2/sbt_0.12/2.1.4/ivys/ivy.xml
[warn] ==== local: tried
[warn] /Volumes/MacintoshHD/Users/gagnechris/.ivy2/local/de.johoop/jacoco4sbt/scala_2.9.2/sbt_0.12/2.1.4/ivys/ivy.xml
[warn] ==== getty-releases: tried
[warn] http://sea-ops-artifacts-01.amer.gettywan.com:8081/nexus/content/repositories/releases/de/johoop/jacoco4sbt_2.9.2_0.12/2.1.4/jacoco4sbt-2.1.4.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/de/johoop/jacoco4sbt_2.9.2_0.12/2.1.4/jacoco4sbt-2.1.4.pom
[info] Resolving com.escalatesoft.subcut#subcut_2.9.2;2.0 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: de.johoop#jacoco4sbt;2.1.4: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] de.johoop:jacoco4sbt:2.1.4 (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: de.johoop#jacoco4sbt;2.1.4: not found

working with sbt-aspectj

Hi,

I'm using sbt-aspectj plugin to do runtime weaving for my code.

The config for aspectj plugin is something like:

lazy val aspectJSettings = aspectjSettings ++ Seq(
aspectjVersion := Dependencies.aspectjVersion,
compileOnly in Aspectj := true,
fork in Test := true,
javaOptions in Test <++= weaverOptions in Aspectj,
javaOptions in run <++= weaverOptions in Aspectj,
lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore"
)

I believe it will finally add "-javaagent:aspectjweaver-1.x.x.jar" to the java command.

It works well when I do sbt test

However, when I try to do jacoco:cover

The test case failed due to the aspectj not working.

I'm wondering whether jacoco's instrument has some conflict with apsectj's?

btw, I use addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.4") and aspectj weaver 1.7.4

Thanks

Leon

ClassCast on sbt publish

When I run sbt clean jacoco:cover publish I always end up with:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at org.apache.ivy.core.settings.IvySettings.addAllVariables(IvySettings.java:589)
    at org.apache.ivy.core.settings.IvySettings.addAllVariables(IvySettings.java:583)
    at org.apache.ivy.core.settings.IvySettings.addSystemProperties(IvySettings.java:303)
    at org.apache.ivy.core.settings.IvySettings.<init>(IvySettings.java:298)
    at org.apache.ivy.core.settings.IvySettings.<init>(IvySettings.java:218)
    at sbt.IvySbt.sbt$IvySbt$$settings$lzycompute(Ivy.scala:66)
    at sbt.IvySbt.sbt$IvySbt$$settings(Ivy.scala:64)
    at sbt.IvySbt.ivyLockFile$lzycompute(Ivy.scala:92)
    at sbt.IvySbt.ivyLockFile(Ivy.scala:92)
    at sbt.IvySbt.withDefaultLogger(Ivy.scala:60)
    at sbt.IvySbt.withIvy(Ivy.scala:101)
    at sbt.IvySbt.withIvy(Ivy.scala:97)
    at sbt.IvySbt$Module.withModule(Ivy.scala:116)
    at sbt.IvyActions$.makePom(IvyActions.scala:68)
    at sbt.Classpaths$$anonfun$32.apply(Defaults.scala:946)
    at sbt.Classpaths$$anonfun$32.apply(Defaults.scala:946)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)

Just sbt clean publish works fine, just sbt clean jacoco:cover as well.

SBT 0.13.2 and 0.13.5, tried various things like setting publishMavenStyle to false.

Execute code coverage for single test / test suite

I have a Test Suite where I define all the tests I want to run.
This so I can start up a webserver on "@BeforeClass" and shut down at "@afterclass" so the server is running throughout execution of the whole test suite. That makes the test execution much quicker.

This is how I execute it:

$ activator "test-only suite.DigSuite"
or
$ sbt "test-only suite.DigSuite"

But if I run:

$ sbt jacoco:cover

It implicity executes

$ sbt test

I tried:

$ sbt "jacoco:test-only suite.DigSuite"
and
$ sbt "jacoco:testOnly suite.DigSuite"

But no luck, it still executes the "sbt test". Anyone who can point me in right direction?

In advance thanks

jacoco4sbt not working

I want to setup Jacoco4sbt for my scala project. I followed the setup instruction mentioned here https://github.com/sbt/jacoco4sbt.

when I ran "sbt jacoco:cover" it throws the following error

build.sbt:8: error: not found: value jacoco

jacoco.settings

^

[error] Type error in expression

Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

My sbt version = 0.13
scala version = 2.10.4

include coverage of sub-project in parent reports

Say we have project A which depends on B. There are tests in A but not in B.
When running jacoco:cover on A, the report only contains classes that are directly in A.
Is it possible to also include the coverage of classes in B?

coveralls support

have you considered coveralls support? It would be great to be able to publish coverage results in their format as it integrates well with CI like travis.

Create junitxml report

Currently i run my tests with "test-only -- junitxml console" to create junitxml report files for my tests which (used on ci-server).

With the jacoco plugin this is not possible. Is there a way to use jacoco while creating the junitxml files without running the tests twice?

Getting error when following wiki installation instructions

Hello,

I get the error below when following the wiki instructions. I have added the dependency line to my ./project/plugins.sbt file.

Loading /usr/local/bin/sbt_0.13.0/bin/sbt-launch-lib.bash
/Users/greg.zoller/git/shock/project/jacoco4.sbt:1: error: not found: object de
import de.johoop.jacoco4sbt._
^
/Users/greg.zoller/git/shock/project/jacoco4.sbt:5: error: not found: value jacoco
jacoco.settings
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

IncompatibleClassChangeError

Greetings,

I had jacoco4sbt working fine with Play 2.1, but now with Play 2.2.0 and Scala 2.10.2, I am getting the following error:

[play-example-quality-assurance] $ jacoco:cover
[trace] Stack trace suppressed: run last jacoco:fullClasspath for the full output.
error java.lang.IncompatibleClassChangeError: class org.jacoco.core.internal.flow.ClassProbesVisitor has interface org.objectweb.asm.ClassVisitor as super class
[error] Total time: 9 s, completed Dec 4, 2013 1:42:45 PM

I saw a previous posting about this that suggested downgrading to 1.2.4, but when I try that there is a compatibility problem with Scala which prevents this from succeeding.

The project exhibiting this problem is at:

https://github.com/ics-software-engineering/play-example-quality-assurance

The relevant files are (probably):
https://github.com/ics-software-engineering/play-example-quality-assurance/blob/master/project/build.properties

https://github.com/ics-software-engineering/play-example-quality-assurance/blob/master/project/plugins.sbt

https://github.com/ics-software-engineering/play-example-quality-assurance/blob/master/qa.sbt

Thanks for any help you can provide.

Philip

Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter

Hi,

I’m having trouble running jacoco in my project. Here is the trace from last myProject/jacoco:fullClasspath:

java.lang.NoClassDefFoundError: Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:81)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:122)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

The project aggregates several subprojects, and I get this same error whether the settings are applied to it or just to a single subproject. The settings revelant for tests look like this:

val testSettings = Seq(Test, jacoco.Config).flatMap { conf =>
  Seq(
    parallelExecution in conf := false,
    fork in conf := true,
    javaOptions in conf += "-Xmx2g",
    javaOptions in conf += "-javaagent:" + (dependencyClasspath in Test).value
      .files.find(_.name.endsWith(s"jmockit-${Versions.JMockit}.jar")).get,
    testOptions in conf += Tests.Argument(
      TestFrameworks.JUnit, "--ignore-runners=org.scalatest.junit.JUnitRunner"
    )
  )
} ++ jacoco.settings ++ Seq(
  ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := false,

  libraryDependencies ++= Seq(
    "org.scalatest" %% "scalatest" % "1.9.2" % "test",
    "de.bwaldvogel" % "mongo-java-server" % "1.2.0" % "test",
    "org.jmockit" % "jmockit" % Versions.JMockit % "test",
    "com.novocode" % "junit-interface" % "0.11" % "test",
    "junit" % "junit" % "4.11" % "test"
  )
)

No tests to run for jacoco:test

When I run jacoco:cover with play 2.2.3 , the result is as following.
[info] Resolving org.jacoco#org.jacoco.agent;0.7.0.201403182114 ...
[info] Done updating.
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for jacoco:test
[info]
[info] ------- Jacoco Coverage Report --------
[info]
[info] Lines: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Instructions: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Branches: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Methods: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Complexity: 0% (>= required 0.0%) covered, 0 of 0 missed, OK
[info] Class: 0% (>= required 0.0%) covered, 0 of 0 missed, OK

config files:

  1. in plugins.sbt
    addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")

libraryDependencies ++= Seq(
"org.jacoco" % "org.jacoco.core" % "0.7.1.201405082137" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
"org.jacoco" % "org.jacoco.report" % "0.7.1.201405082137" artifacts(Artifact("org.jacoco.report", "jar", "jar")))

  1. in Build.scala
    lazy val s = Defaults.defaultSettings ++ Seq(jacoco.settings:_*)
    val main = play.Project(appName, appVersion, appDependencies, settings = s).settings(
    // jacoco.settings
    parallelExecution in jacoco.Config := false,
    jacoco.reportFormats in jacoco.Config := Seq(HTMLReport("utf-8")),
    Keys.fork in jacoco.Config := false
    )

Play directory tree is like
app → Application sources
└ assets → Compiled asset sources
└ stylesheets → Typically LESS CSS sources
└ javascripts → Typically CoffeeScript sources
└ controllers → Application controllers
└ models → Application business layer
└ views → Templates
build.sbt → Application build script
conf → Configurations files and other non-compiled resources (on classpath)
└ application.conf → Main configuration file
└ routes → Routes definition
public → Public assets
└ stylesheets → CSS files
└ javascripts → Javascript files
└ images → Image files
project → sbt configuration files
└ build.properties → Marker for sbt project
└ plugins.sbt → sbt plugins including the declaration for Play itself
lib → Unmanaged libraries dependencies
logs → Standard logs folder
└ application.log → Default log file
test → source folder for unit or functional tests

sbt.version=0.13.0

Why it can't find test classes?

ClassCastException when using forked mode tests

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

Jacoco doesnot generate a coverage report

Hi all,
If you have a set of tests and at least one test is failing, no coverage report is generated. I think it would be nice if the coverage report would be also generated in this situation. The coverage date seems to be generated anyways

Greetings

Gerald

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

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]  

jacoco:check it-jacoco:cover + threshold values

I am not able to set threshold values that kick in for it-jacoco:cover. I can set thresholds for jacoco:cover, and i have tried the snapshot 2.1.7 and using aggregateThreshold on both jacoco and it-jacoco to no avail.

Any help on this?

Branch coverage for a simple case class is very low

package cpf.branch.coverage

trait Result

case class OKResult[A](a: A) extends Result

case class FailureResult(msg: String) extends Result

the code is like the above.
when I run jacoco:cover, the result says:
all 16 branches missed
for the FailureResult case class.

and the pattern match code that uses the case class is like this:

    ...... match {
      case OKResult(result) => result.toString
      case FailureResult(error) => error
    }

and the results says that 1 of 2 branches missed for the second case.

is this because scala compiler generates extra code that has more branches than I intended in the scala code? and how to work around this to make my branch coverage look normal?

the code above is here: https://github.com/cuipengfei/reproduce-weird-issues/tree/master/scala-jacoco-branch-coverage

Add travis build/continuous integration job

It would be nice to have a badge "build passing" for this project to see that it is tested and stable.

For my projects I use travis, it is free for open source projects and easy to setup.

The cool thing is, it executes also tests for pull requests and shows the results in GitHub.

[error] (jacoco:test) Expected dependency to fail.

info] Passed: Total 3, Failed 0, Errors 0, Passed 3
error Expected dependency to fail.
[error] Total time: 6 s, completed Feb 14, 2016 4:32:17 AM

Not sure why do I get this while running the tests with Jacoco:cover

java.lang.ExceptionInInitializerError on running jacoco:test

On jacoco4sbt 2.1.5.

java.lang.ExceptionInInitializerError
    at org.jacoco.core.instr.Instrumenter.createInstrumentingVisitor(Instrumenter.java:79)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:93)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:134)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.IllegalArgumentException
    at org.objectweb.asm.MethodVisitor.<init>(Unknown Source)
    at org.jacoco.core.internal.flow.MethodProbesVisitor.<init>(MethodProbesVisitor.java:38)
    at org.jacoco.core.internal.flow.MethodProbesVisitor.<init>(MethodProbesVisitor.java:28)
    at org.jacoco.core.internal.flow.ClassProbesAdapter$1Impl.<init>(ClassProbesAdapter.java:31)
    at org.jacoco.core.internal.flow.ClassProbesAdapter.<clinit>(ClassProbesAdapter.java:62)
    at org.jacoco.core.instr.Instrumenter.createInstrumentingVisitor(Instrumenter.java:79)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:93)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:134)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Make plugin work with forked tests

As sbt has been supporting forked tests for quite a while now, jacoco4sbt should too.

There's two possibilities to implement this: Either use the JaCoCo Java agent for everything except merging and reporting, or pre-instrument and adapt the classpath (as done currently).

Handling forked tests should actually be easier than handling non-forked tests afaik...

sbt 0.13.0 -> 0.13.2

I'm trying to migrate the project (Play2) from sbt 0.13.0 to 0.13.2. With new sbt version I have an issue when I run
sbt clean jacoco:cover
I have a bunch of exceptions that look like
java.lang.ClassCastException: java.lang.Long cannot be cast to [Z
[info] at {MY_CLASS}.$jacocoInit({MY_CLASS})
for different classes in my project.
The exception looks similar to https://github.com//issues/6, where it was related to fork parameter in the config.
I tried to add
Keys.fork in jacoco.Config := false
to build.sbt but it did not help.
Any advise how to make it compatible with sbt 0.13.2?

BTW: Thanks for code review and merging my changes! :-)

jacoco4sbt unable to perform code coverage with play 2.3.1

Hi,

I am using jacoco4sbt to perform code coverage for an application deployed in play 2.3.1 (activator based).

When I run 'activator jacoco:cover' command, it gives me the following output.

[info] Lines: 0% (>= required 0.0%) covered, 1148 of 1148 missed, OK
[info] Instructions: 0% (>= required 0.0%) covered, 6535 of 6535 missed, OK
[info] Branches: 0% (>= required 0.0%) covered, 478 of 478 missed, OK
[info] Methods: 0% (>= required 0.0%) covered, 264 of 264 missed, OK
[info] Complexity: 0% (>= required 0.0%) covered, 503 of 503 missed, OK
[info] Class: 0% (>= required 0.0%) covered, 81 of 81 missed, OK
[info] Check /home/gdev/fase/v2.0/fase/platform/service-components/Job/eqx-fase-product-dist-job/target/scala-2.11/jacoco for detail report

Why is it failing to do code coverage ?

Thanks,
Rohit

Conditional Merge of integration test set to false does not appear to be working

I'm having problems getting conditional merge on the intergration tests set to false - I would like to maintain two separate reports.

Our build.sbt looks something like this (a few app specifics removed):

import play.PlayImport._
import play.PlayScala
import de.johoop.jacoco4sbt._
import JacocoPlugin._


name := "my-awesome-app"

scalaVersion := "2.11.2"

unmanagedSourceDirectories in IntegrationTest <<= (baseDirectory in IntegrationTest)(base =>  Seq(base / "test-integration"))

lazy val root = (project in file(".")).enablePlugins(PlayScala).configs(IntegrationTest).settings(
  Defaults.itSettings : _*
)

resolvers ++= Seq(
  "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/"
)

//----------------------------------------
// Setup Jacoco test coverage.
// Invocation: jacoco:cover
// Results: target/jacoco/html/index.html
// See: https://github.com/sbt/jacoco4sbt
//      project/plugins.sbt
//----------------------------------------
jacoco.settings

parallelExecution      in jacoco.Config := false

jacoco.outputDirectory in jacoco.Config := file("target/jacoco")

jacoco.reportFormats   in jacoco.Config := Seq(XMLReport("utf-8"), ScalaHTMLReport(withBranchCoverage = true))

jacoco.includes        in jacoco.Config := Seq("*controllers*", "*actors*", "*helpers*", "*model*")

jacoco.excludes        in jacoco.Config := Seq("controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controllers*ref*")

//
// Integration tests once
//

itJacoco.settings

parallelExecution        in itJacoco.Config := false

itJacoco.mergeReports    in itJacoco.Config := false

itJacoco.outputDirectory in itJacoco.Config := file("target/it-jacoco")

itJacoco.reportFormats   in itJacoco.Config := Seq(XMLReport("utf-8"), ScalaHTMLReport(withBranchCoverage = true))

itJacoco.includes        in itJacoco.Config := Seq("*controllers*", "*actors*", "*helpers*", "*model*")

itJacoco.excludes        in itJacoco.Config := Seq("controllers*routes*", "controllers*Reverse*", "controllers*javascript*", "controllers*ref*")

Note that I have the mergeReports of the itJacoco configuration turned off.

However, when I run a command such as this:
sbt clean-files clean compile jacoco:cover it-jacoco:cover
all the tests run, but in my output directory of the target/it-jacoco folder I have a jacoco.exec and a jacoco-merged.exec, and the report html files that are built are built from the merged results.

I am using:

  • sbt 0.13.6
  • jacoco4sbt 2.1.6
  • core jacoco of 0.7.1.201405082137

Give own application.conf file when running test coverage

Hi,

How can I give my one own application.conf file instead of default when run the coverage? I have configuration files based on different environment like (local, qa, prod). It contains properties like db connections detail and others. When I start server normally I use this

activator "run -Dhttp.port=9001 -Dconfig.file=conf/application-local.conf"

Regards
Adnan Ahmed

Respect jacoco.excludes in the instrumentation process

Currently as for the version 2.1.6 of jacoco4sbt, jacoco.excludes is not respected during the instrumentation process.

Although I don't see any need to make the change form jacoco4sbt perspective, it would be helpful to make jacoco.excludes respected during the instrumentation process in order to make it possible for jacoco4sbt users to apply the easy workaround of jacoco/jacoco#177 via jacoco.excludes.

jacoco:test runs in root working directory for sub projects instead of the current sub project's directory

I am using Play 2.2.1 and jacoco4sbt 2.1.2

Short version:

play test execute common subproject tests' FakeApplication() in the sub project's directory. play jacoco:test executes this FakeApplication() in the root directory.

Long version:

I am trying to read the root's configuration file in my common subproject FakeApplication by running as:

app  = FakeApplication(new File("./../../", ...)

This accesses the app.conf fine with play test. But with jacoco:test I get the following error:

Error while writing configuration file /path/to/root/./../../conf/app.conf
org.apache.commons.configuration.ConfigurationException: No file name has been set!

If I change my FakeApplication to

app = FakeApplication(new File("."), ...)

jacoco:test works, but play test fails with:

Error while writing configuration file /path/to/root/modules/common/./conf/app.conf for property...
org.apache.commons.configuration.ConfigurationException: No file name has been set!

Note the difference between
jacoco:test: /path/to/root/./../../conf/app.conf
and
play test: /path/to/root/modules/common/./conf/app.conf

I have a multi project setup that looks like this:

root
- app
- conf
- project 
   - Build.scala
   - plugins.sbt
- modules
   - api
   - common
      - app
      - test
      - conf
   - etc...

My Build.scala looks like:

  // So we can get code coverage
  lazy val jacocoSettings = Seq(
      parallelExecution in jacoco.Config := false,
      jacoco.excludes in jacoco.Config := Seq("Routes*","*Reverse*","*anonfun*"),
      resolvers += "julienrf.github.com" at "http://julienrf.github.com/repo/"
    )

  // Every module needs to have jacoco (for coverage)
  lazy val s = playJavaSettings ++ Seq(jacoco.settings:_*) ++ jacocoSettings

  lazy val common = play.Project(
      "common", appVersion, commonDependencies, settings = s, path = file("modules/common")
    ).dependsOn(api)

I've tried setting the baseDirectory in jacoco.Config to the sub project path, but that doesn't work either.

I would expect that jacoco:test executes the sub project tests in the sub project's working directory.

This was working with Play 2.1.3 and jacoco.

Test resources are not found

In my java (with play 2.2.0) project I tried to jacoco4sbt 2.1.2.
There are tests which needs some resources obtained in such way:

 SomeTest.class.getResource("").getPath();

It works properly with play test, but fails with play jacoco:coverage. In the second case path points to target/scala-2.10/jacoco/classes instead of target/scala-2.10/test-classes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.