2

我最近使用 Slick 等将我的 Play 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
  }
}
4

1 回答 1

1

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

于 2015-06-11T19:57:41.240 回答