class ServiceTest extends PlaySpecification with Mockito {
override def is =
s2"""
This is Service Specification
The Service should create element in right way $init
"""
val metricId = 1
val hashid = HashIdGenerator.hashId(metricId)
def init = 1 mustEqual (1)
}
The HashIdGenerator need play application start , the play doc shows we need get a play application in this way: https://www.playframework.com/documentation/2.1.0/ScalaTest
"Computer model" should {
"be retrieved by id" in new WithApplication {
// your test code
}
"be retrieved by email" in new WithApplication {
// your test code
}
}
but i don't like this 'should in ' style , so how can i get a play application and keep using 'is' style at the same time .
use WithApplication wrap the code depend on play application:
val Id = 1
val app = new WithApplication {
val hashId = HashIdGenerator.hashId(Id)
}
val hashId = app.hashId