为什么我的 Wiremock 没有在我的测试中启动

Why my Wiremock is Not Starting in my Test

我有这样的 wiremock 特征:

trait WiremockSetup extends BeforeAndAfterAll { self: Suite =>

  import WireMockConfiguration._

  protected val wiremockServer = new WireMockServer(options().dynamicPort())

  override protected def beforeAll(): Unit = {
    super.beforeAll()
    wiremockServer.start()
  }

  override protected def afterAll(): Unit = {
    wiremockServer.stop()
    super.afterAll()
  }

}

然后我在我的测试中混合特征 class 像这样

class Foo extends FlatSpec with WiremockSetup{

"Test scneario" should "do something" in {
assert (1 == 1)
}

}

但是我看到这样的编译问题:

An exception or error caused a run to abort. 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.github.tomakehurst.wiremock.jetty9.JettyHttpServerFactory.buildHttpServer(JettyHttpServerFactory.java:63)
    at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:76)

为什么会出现问题?

确保你有这个依赖:

"com.github.tomakehurst"  %  "wiremock-jre8"            % "2.22.0"