You can use --test_arg, but the test rule itself must interpret such flags.
scala_specs2_junit_test macro wraps a
scala_junit_test rule. As a test rule, the latter must write
ctx.outputs.executable (see rule()#test) which is what Bazel executes upon
bazel test //my:test and passes the
--test_arg flags to.
I didn't find any logic in the Scala rules that would parse
--jvm_flags flags, so it seems they need to be updated to handle that.
def _my_test_impl(ctx): ctx.file_action( ctx.outputs.executable, "\n".join([ "#!/bin/bash", "echo \"DEBUG: Hello from $(basename $0)\"", "echo \"DEBUG: Argv=($@)\"", # Flag parsing (e.g. --jvm_flags) would have to happen here ]), True) my_test = rule( implementation = _my_test_impl, test = True, )
load("//:my_test.bzl", "my_test") my_test( name = "my_test", )
$ bazel test //:my_test --test_output=streamed -t- --test_arg=--foo=bar --test_arg=--jvm_flags=blah (...) INFO: (14:45:05.379) Found 1 test target... DEBUG: Hello from my_test DEBUG: Argv=(--foo=bar --jvm_flags=blah) Target //:my_test up-to-date: bazel-bin/my_test INFO: (14:45:05.501) Elapsed time: 0.393s, Critical Path: 0.11s INFO: (14:45:05.501) Build completed successfully, 3 total actions //:my_test PASSED in 0.1s
EDIT: added comment to my_test.bzl to highlight where the flag parsing would happen
You can always set a system property in Java programatically using System.setProperty(name, value).
The drawback to doing this in a unit test is that the property will stay set after the test. Make sure you set the value to null after the test.
- Bazel- Can I pass system property to test JVM (skylark rule)?
- How can I pass JVM options to SBT to use when running the app or test cases?
- In ScalaTest, how can I specify test tags via a system property
- Pass system property to spark-submit and read file from classpath or custom path
- How can I pass my logback.xml into my akka application as a system property?
- Pass System Property to `sbt console`?
- How can I pass this case rule in Scala to only accept string containing letters?
- In scala can I pass repeated parameters to other methods?
- How can I pass extra parameters to UDFs in Spark SQL?
- How can I fix the missing implicit value for parameter ta: TildeArrow in a test spec
- How can I share memory between two JVM instances?
- Scala: How can I install a package system wide for working with in the repl?
- How can I configure system properties or logback configuration variables from typesafe config?
- How do I set a system property for my project in sbt?
- How to fork the jvm for each test in sbt
- How to make virtual time pass in a test in Cats Effect 3?
- How can I pass a Scala object reference around in Java?
- Can a Scala for-yield return None if I pass in an Option to it?
- can you test nested functions in scala?
- How to pass environment variables to a sbt test build step in Jenkins?
- How can I roll back an integration test with Slick 3 + Specs2?
- How can i skip a test in specs2 without matchers?
- How can I test Java programs with ScalaCheck?
- Can I pass an arbitrary function to another function in Scala?
- How can I get a return value from ScalaTest indicating test suite failure?
- How to set System property for a scalatest from sbt command line
- Can I run my scala program without JVM using scala-native?
- How can I reduce the number of test cases ScalaCheck generates?
- How can I pass a type as a parameter in scala?
- How can I get the max of an arbitrary property from a list in Scala?
More Query from same tag
- SBT - invalid system property 'sbt.repository.config'
- How to pass some Bundles as Module parameters?
- Round-up of Scalaz type class instances for other libraries
- Avoid code duplication using duck typing in scala
- remove all substrings matching pattern within a string in scala
- Apache Spark: Hold Custom class in GraphX: Not Serializable?
- Calling an anonymous function inside a map method
- Why does Breeze use Array to represent a matrix?
- Scala: recursively adding to immutable map?
- How to build an Akka Streams Source from the Akka Event Stream?
- How to store different value types in scala
- Finding the TotalSpent for each Customer in Scala
- direct use of Futures in Akka
- Error while writing the content of a file to another in scala
- Invoking scala classes which extends traits during runtime
- is it possible to console.log in Play Framework view?
- Find file in external jar not in my classpath
- Mocking in Play! and Scala
- Get only the Header using the WS library from play framework 2.2.1. (Scala)
- Multiple type for a variable in spark using scala
- Spark Dataframe changing through execution
- obtaining type from type name in scala
- Explode array in apache spark Data Frame
- How refactor incrementing in scala?
- Is it possible to "mix in: additional type constraints
- Handling multiple TCP connections with Akka Actors
- I am trying to delete the data from postgres using spark but unable to delete same code is working for select statements
- How to find import associated with a class?
- Scala Dynamic class to inner dynamic class
- How to create a sequence of timestamps in Scala