I have simple specification with several cases in it:
class MySpec extends Specification {
"Something" should {
"case 1" in {
...
}
"case 2" in {
...
}
}
}
Now I need to start application, run all cases, and shutdown the application. Starting/stopping the application is time consuming and I don't want it to happen around each case.
How do I run code before cases are started and after all the cases have finished?
The existing answers are great, but now there is a simple BeforeAfterAll
trait in specs2. Overriding it will provide the wanted functionality. For instance, the test:
class ASpec extends Specification with BeforeAfterAll {
"The 'Hello world' string" should {
"contain 11 characters" in {
println("test 1")
"Hello world" must have size (11)
}
"start with 'Hello'" in {
println("test 2")
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
println("test 3")
"Hello world" must endWith("world")
}
}
def beforeAll(): Unit = {
println("beforeAll")
}
def afterAll(): Unit = {
println("afterAll")
}
}
Will output:
beforeAll
test 3
test 2
test 1
afterAll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With