Jeriho Jeriho - 1 month ago 7
Scala Question

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?

Answer

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