I know I can filter which tests to run using Tests.Filter(s => s.endsWith("Test")).
However, Scalatest (and I'm sure other testing frameworks) has an #DoNotDiscover annotation for when running the framework directly.
I was wondering, is there a way to make SBT recognize this annotation?
Thanks
EDIT: I just found out that Tests.Filter(s => s.endsWith("Test")) isn't what I want. I have some tests that shouldn't be ran in Jenkins. I would like these tests to not run when I type sbt test. However, I would like these tests to run if called directly sbt test-only some.test.
I think you can't do it with ScalaTest 1.x, the latest 2.0.M6-SNAP36 should have it supported though:
https://oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.10/2.0.M6-SNAP36/
Related
I'm currently experiencing a problem with Specs2 + SBT where my tests always fail via command-line because of dependency order in the classpath. Specs2 requires that the Mockito jars come after the Specs2 jars so that Mockito classes can be overridden to fix issues with by-name scala method parameters (see this issue for more information: https://github.com/etorreborre/specs2/issues/428).
In IntelliJ, I can order my dependencies via the Project Structure/Modules/Dependencies window, which fixes my tests when run inside IntelliJ, however, I have not found a solution to fix this issue when running my tests on the command-line via sbt test.
Does anyone know if it is possible to change the classpath order of dependencies for SBT using settings in build.sbt (or similar)?
To my knowledge you need to make sure that specs2-mock comes before mockito in your libraryDependencies setting.
I want to have an additional battery of tests to run against a database in addition to the unit test battery that requires no IO. What's the best way to do this with specs2 and sbt?
One of the solutions would be to put them in a namespace and use sbt test-only command:
$ sbt
> test-only com.example.utils.*
There's also a notion of tags in Specs2, which could be used to include or exclude tests at run time via SBT configuration.
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.
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)
I have an SBT 0.7.5 project and its some test cases fail. Until all test cases are fixed, I want to skip tests to generate a JAR. Is there any command line argument that tells SBT to skip all tests, like Maven's -Dmaven.test.skip=true flag?
I had the same problem, I'm using the assembly plugin. In this case, the solution was to modify the build file and add
test in assembly := {}
Instead of using compile, you could use package. The compile tasks also runs the tests, package doesn't.