scalavisual-studio-codescalatestscala-metalsmill

VSCode / Metals / Mill / ScalaTest: AnyFlatSpec specs are not picked up


I am using AnyFlatSpec for my tests:

class FooTest extends AnyFlatSpec with Matchers {

  behavior of "The Foo"

  it should "do bar" in { ... }
  it should "do moo" in { ... }
}

My project setup is using Mill, VSCode and Metals.

In the Tests tab, VSCode only shows me the test class, so I can only run the whole test class, not individual tests.

What do I have to do to to be able to run individual tests?

If ScalaTest is not supporting that, I am also eager to switch to another testing framework.


Solution

  • In principle it should be possible to run individual tests using ScalaTest, but it requires to pass a flag to the runner specifying the full test name to guarantee you are running exactly one test (see https://www.scalatest.org/user_guide/using_the_runner#selectingSuitesAndTests). This might be something that the VS Code integration your are using cannot do (I believe IntelliJ does). You might want to have a look at MUnit, which seems to have a more convenient way of filtering individual tests (https://scalameta.org/munit/docs/filtering.html) and might already be integrated.