How to run specifications sequentially

Jeriho picture Jeriho · Feb 28, 2013 · Viewed 16.8k times · Source

I want to create few specifications that interoperate with database.

class DocumentSpec extends mutable.Specification with BeforeAfterExample {
  sequential

  def before() = {createDB()}
  def after() = {dropDB()}

  // examples
  // ...
}

Database is created and dropped before and after every example (which is executed sequentially). Everithing works as expected until there is only one spec that works with database. Because specifications are executed parallel, they interfere and fail.

I hope that I'm able to avoid this by instructing specs2 to run tests with side effects sequentially while keeping side effect free tests to run in parallel. Is it possible?

Answer

Régis Jean-Gilles picture Régis Jean-Gilles · Feb 28, 2013

I suppose you are using SBT? If so, check the documentation: http://www.scala-sbt.org/release/docs/Detailed-Topics/Parallel-Execution

The relevant SBT setting is parallelExecution. Add this to your project definition:

parallelExecution in Test := false