当我使用sbt控制台运行单元测试两次或更多时,我得到以下错误。我第一次跑的时候没有任何错误。如果我从Sbt退出(Ctrl + D)并返回到Sbt,首次运行测试没有问题。使用IntelliJ。
我的测试套件包含许多测试用例,如下所示
val timeOutSpan = 5
val intervalSpan = 500
implicit val defaultPatience =
PatienceConfig(timeout = Span(timeOutSpan, Seconds), interval = Span(intervalSpan, Millis))
it should "get houses" in {
val index: Future[Result] = destinations.index
.apply(FakeRequest(GET, "/houses"))
whenReady(index){ index =>
index.header.status shouldBe 200
}
}
获得以下错误
java.lang.ExceptionInInitializerError
at play.api.http.HttpConfiguration$.current(HttpConfiguration.scala:149)
at play.api.mvc.GlobalStateHttpConfiguration$.httpConfiguration(Http.scala:22)
at play.api.mvc.Session$.path(Http.scala:713)
at play.api.i18n.DefaultMessagesApi.setLang(Messages.scala:502)
at play.api.i18n.I18nSupport$ResultWithLang.withLang(I18nSupport.scala:49)
at controllers.BaseController.decorate(BaseController.scala:38)
at modules.home.controllers.Home$$anonfun$index$1$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$9$$anonfun$apply$10.apply(Home.scala:51)
at modules.home.controllers.Home$$anonfun$index$1$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$9$$anonfun$apply$10.apply(Home.scala:40)
at scala.util.Success$$anonfun$map$1.apply(Try.scala:237)
at scala.util.Try$.apply(Try.scala:192)
at scala.util.Success.map(Try.scala:237)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:237)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:237)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
at org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParserImpl(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(Unknown Source)
at play.api.Play$.<init>(Play.scala:46)
at play.api.Play$.<clinit>(Play.scala)
... 19 more
答案 0 :(得分:0)
在我的测试套件中包含OneAppPerSuite解决了这个问题。
class ExampleSpec extends FlatSpec with OneAppPerSuite {
test cases go here
}
OneAppPerSuite的详细信息为here