5
votes

How to run Test Suites sequentially in ScalaTest / SBT?

For example if I have this test suites A, B and C I want to make sure that the tests of A will be run 1st then the ones of B then the ones of C.

Is there in configuration that I can make in Scalatest or SBT?

Thank you.

3

3 Answers

2
votes

According to the documentation http://doc.scalatest.org/1.7/org/scalatest/Suite.html

You need to create your own Test Suite like the following:

FirstTest.scala

import org.scalatest.{DoNotDiscover, FunSuite}

@DoNotDiscover
class FirstTest extends FunSuite {

  test("first test"){
    assert(1 == 1)
  }

}

SecondTest.scala

import org.scalatest.{DoNotDiscover, FunSuite}

@DoNotDiscover
class SecondTest extends FunSuite{

  test("second test"){
    assert(2 == 2)
  }
}

MainTest.scala

import org.scalatest.Suites
class MainTest extends Suites (new FirstTest,new SecondTest)

Now, if you run sbt test it's work properly.

Notes: the property @DoNotDiscover is mandatory. this avoid unexpected behavior like execution of FirstTest and SecondTest after the execution of the MainSuite that are already executed the two test suites.

I hope it was helpful

1
votes

try using parallelExecution in Test := false

1
votes

As raj mehra said, the solution is to configure to run the tests not in parallel.

parallelExecution in Test := false

Here is the Documentation that explains it: SBT Parallel Execution

From it:

As before, parallelExecution in Test controls whether tests are mapped to separate tasks.