Reputation: 1094
The following is a fragment of build.sbt
, that I comment out when I want to debug an individual test.
// *** Uncomment These Two Lines If you are debugging individual Test ***
//fork in Test := false
//parallelExecution in Test := false
What I would like to do is instead of manually commenting in/out the above fragment, is to run the above condition depending on the environment value I specify to sbt
(for example "test-only -Dindividual_test=true"
). This way, I can write various test and integrated run configurations from an IDE.
I know if we left it like this, some day, a developer will push the change with this left undocumented.
Is this something we need to do in build.scala
instead?
Or is there an alternate way of achieving this?
Upvotes: 1
Views: 826
Reputation: 14842
You could create an individual setting key which you can change in the interactive session:
build.sbt
val individualTest = Def.settingKey[Boolean]("Whether to run tests individually")
individualTest := false // individualTest is a setting like every other
fork in Test := !individualTest.value
parallelExecution in Test := !individualTest.value
Now in your session, you can just switch individualTest
interactively:
> set individualTest := true
> testOnly
// fork in Test is false
// parallelExcecution is false
> set individualTest := false
// fork in Test is true
// parallelExcecution is true
If you want to run this from the command line, put each individual sbt command in quotes:
sbt 'set individualTest := true' 'testOnly myTest'
Upvotes: 2