I want to override the ScalaTest trait BeforeAndAfterEach to have that stuff implemented once for all my tests. Finally I got it to compile, but I don't understand why.
trait MySetup extends BeforeAndAfterEach {
this : org.scalatest.BeforeAndAfterEach with org.scalatest.Suite =>
var service: String = _
abstract override def beforeEach(): Unit = {
service = "apa"
super.beforeEach()
}
abstract override def afterEach(): Unit = {
service = ""
}
}
The thing that got it working was the line:
this : org.scalatest.BeforeAndAfterEach with org.scalatest.Suite =>
I found it in the beginning of the BeforeAndAfterEach implementation and copied it.
What does it do, and why do I need it?
Update:
This is a simpler version.
trait MySetup extends FlatSpec with BeforeAndAfterEach {
var service: String = _
override def beforeEach {
service = "apa"
super.beforeEach
}
override def afterEach {
service = ""
super.afterEach
}
}