How to chain SBT task with multi module project - scala

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.

Related

Maven test coverage for scala

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.

SBT - why sbt giving compilation errors while running?

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.

Sonar / JaCoCo4sbt / Jenkins

I would like to know whats the easiest way to plug JaCoCo4sbt's data into Sonar,
In Jenkins I have installed Sonar & JaCoCo's plugins. I have also installed JaCoCo's plugin in Sonar.
My sonar-project.properties file contains :
sonar.jacoco.reportPath=target/jacoco/jacoco.exec
And Jenkins's job execute these commands :
sbt jacoco:cover
/opt/sonar-runner/bin/sonar-runner
SBT_OPTS="-Dsbt.log.noformat=true"
sbt clean update compile test doc
For now I don't get any code coverage data into Sonar
Do you want to report code coverage on Scala code using the Scala plugin for Sonar (http://docs.codehaus.org/display/SONAR/Scala+Plugin)?
Unfortunately it does not yet provide a sensor for code coverage.
It's on the roadmap for future versions.
At least jacoco4sbt successfully generates the file jacoco.exec but it is just not picket up by the Scala plugin.
You'll need the following properties:
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=${build.dir}/jacoco.exec
I don't use sbt, but the following is an ANT example:
Add ant plugins dynamically at buildtime?
Check the properties file at the end for all the Sonar related stuff.

How to compile tests with SBT without running them

Is there a way to build tests with SBT without running them?
My own use case is to run static analysis on the test code by using a scalac plugin. Another possible use case is to run some or all of the test code using a separate runner than the one built into SBT.
Ideally there would be a solution to this problem that applies to any SBT project. For example, Maven has a test-compile command that can be used just to compile the tests without running them. It would be great if SBT had the same thing.
Less ideal, but still very helpful, would be solutions that involve modifying the project's build files.
Just use the Test / compile command.
Test/compile works for compiling your unit tests.
To compile integration tests you can use IntegrationTest/compile.
Another hint to continuously compile on every file change: ~Test/compile
We have a build.sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.
I found out I can compile only the tests for a specific project named xyz by doing:
sbt xyz/test:compile
Using sbt version 1.5.0 and higher test:compile returns deprecation warning.
Use Test / compile.
(docs)

m2eclipse: Like "mvn test" but with GUI?

We have a multi-module Maven setup with a master pom.xml that includes all the others. So mvn test from the root directory runs all our unit tests, with textual output.
I can do Run / Run As / JUnit Test to run a single test class with a graphical test runner.
Question: How do I combine the two, so that I can run all the tests that mvn test runs but with a graphical runner, like the one from Run / Run As / JUnit Test?
Create an eclipse project with all your modules as Maven Dependecies and then create a JUnit Suite which incorporates all tests. Eclipse's JUnit Runner then will execute all declared Tests if you run this suite.
In Eclipse Juno, assuming your project is a Maven Project, you can just right click the project name in the Project Explorer and select Run As ... jUnit test. Alternatively you can produce the same text output you get from mvn test by selecting Run As ... Maven test