1
votes
object Test extends Specification {

  var test = 1
  println("test: " + test)
  "Tests" should {
    "A" in {
      println("test in A: " + test)
      test = 2
      1 mustEqual 1
    }
    "B" in {
      println("test in B: " + test)
      test = 3
      1 mustEqual 1
    }

  }

  println("test end: " + test)

}

and when I run test I get:

test: 1 test end: 1 test: 1 test end: 1 test in B: 1 test in A: 1

I would like to make use of this variable, is it possible ? Thanks!

1

1 Answers

1
votes

The reason for the odd behaviour is that specs2 runs the specs concurrently.

This is one of the features, as you can read here http://etorreborre.github.io/specs2/ (check Features header).

You can make it running it sequentially, by adding sequential call to your spec.

object Test extends Specification {
  var test = 1

  sequential // <- this will make the examples sequentially

  println("test: " + test)
  "Tests" should {
    "A" in {
      println("test in A: " + test)
      test = 2
      1 mustEqual 1
    }
    "B" in {
      println("test in B: " + test)
      test = 3
      1 mustEqual 1
    }

  }

  println("test end: " + test)

}