SBT / Scala - Execute tests in order

Viewed 259

We are running "sbt test" to execute our tests on multiple projects. But we now have tests which need to execute in a specific order. So first all tests with @attributeX and after all these tests are completed we want to execute every test which doesn't contain attribute @attributeX.

sbt testOnly -- -n attributeX
sbt testOnly -- -l attributeX

This implementation works fine, but our issue is with the test reports. When the first run is completed we have our test reports for these tests, but when the second run has completed, the XML files are all generated again and this deleted the results of the first run.

Is there a easy way to configure in either build.sbt that we want to run groups of tests in a specific order (so we still want to run tests parallel but only within the group). Or can we somehow merge the two test results into one when executing these commands separately?

1 Answers

You could order them on per-suite level, for example:

@DoNotDiscover
class MyTest1 extends AnyFlatSpec ...

@DoNotDiscover
class MyTest2 extends AnyFlatSpec ...

and then:

import org.scalatest.Sequential

class SequentialSuite extends Sequential(
   new MyTest1,
   new MyTest2
)

Now when you run sbt test it will first execute tests in MyTest1, and then in MyTest2.

That's regardless of your tags.
Which kinda makes sense, because tags are usually fast/slow/uses-db.
They are usually used for local-only/environment-dependent etc.

Related