Search code examples
sbtscalatest

SBT - Override testOnly


For testOnly in sbt I want to use specific testOptions (so the task test has different testOptions) and also I want to set a environment variable..

Any examples?


Solution

  • I've fixed it by introducing a new scope Diagnose:

    
    lazy val Diagnose = config("diagnose") extend Test
    lazy val diagnoseSettings = inConfig(Build.Diagnose)(Defaults.testTasks ++ Seq(testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oD"), envVars := Map("TEST_LOG_LEVEL" -> "debug")))
    

    Then I use it at a project in conjuction with these settings

    
    val p = (project in file("project")).configs(Build.Diagnose).settings(Build.diagnoseSettings).settings(testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-W", "5", "2"), testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oNCXEHLOPQRM"))
    

    Now when I run sbt test it will show only the failed tests. When you want to see why it failed you can use sbt diagnose:testOnly test-class