播放升级到2.3.8使用wiremock的scala测试失败

时间:2015-05-15 16:00:26

标签: scala unit-testing playframework wiremock

我最近使用Slick等将我的Pl​​ay Scala项目更新为2.3.8。

从那时起,我的单元测试使用Wiremock继续失败。

错误显示:

  The future returned an exception of type: java.lang.RuntimeException, with message: There is no started application.

如果有任何帮助/建议会很感激吗?

class BlahTest extends FunSuite
  with MockitoSugar with ScalaFutures
  with SpanSugar with BeforeAndAfter with BeforeAndAfterAll {

val wiremock = new WireMockServer(wireMockConfig().port(1234)
  .fileSource(new SingleRootFileSource("test/resources")))

override protected def beforeAll() = wiremock.start()

override protected def afterAll() = wiremock.stop()

before {
  Mockito.reset(mockLogger)
  configureFor("localhost", 1234)
  stubFor(post(urlMatching("/somepath"))
    .willReturn(aResponse()
    .withStatus(200)))
}

after {
  WireMock.reset()
}

test("Some test") {
  val f = someObject.method(param1, param2)
  whenReady(f, timeout(WiremockTimeout milliseconds)) { answer =>
    // verify
  }
}

1 个答案:

答案 0 :(得分:1)

确保您的测试首先启动FakeApplication。一种方法是使您的测试类扩展WithApplication