Search code examples
scalaspecs2

How to run specifications sequentially


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?


Solution

  • 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:

    Test / parallelExecution := false