How to disable “Slow” tagged Scalatests by default, allow execution with option?

后端 未结 1 662
灰色年华
灰色年华 2021-02-02 17:29

I want to disable certain automated tests tagged as \"Slow\" by default but allow the user to enable their execution with a simple command line. I imagine this is a very common

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 17:50

    I had a similar issue: I wanted to have tests that are disabled by default, but run in the release process. I solved it by creating a custom test configuration and setting testOptions in different scopes. So adapting this solution to your case, it should be something along these lines (in your build.sbt):

    lazy val Slow = config("slow").extend(Test)
    configs(Slow)
    inConfig(Slow)(Defaults.testTasks)
    

    Now by default exclude slow tests:

    testOptions in Test += Tests.Argument("-l", "org.scalatest.tags.Slow")
    

    But in the Slow scope don't exclude them and run only them:

    testOptions in Slow -= Tests.Argument("-l", "org.scalatest.tags.Slow")
    testOptions in Slow += Tests.Argument("-n", "org.scalatest.tags.Slow")
    

    Now when you run test in sbt, it will run everything except slow test and when you run slow:test it will run only slow tests.

    0 讨论(0)
提交回复
热议问题