Read paramenters from maven cli in tests

65 views
Skip to first unread message

gerrald...@gmail.com

unread,
Apr 9, 2014, 11:40:34 AM4/9/14
to scalate...@googlegroups.com
Hi all,
 
Could somebody help me understand how can I read and use in tests values that are specified in maven cli when starting tests?
 
I'm using
- scalatest_2.10
- scalatest-maven-plugin 1.0-M4-SNAPSHOT
 
I run tests with the command:
 
mvn clean test-compile scalatest:test -Dsuites=com.gr.MySuite
 
I need to be able to specify the env to run the tests against. Something like:
 
mvn clean  test-compile scalatest:test -Dsuites=com.gr.MySuite -Denv=QA
 
When I try to do that and then in the test get this with System.getProperty("env") I get null instead of the value
 
 
What am I missing here?
 
I've tried to search the group topic but for no results. Sorry if this question is something that is already answered - I'm new to Scalatest and to google groups
 
Thanks!
 
GerraldG

Bill Venners

unread,
Apr 9, 2014, 12:30:07 PM4/9/14
to scalate...@googlegroups.com
Hi Gerrald,

I am not sure why your system properties are not showing up. That I think may be a maven question, so you could possibly ask on a Maven-oriented list. But what I'd suggest using instead, though, is ScalaTest's config map properties. Our documentation for the ScalaTest Maven plugin is here:

http://scalatest.org/user_guide/using_the_scalatest_maven_plugin

It says:

config  Comma separated list of configuration parameters to pass to ScalaTest. The parameters must be of the format <key>=<value>: e.g., foo=bar,monkey=donkey

This means to insert something like this in your XML:

<config>env=QA</config>

You can then grab this from the config map in various ways. The configMap is passed to run, runNestedSuites, runTests, runTest, and withFixture, so you can override one of those to grab the config map itself. Then use its API to grab the env, described here:

http://doc.scalatest.org/2.1.3/index.html#org.scalatest.ConfigMap

We are currently trying this ourselves, just to verify we have the syntax correct, and I'll update the documentation with a better example once we have it. If I discover anything different from what I said here I'll post again. Let me know if you have any trouble.

Thanks.

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/d/optout.



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

gerrald...@gmail.com

unread,
Apr 10, 2014, 6:02:41 AM4/10/14
to scalate...@googlegroups.com
Hey Bill,
 
Looks like system properties cannot be reached within ScalaTest unless they're passed to scalatest-maven-plugin in some way. 
Yes, using ConfigMap solves this but with some additional steps in pom.xml:
 
1. I've defined property in pom.xml like
 <properties><environment>QA</environment><properties>
 
2. I've told plugin to use that in ConfigMap:
<config>env=${environment}</config>
 
3. In the test code I'm using BeforeAndAfterAllConfigMap:
 
  override def beforeAll(conf:ConfigMap) {
    val en = conf.get("env").get

  }
 
Now if I run the tests with
mvn clean  test-compile scalatest:test -Dsuites=com.gr.MySuite -Denvironment=DEV
 
The flag is passed to config map and can be used in code. Thus, I'm able to dynamically tell which env to run tests against ( particularly in Jenkins job) - by default we're targeting QA.
 
Thanks for hint!
 
Best regards,
GerraldG
 

 

Bill Venners

unread,
Apr 10, 2014, 6:29:38 PM4/10/14
to scalate...@googlegroups.com
Hi Gerrald,


You're welcome. Glad to hear it worked for you.

Bill
 
Best regards,
GerraldG
 

 

--
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/d/optout.
Reply all
Reply to author
Forward
0 new messages