Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute code coverage for single test / test suite #62

Open
tha022 opened this issue Feb 29, 2016 · 9 comments
Open

Execute code coverage for single test / test suite #62

tha022 opened this issue Feb 29, 2016 · 9 comments

Comments

@tha022
Copy link

tha022 commented Feb 29, 2016

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

@raam86
Copy link

raam86 commented Jun 21, 2016

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

@MSaifAsif
Copy link

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

@karthikkbaalaji
Copy link

+1

@maichler
Copy link

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.

@gmkumar2005
Copy link

gmkumar2005 commented Nov 27, 2017

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

@maichler
Copy link

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.

@gmkumar2005
Copy link

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

@pradeepreddyk
Copy link

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

@davidgfolch
Copy link

davidgfolch commented Feb 13, 2019

Same as @gmkumar2005 here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants