Frage

I need some help here... I’m using specs2 to run my integration tests.

So before everything is running, I’m setting up my simplicators (fake server my system interact with).

The problem is, that I need to find a way how to know when to shut down these servers once all tests are done.

After and step() are not good enough as they happen in each individual test scope. What is something that can run after all tests are done?

War es hilfreich?

Lösung

I found it!

Here is how it is done!

Here is a nice interface to setup an IT environment:

trait FakeServer {
  def setup: Unit
  def tearDown: Unit
}

object ITEnvironment extends FakeServer{
  private val simplicators: Seq[FakeServer] = Seq(new FakeWebServer)

  override def setup: Unit = simplicators foreach { server => server.setup}
  override def tearDown: Unit = simplicators foreach { server => server.tearDown}
}

trait Specs2ITEnvironment { this: Specification =>
  sequential
  override def map(fs: =>Fragments) = Step( {ITEnvironment.setup} ) ^ fs ^ Step( {ITEnvironment.tearDown} )
}

class LoginIT extends SpecificationWithJUnit with Specs2ITEnvironment{
    ... your test here ...
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top