Re: Set environment variable for running tests

4,772 views
Skip to first unread message

Jaka Jančar

unread,
Jan 4, 2013, 2:45:57 PM1/4/13
to simple-b...@googlegroups.com
Any tips? :(

On Thursday, January 3, 2013 8:52:00 PM UTC+1, Jaka Jančar wrote:
Hi,

Some of my classes, upon initialization (in companion object body), read an environment variable.

I need this environment variable to be set when running tests, before the classes are loaded.

Is there a way to do it with sbt / ScalaTest?

Thanks,
 Jaka

Eugene Vigdorchik

unread,
Feb 25, 2013, 8:14:40 AM2/25/13
to simple-b...@googlegroups.com
On Thu, Jan 3, 2013 at 11:52 PM, Jaka Jančar <ja...@kubje.org> wrote:
> Hi,
>
> Some of my classes, upon initialization (in companion object body), read an
> environment variable.
>
> I need this environment variable to be set when running tests, before the
> classes are loaded.
>
> Is there a way to do it with sbt / ScalaTest?
The easiest way looks to fork the tests and give the variables as java options:

fork in Test := true,
javaOptions in Test := Seq("-Dyour.option=value")

hth,
Eugene.

>
> Thanks,
> Jaka
>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-build-tool/-/siH_qvbtXKEJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-build-tool?hl=en.

Mark Harrah

unread,
Feb 27, 2013, 11:58:01 AM2/27/13
to simple-b...@googlegroups.com
On Mon, 25 Feb 2013 17:14:40 +0400
Eugene Vigdorchik <eugene.v...@gmail.com> wrote:

> On Thu, Jan 3, 2013 at 11:52 PM, Jaka Jančar <ja...@kubje.org> wrote:
> > Hi,
> >
> > Some of my classes, upon initialization (in companion object body), read an
> > environment variable.
> >
> > I need this environment variable to be set when running tests, before the
> > classes are loaded.
> >
> > Is there a way to do it with sbt / ScalaTest?
> The easiest way looks to fork the tests and give the variables as java options:
>
> fork in Test := true,
> javaOptions in Test := Seq("-Dyour.option=value")

Yes, if system properties are acceptable, that is the best way. In 0.13.0, environment variables may be set for forking run and test by configuring the envVars task:

https://github.com/sbt/sbt/issues/665

-Mark

> hth,
> Eugene.
>
> >
> > Thanks,
> > Jaka
Reply all
Reply to author
Forward
0 new messages