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

Execute code coverage for single test / test suite

Open tha022 opened this issue 8 years ago • 9 comments

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

tha022 avatar Feb 29 '16 18:02 tha022

Yes I am having the same issue, I do not want jacoco to run the tests only report on coverage.

raam86 avatar Jun 21 '16 13:06 raam86

Did anyone have any luck on how to achieve this so far?

MSaifAsif avatar Dec 22 '16 09:12 MSaifAsif

+1

karthikkbaalaji avatar Aug 30 '17 22:08 karthikkbaalaji

Since version 3.x sbt-jacoco seems to instrument code not only for task jacoco but also for test and testOnly. This allows to combine e.g. testOnly and jacocoReport to generate a coverage report.

$> clean
$> testOnly suite.DigSuite
$> jacocoReport

clean is necessary because coverage data gets merged instead of replaced. It would be enough to just delete target/jacoco/data/jacoco.exec before executing testOnly but there is no easy way from within the sbt console that I'm aware of.

That said, a jacocoOnly task would be much more convenient.

maichler avatar Nov 23 '17 14:11 maichler

Not working. I have done ;clean;testOnly **.MyFavouriteDaoTest;jacocoReport

The report shows 0% coverage. I have noticed After completion of testOnly

target/jacoco/data/jacoco.exec is not created.

When i run all test cases the results are proper. Any one got this working ?

Details : Plugin used : addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.0.3") Scala Version : scala-2.12 Junit : Version 4.1.2 Source Code : Java sbt.version=1.0.2

gmkumar2005 avatar Nov 27 '17 07:11 gmkumar2005

I've rechecked my project settings and noticed that I missed a detail:

fork in Test := true

With fork enabled, jacoco is able to load its agent via commandline arguments.

maichler avatar Nov 27 '17 08:11 maichler

Issue is resolved after I added fork in Test := true

gmkumar2005 avatar Nov 27 '17 14:11 gmkumar2005

fork in Test :=true would run all the tests in sequence. Is there any option to keep the parallel execution true.

pradeepreddyk avatar Aug 07 '18 13:08 pradeepreddyk

Same as @gmkumar2005 here

davidgfolch avatar Feb 13 '19 09:02 davidgfolch