I want to do test coverage on my Scala project, for which I use Maven as a build tool.
So I found this:
https://github.com/scoverage/scoverage-maven-plugin
And I looked here:
http://scoverage.github.io/scoverage-maven-plugin/1.3.0/check-mojo.html
So now to check test coverage, I run this:
mvn test
And then:
mvn scoverage:check
However, this only makes the tests to be run. I get no information about coverage.
Also, I tried:
mvn scoverage:report
But the result is the same.
So how can I use this tool or another to get test coverage info in a Scala/Maven project?
I have only used Scoverage with SBT, but chances are the usage is the same.
mvn scoverage:check will only generate some metadata - XML - and compare the generated coverage values against any coverage minimum you might have set up.
With mvn scoverage:report you will get some formatted reports. More docs here.
Related
I have configured one SBT multi-module project with scoverage plugin, which is working fine.
To generate test coverage, I am using > SBT clean coverage test coverageReport but is there any way to create a new task which chains internally coverage test coverageReport.
I have tried
Run custom task automatically before/after standard task to create a custom task, but it seems not working with multimodule project.
And one more - http://eed3si9n.com/sequencing-tasks-with-sbt-sequential
Try addCommandAlias like so
addCommandAlias("coverageAll", ";clean;coverage;test;coverageReport")
Now executing sbt coverageAll should generate coverage report for all the sub-projects.
It would be great if one can take advantage of sbt incremental compilation and avoid having to recompile the whole project every time you run your tests, which is exactly what happens when you do clean. The following sequence though:
sbt> coverage
sbt> test
sbt> coverageReport
doesn't re-generate the coverage report but this one does:
sbt> clean
sbt> coverage
sbt> test
sbt> coverageReport
e.g The following sequence will always generate the same coverage report (i.e. the report that was generated the first time around):
sbt> coverage
sbt> test
sbt> coverageReport
here I change one of my test files and again run:
sbt> coverage
sbt> test
sbt> coverageReport
I am going to copy comments posted on this question:
By Mateusz Kubuszok:
From my experience that is exactly the problem with scoverage - during coverage instrumentation it only notices parts of code affected in some way. If you clean it will measure coverage on whole code. If you repeat measurement after that, it will only measure on... I guess parts touched by incremental compilation.
By Grzegorz Slowikowski:
SBT compilation is incremental, Scoverage uses a sequence to identify statements it instruments. This sequence is not stored anywhere, it's being reset on every compilation. For incremental compilation different statements would reuse the same first sequence numbers (1, 2, 3, ...) and it would lead to inconsistent scoverage data. Maybe it would be possible to store and reuse the sequence in subsequent builds, but nobody tried it.
I am trying to merge two modules into single module. Both are successfully running modules. I merge two modules. And trying to run the test cases.
i am compiling source and testcases by using sbt commands:
sbt
clean
compile
project module-read
test:compile
it:test
Till test:compile everything working fine but after it:test, it showing lot of compilation issues.
Could I know best way of compiling?
The test:compile task will only compile tests within the src/test/scala folder as per the default sbt test configuration.
In order to compile your integration tests (in src/it/scala) you will have to run it:compile .
See http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Testing.html#integration-tests for more info.
I have not found any documentation on how to do this. For JUnit the equivalent would be:
mvn -Dtest=org.apache.spark.streaming.InputStreamSuite test
tl;dr mvn test -Dsuites="some.package.SpecsClass"
I found an answer from here and it works:(https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)
run test 'a pending test' in HelloSuite, and all tests in HelloWordSpec:
mvn test -Dsuites='org.example.
HelloSuite #a pending test, org.example.HelloWordSpec'
run all tests in HelloSuite containing 'hello':
mvn test -Dsuites='org.example.HelloSuite hello'
for more details: http://scalatest.org/user_guide/using_the_scalatest_maven_plugin
Found the answer: it is
-DwildcardSuites
So here is the example command line:
mvn -pl streaming -DwildcardSuites=org.apache.spark.streaming.InputStreamSuite test
Update Newer versions of scalatest use
-Dsuites
So the syntax would be:
mvn -pl streaming -Dsuites=org.apache.spark.streaming.InputStreamSuite test
Note that if you have some Java tests in the same module, as much of spark does, you need to turn them off -which you can do by telling surefire to run a test that isn't there
Here is the test that I've just been running
mvn test -Dtest=moo -DwildcardSuites=org.apache.spark.deploy.yarn.ClientSuite
That skips the java test and only runs the scala one.
One thing which scalatest doesn't seem to do is let you run a single test within a suite, the way maven surefire does. That's not ideal if you have one failing test in a big suite.
[Correction 2016-08-22: looks like you can ask for a specific suite by name; look at the other answers below. Happy to be wrong].
Hi I am using sonar and I love it...
But I have a somewhat strange behavior with my latest proj.
If I put all my tests in a JUnit 4 #TestSuite JaCoCo gives me a coverage of 86,2% ( Groove baby !!! ) when I run mvn sonar:sonar
If I let the tests by themselves I get 0% coverage even with the Unit test success
100,0%
I don't need a TestSuite for this proj any clue about why JaCoCo is doing this?
BTW: I am using Maven 2.2.1 + Sonar 3.4.1 + sonar-maven-plugin 1.0.
You do not need to define a test suite if your tests respect the "Test*.java" & "*Test.java" naming convention.
You can have a look at the following sample application for which tests are analysed by JaCoCo: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/maven/ut-maven-jacoco-runTests