How to set System property for a scalatest from sbt command line
11,350
Solution 1
Your third way almost works (if fork in Test := true
is set). But you have to change into the project first:
sbt/sbt '; project mllib; set javaOptions in Test +="-Dtest.num.points=500000"; \
test-only org.apache.spark.mllib.optimization.LBFGSSuite'
Solution 2
This worked for me:
val myFoo = sys.props("foo.property")
and:
SBT_OPTS="-Dfoo.property=foo" sbt "testOnly *your_test_package*"
Author by
WestCoastProjects
R/python/javascript recently and before that Scala/Spark. Machine learning and data pipelines apps.
Updated on June 14, 2022Comments
-
WestCoastProjects almost 2 years
A ScalaTest suite is using
System.getProperty("my.command-line.property")
What is the sbt command line to achieve this setting?
I have tried
SBT_OPTS="-Dmy.command-line.property=foo" sbt "test-only <path to test suite"
Also:
JAVA_OPTS="-J-Dmy.command-line.property=foo" sbt "test-only <path to test suite"
Finally:
sbt/sbt '; set javaOptions in Test +="-Dtest.num.points=500000"; \ project mllib; test-only org.apache.spark.mllib.optimization.LBFGSSuite'
When using any of those attempts the System.getProperty comes up blank.
An approach that does work is running the ScalaTest from within Intellij and setting the JVM parameters to -Dmy.command-line.property=foo within the Run Configuration.
-
WestCoastProjects about 9 yearsYour answers are not addressing the particulars of this question: runMain is not applicable to scalatest
-
Sudheer Aedama about 9 years@javadba I did not give you the direct answer. You could have guessed the answer, :) If not see my
EDIT 2
-
WestCoastProjects about 9 yearsI partially agree: was molding my command line that way to see if scalatest can work with it. Update: that approach does not apparently work with scalatest.
-
WestCoastProjects over 8 yearsInside a scalatest suite?
-
user1859675 over 8 yearsThe first line inside your test code, the second line command line (how to set your property and limit the test execution only to your desired package)
-
Mingo almost 6 yearsEdit 2 would work on unix but not on windows, as need double quote wrapper, any ideas on how could make this work on windows?
-
Troy Daniels over 4 yearsIs there a way to apply that to every project? I am trying to set a flag that limits logging during the CI build, but I wan't it set in every project. And since it is only for CI, I need a command line option