ScalaTest in sbt: is there a way to run a single test without tags?

后端 未结 5 1736
不知归路
不知归路 2020-12-04 05:46

I know that a single test can be ran by running, in sbt,

testOnly *class -- -n Tag

Is there a way of telling sbt/scalatest to run a single

5条回答
  •  误落风尘
    2020-12-04 06:15

    I don't see a way to run a single untagged test within a test class but I am providing my workflow since it seems to be useful for anyone who runs into this question.

    From within a sbt session:

    test:testOnly *YourTestClass
    

    (The asterisk is a wildcard, you could specify the full path com.example.specs.YourTestClass.)

    All tests within that test class will be executed. Presumably you're most concerned with failing tests, so correct any failing implementations and then run:

    test:testQuick
    

    ... which will only execute tests that failed. (Repeating the most recently executed test:testOnly command will be the same as test:testQuick in this case, but if you break up your test methods into appropriate test classes you can use a wildcard to make test:testQuick a more efficient way to re-run failing tests.)

    Note that the nomenclature for test in ScalaTest is a test class, not a specific test method, so all untagged methods are executed.

    If you have too many test methods in a test class break them up into separate classes or tag them appropriately. (This could be a signal that the class under test is in violation of single responsibility principle and could use a refactoring.)

提交回复
热议问题