jacoco4sbt is not "detecting" my tests. Any idea why? - scala

I have a typical sbt (0.13) build and have added the jacoco4sbt plugin to my build.
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.1")
I use specs2 to run my tests (2.2.2).
If I run
~>sbt
>test
all my tests get run (120 of them). However, if I do
>jacoco:test
it runs 0 tests, as if the jacoco configuration cannot find them.
A quick search reveals that there is an issue with jacoco4sbt and Play because Play sets parallelExecution to false. However, I am not using Play, and parallelExecution is set to True for both configurations. I have tried to set them both to false to no avail.
Any idea what might be going wrong?
n.b. The project I am working on is open source, so I created a branch where I put my attempt at adding jacoco4sbt. Feel free to clone it and see what is happening for yourself.
https://github.com/jedesah/scala-codesheet-api/tree/jacoco

I had this issue, but upgraded to Specs2 2.2.3 and jacoco4sbt started producing output from that point.

For what it's worth, I had the same problem when using specs2. When I switched to ScalaTest, jacoco4sbt started detecting my tests.
I have a very basic configuration too, so I don't know we're missing something or if there's something wrong in the current jacoco4sbt version. I did try version 2.1.0 of jacoco4sbt but had the same results.

Related

Running sbt with Wartremover

I'd like to check the code of my whole project with wartremover and sbt.
I've added addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.13" to plugins.sbt, but don't know what to do next.
I don't get any output from wartremover with sbt run and sbt compile.
Like said in the documentation, you will need to configure the linter:
wartremoverErrors ++= Warts.unsafe
With sbt >= 0.13.5 and the auto plugin feature, that's all. I get compilation errors with the examples as soon as I add the line above.

Why don't specs2 + scalamock tests run in IntelliJ? Multiple suite traits detected

I'm trying to run Specs2 tests from IDEA from both Windows and Mac versions of Intellij IDEA 14. I generated the idea project files using both gen-idea and the built in SBT plugin and get the same results...
When I try to run them, I get
Error running Specs2 in 'scala': Test class not found
I've added packages and switched "search for tests" to in single module but still no avail. I also get the message below on the run config.
Multiple suite traits detected: List(ScTrait: SpecificationStructure, ScTrait: SpecificationStructure,)
The similar post How to run all Specs2 tests under IntelliJ IDEA? doesn't help and it all runs fine from SBT, BTW. I can't run individual tests via the short-cut either :'(
I'm suspecting it's a combination of scalamock and specs2, as if I remove the following from my build.sbt, I can run them again.
"org.scalamock" %% "scalamock-specs2-support" % "3.2" % "test"
Here's the run config.
You should check if you have multiple specs2 jars dependencies in your module. If you just leave one jar dependency the configuration error should disappear.
To help other googlers, it could also be that you have one package depending on specs2-core, and scalamock-specs2-support which depends on specs2. The solution is to add an explicit dependency on specs2, and both dependencies should be evicted to the one you import. I was just able to fix this with the following dependency: "org.specs2" %% "specs2" % "3.7" % "test"

SBT Broken Pipe

I've been avoiding using SBT since the support in intellij for maven has always been far superior, plus I don't see much advantage in SBT; but I figure why fight the masses.
So one of my open source projects I've converted over to SBT. Now when I run tests (approx 1000 test cases), I get OOMs. Ok so I've tried
fork in Test := true
javaOptions in Test ++= Seq("-Xmx2048m", "-XX:MaxPermSize=512m")
Ok so my OOMs go away but now I get
sbt.ForkMain$Run$RunAborted: java.net.SocketException: Broken pipe
at sbt.ForkMain$Run.write(ForkMain.java:114)
at sbt.ForkMain$Run$1.info(ForkMain.java:132)
Seems to be in different places each time.
These tests all pass if I'm building via maven (scala test maven plugin).
Help me Obi-wan or SBT lovers.
Edit: Adding env details
sbt 0.12.4
java 7.25
scala 2.10.2

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)

SBT doesn't reconize junit testcase written in java file

I made a Scala/Java mixed project with SBT 0.11.2. My config for JUnit testing is
resolvers += "twitter.com" at "http://maven.twttr.com/"
seq(com.github.retronym.SbtOneJar.oneJarSettings: _*)
libraryDependencies += "com.novocode" % "junit-interface" % "0.10-M2" % "test"
When I write JUnit test cases in Scala with #Test, every goes well. But when I write a Java JUnit test case, then run test in sbt, the Java JUnit test cannot be reconized. Only test cases written in Scala are executed.
How can I make sbt recognize my Java and Scala test cases at the same time?
Probably late for the origional question, but..
I've just been looking at this. The JUnit tests in my project were not running for me until I ran sbt clean test. Now all working like a charm.
There was a bug in 0.11.x in detecting Java tests that was fixed in 0.12.0, although I didn't think it affected detecting annotated tests. You might try coming up with a minimal test case and checking with the latest sbt version (0.12.1). If the problem still exists, file a bug.
you should put your test classes into src/test/java and your class name should end with "Test" (for example myTest.java)