How to break the build if test coverage fails minimum threshold? - scala

We want to fail the build on codeship if test coverage goes below the threshold value. But it is not failing the build.
Scoverage Plugin:
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")
Added following two statements in build.sbt
coverageMinimum := 80,
coverageFailOnMinimum := true
It is not failing even in local if test coverage is below 80. The command I run is
sbt clean coverage test coverageReport

Try upgrading to version 1.5.1 like so
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")

Related

Run scoverage from intellij

I was wondering, is it possible to run scoverage from intellij (not from the terminal ) and even better, see scoverage reports like the native coverage from intellij?
Thanks
I've managed to collect coverage by adding scalac-scoverage-plugin as a test dependency:
libraryDependencies += "org.scoverage" %% "scalac-scoverage-plugin" % "1.4.0" % Test

Issues with using Scoverage: Scala Sbt

I added the scoverage plugin to projects/plugins.sbt
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")
I was able to generate test coverage using
sbt clean coverage test
sbt coveragereport
However when I try to add socverage config to my build.sbt. I see build errors
error: value ScoverageKeys is not a member of object scoverage.ScoverageSbtPlugin
ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 70
Looks like build.sbt does not find Scoverage classes. What is going on here?
check that out. Seems like what you need is:
scoverage.ScoverageKeys.coverageMinimum := 70

Using ScalaTest with SBT android-sdk-plugin

I'm trying to use SBT with android-sdk-plugin and ScalaTest, but have no success.
I could run test command in SBT console, but it didn't find any ScalaTest test suite in my src/test/scala folder.
I got the following output from SBT, which seems didn't run any ScalaTest test suite at all.
[info] Compiling 2 Scala sources and 3 Java sources to /home/brianhsu/AndroidProject/FindLost/target/android-bin/classes...
[info] Packaging /home/brianhsu/AndroidProject/FindLost/target/android-bin/classes.jar ...
[info] Done packaging.
[info] Packaging /home/brianhsu/AndroidProject/FindLost/target/scala-2.10/findlost_2.10-0.1-SNAPSHOT-tests.jar ...
[info] Done packaging.
[info] Run completed in 44 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] No tests to run for test:test
The following is how I create the project:
Using android create project -g to create an Android project with gradle layout.
Add addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.2.11") to project/plugins.sbt to include android-sdk-plugin to my project.
Add ScalaTest to my libraryDependencies setting in build.sbt, which makes the build file looks like the following:
import android.Keys._
android.Plugin.androidBuild
name := "FindLost"
scalaVersion := "2.10.4"
organization := "org.bone.findlost"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
platformTarget in Android := "android-19"
run <<= run in Android
install <<= install in Android
Add a ScalaTest test case to src/test/scala, which contains example test suite from QuickStart page of ScalaTest.
Place your tests in src/androidTest/scala
The android-sdk-plugin uses androidTest for both Android instrumentation tests as well as regular tests.
See Ordinary scalatests not found from src/test #45 for a discussion on this topic. Note, that since that discussion the plugin changed directory has changed to the path I listed.

How do I declare SBT dependencies withSources that have test scope in published pom file?

When attempting to publish:
https://github.com/thetrav/http-stub-server-scala/blob/master/project/build.scala
The test framework dependencies are leaking into the runtime dependencies.
I've narrowed it down to the line:
"org.scalatest" %% "scalatest" % "2.0.M5b" % "test" withSources(),
The problem appears to be withSources() which does not get published with the test scope
Is there a way for me to get the sources in test and dev, but not in the runtime?
withSources is not recommended in sbt 0.10+. The IDE plugins use updateClassifiers, for example, and this can be used by other tasks/plugins that do similar things.

How do I resolve my own test artifacts in SBT?

One of my projects will provide a jar package supposed to be used for unit testing in several other projects. So far I managed to make sbt produce a objects-commons_2.10-0.1-SNAPSHOT-test.jar and have it published in my repository.
However, I can't find a way to tell sbt to use that artifact with the testing scope in other projects.
Adding the following dependencies in my build.scala will not get the test artifact loaded.
"com.company" %% "objects-commons" % "0.1-SNAPSHOT",
"com.company" %% "objects-commons" % "0.1-SNAPSHOT-test" % "test",
What I need is to use the default .jar file as compile and runtime dependency and the -test.jar as dependency in my test scope. But somehow sbt never tries to resolve the test jar.
How to use test artifacts
To enable publishing the test artifact when the main artifact is published you need to add to your build.sbt of the library:
publishArtifact in (Test, packageBin) := true
Publish your artifact. There should be at least two JARs: objects-commons_2.10.jar and objects-commons_2.10-test.jar.
To use the library at runtime and the test library at test scope add the following lines to build.sbt of the main application:
libraryDependencies ++= Seq("com.company" % "objects-commons_2.10" % "0.1-SNAPSHOT"
, "com.company" % "objects-commons_2.10" % "0.1-SNAPSHOT" % "test" classifier "tests" //for SBT 12: classifier test (not tests with s)
)
The first entry loads the the runtime libraries and the second entry forces that the "tests" artifact is only available in the test scope.
I created an example project:
git clone git#github.com:schleichardt/stackoverflow-answers.git --branch so15290881-how-do-i-resolve-my-own-test-artifacts-in-sbt
Or you can view the example directly in github.
Your problem is that sbt thinks that your two jars are the same artifact, but with different versions. It takes the "latest", which is 0.1-SNAPSHOT, and ignores the 0.1-SNAPSHOT-test. This is the same behaviour as you would see if, for instance you have 0.1-SNAPSHOT and 0.2-SNAPSHOT.
I don't know what is in these two jars, but if you want them both to be on the classpath, which is what you seem to want to do, then you'll need to change the name of the test artifact to objects-commons-test, as Kazuhiro suggested. It seems that this should be easy enough for you, since you're already putting it in the repo yourself.
It will work fine if you change the name like this.
"com.company" %% "objects-commons" % "0.1-SNAPSHOT",
"com.company" %% "objects-commons-test" % "0.1-SNAPSHOT" % "test",