sbt-jacoco
sbt-jacoco copied to clipboard
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
Yes I am having the same issue, I do not want jacoco to run the tests only report on coverage.
Did anyone have any luck on how to achieve this so far?
+1
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.
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
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.
Issue is resolved after I added fork in Test := true
fork in Test :=true would run all the tests in sequence. Is there any option to keep the parallel execution true.
Same as @gmkumar2005 here