sbt command line arguments

3,716 views
Skip to first unread message

Jeremy Stowell

unread,
May 9, 2013, 5:21:06 PM5/9/13
to scalate...@googlegroups.com
Is there a way that I can pass in command line arguments to launch the scalatest through sbt.

For example
I could pass in a argument in mvn testng like this
mvn clean test -Denv.USER=UAT
We are looking for a way to be able to pass in environment specific variables.  Database connection info, usernames, passwords, url based on if we are going against development, test, or stage.
We would like to be able to start the tests from the command prompt, but include a environment so that the tests will know what properties to use when running the tests.
sbt "test-only suite.name.className -Denv=test"   
Somthing like that.

Thanks
--Jeremy

Bill Venners

unread,
May 9, 2013, 6:19:43 PM5/9/13
to scalate...@googlegroups.com
Hi Jeremy,

You can pass arguments after -- via test-only. So something like:

$ sbt test-only suite.name.className -- -Denv=test

What that sets, though, is a ScalaTest "config map" param, so you'll need to grab env from the config map. If you want it to be  system property, you can set the system property programmitically by reading it out of the config map. I would think there must be some way to set system properties when starting sbt. (One way I can think of is to hack the sbt shell script, but one would think there's a way to do it on the command line. That's an sbt question though.)

Let me know if you have trouble with this, and if so, please include the version of sbt and ScalaTest you are using.

Bill


--
--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Bill Venners
Artima, Inc.
http://www.artima.com

Jeremy Stowell

unread,
May 10, 2013, 12:37:42 PM5/10/13
to scalate...@googlegroups.com
Perfect.  Thanks Bill that is exactly what we needed.

--Jeremy

Dara Lillis

unread,
Oct 3, 2016, 9:20:53 PM10/3/16
to scalatest-users, jeremy....@gmail.com
I am dealing with a similar issue and am stumped on how to grab the config map arguments passed via "-D"

I have Selenium tests I run inside sbt and would like to be able to configure, from the command line, which browser the test runs in.

So, I'd like to have something like:

$ sbt
> test-only <test name> -- -Dbrowser=chrome

I understand I need to grab it from the config map, but I'm having a hard time figuring out how to do that from the docs (I'm a relative newbie to Scala and sbt). A simple example would be really helpful.

Bill Venners

unread,
Oct 3, 2016, 9:37:55 PM10/3/16
to scalate...@googlegroups.com, jeremy....@gmail.com
Hi Dara,

The config map is included in the Args object passed into the run methods in ScalaTest, so one way to access them is to override run, runTests, or runTest, do what you want with args.configMap, and call super.run, super.runTests or super.runTest. Perhaps what that method will do is set a var in the trait to the value of the "browser" key in the config map. Probably you'll want to do that in a trait that extends TestSuiteMixin and declares TestSuite as its self type. Then you can  mix that trait into any test classes you want to have pick up the browser setting.

Bill

To post to this group, send email to scalatest-users@googlegroups.com

To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dara Lillis

unread,
Oct 4, 2016, 6:12:54 PM10/4/16
to scalatest-users
That worked, thank you!

The examples at http://www.scalatest.org/user_guide/sharing_fixtures helped me figure out the details.
For more options, visit https://groups.google.com/d/optout.

Tony Murphy

unread,
Oct 26, 2016, 7:42:19 PM10/26/16
to scalatest-users
I also had to add following to my build.sbt
fork in Test := false
Reply all
Reply to author
Forward
0 new messages