KarateKid
KarateKid

Reputation: 3436

Passing command line argument to sbt test

In sbt run config can be passed easily, for example as:

sbt "run -Dlib.lib1.version=2.0.0" 

But a similar thing fails when arguments are passed to sbt test. For example:

sbt "test -Dlib.lib1.version=2.0.0"

Official document states that sbt test doesn't support command line argument: "The test task accepts no command line arguments and runs all tests". I want to run test with different version of a library, the version is kept as a variable in the reference.conf, and I want to override this variable during test without changing the reference.conf each time.

So, how can I pass the config using command line argument to sbt test ?

Upvotes: 5

Views: 5242

Answers (2)

cms
cms

Reputation: 5982

The testOnly task does allow you to pass command line arguments, and they will be honoured.

e.g. sbt "testOnly MyTest -- -oU" allows me to pass the -oU flag through to the scalatest runner from the shell.

In theory this only allows you to pass extra arguments to specific tests. But there's another feature you can take advantage of to hack around this. testOnly parses wildcards in the test name.

So you can use a * wildcard to match every test and still pass arguments

sbt "testOnly * -- -oU"

passes the arguments after the * through to the test runner, and runs every test

Upvotes: 4

insan-e
insan-e

Reputation: 3922

I think that you can avoid passing the library version through the config file, you should be able to tell the sbt that you want different version via % "someConfig", like:

libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "it"

Note that these must not conflict, you can't have lib % "test, it" and lib % "test" because you will get a conflict.

Upvotes: 2

Related Questions