Getting test-only to work outside SBT console - scala

I'm using Specs2 for tests, with latest Play, Scala and SBT.
In sbt console, this works great, running only tests in UserServiceSpec:
[my-project] $ test-only services.UserServiceSpec
Outside sbt console, in project root directory, this does not work:
$ sbt test-only services.UserServiceSpec
This runs all the tests. (Same happens with testOnly.)
How is test-only supposed to work outside sbt console?
Follow-up question: using Specs2 tags, how to execute only tagged tests on the command line, outside sbt console?
$ sbt test-only -- include unit
The above, again, tries to to execute all tests (while test-only -- include unit in sbt console works fine).
Basically, I'd like to run all unit tests on a CI server, and Specs2 tags seem like a good tool for separating different kinds of tests. In this scenario I couldn't use the sbt console, right?

Sbt consider two parameters as two separate commands. You should mark it as one.
Try: sbt "testOnly services.UserServiceSpec"

Related

compile/package multiple configurations from command line sbt scala

is there a way to build/compile all configurations at once? I have a project that has a Dev configuration in addition to the default Compile and Test configuration, and i am looking for a command or a setting in my build.sbt that would allow me to compile/package all 3 configurations at once.
Basically looking for a way to avoid having to do these 3 commands to build the entire source tree:
sbt compile
sbt dev:compile
sbt test:compile
When I use sbt from IntelliJ it is able to do this on building the project, but I am looking to do this from the command line.
First, you can run multiple tasks with a single sbt invocation:
sbt compile dev:compile test:compile
Second, you could define an alias in your build which does what you want:
addCommandAlias("compileAll", "; compile; dev:compile; test:compile")
Then, just run sbt compileAll.

IntelliJ print test run dependencies

I am working on a scala project which uses sbt for build tools. When we run unit tests on command line 'sbt test', the tests are running fine. However, when I run unit tests in IntelliJ, it seems to be picking up incorrect version of a dependency as well.
I was wondering if there is a way for me to print the classpath that IntelliJ is running the unit tests with?
IntelliJ IDEA already does that, actually, for each test run.
Tests are run as an invocation of JVM with the classpath passed to command-line parameter.
You need to press on the ellipsis to see the whole command line.
Classpath will be there after -classpath argument.
It's better to copy it to another window and enable line wrapping for the further digging.

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.

Run scalatest in main instead of test through sbt?

Say I have a Scalatest file in the main directory, is there a sbt command to run the test such as testOnly or `runMain'? On IntelliJ, you are given the option to run the test.
You should be able to use test-only. From the scalatest user guide:
test-only org.acme.RedSuite org.acme.BlueSuite

Group unit tests and run only a set

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.