According to ScalaTest documentation it's possible to use JUnitRunner to run tests. My assumption was, if it runs with JUnitRunner, its callback methods (i.e. methods marked with @Before
or @After
annotation should work as well. But apparently my assumption was wrong. I've created simple example to demonstrate it:
import org.junit.Before
import org.junit.runner.RunWith
import org.scalatest.{FunSuite, _}
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class Test extends FunSuite {
@Before
def before() = {
println("before test")
}
test("nothing") {
println("test is started")
}
}
If you run this example, you'll see test is started
line, but not before test
.
I'm aware of ScalaTest lifecycle callbacks, but the thing is I need to make JUnit callbacks work somehow. I want to write a test for Play 2.4 application and the thing it's play.test.WithBrowser
class relies on JUnit callbacks. I found this workaround for the issue:
var testBrowser : TestBrowser = _
before {
new WithBrowser {
override def createBrowser(): Unit = {
super.createBrowser()
testBrowser = browser
}
}.createBrowser()
}
but I believe it's quite ugly and I suspect that there is a better way.
So, my question is if it's possible to make these JUnit lifecycle callbacks work with ScalaTest? And if it is possible, how to do that?