在'中使用specs2是' play2

时间:2016-01-18 02:56:16

标签: playframework playframework-2.0 specs2

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)

}

HashIdGenerator需要播放应用程序启动,播放文档显示我们需要以这种方式获取播放应用程序: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
  }
}

但是我不喜欢这样的'应该在'风格,所以我怎样才能获得一个游戏应用程序并继续使用'是'风格在同一时间。

1 个答案:

答案 0 :(得分:0)

使用WithApplication将代码依赖于播放应用程序:

  val Id = 1
  val app = new WithApplication {
    val hashId = HashIdGenerator.hashId(Id)
  }
  val hashId = app.hashId