I don’t want to execute some code when it comes from test (Specs2)
For eg. emailers.
How can i check that my code is executing from tests?
I use fakeApplication and TestServer in my specs.
Alternative i could check my database driver (h2 for tests and postgres for production) this way.
import play.api.Play.current
def isFromTests:Boolean={
Play.application.configuration.getString("db.default.driver") match {
case Some("org.h2.Driver") => true
case _ =>false
}
}
But is there a better one? Sometimes i run my app with h2.
You can use
play.Play.isTest()method to check if you are running in test mode.