0
我正在尝试为使用play framework 2.4和scala编写的应用程序编写测试。源是可用的here如何在Play框架应用程序中进行完整的集成测试?
我想写测试,将与整个堆栈一起工作。我们正在使用通过REST API提供的neo4j数据库。
这里是我的测试:
package integration
import org.specs2.mutable._
import org.specs2.specification._
import play.api.test.Helpers._
import play.api.test._
import setup.TestSetup
class PublicAPISpec extends Specification with BeforeEach {
def before = TestSetup.populateNeo4JData()
"The score feedback badge api" should {
"deliver a correct svg file" in {
running(FakeApplication()) {
val svg = route(FakeRequest(GET, "/api/badges/github/test/test.svg")).get
status(svg) must equalTo(OK)
contentType(svg) must beSome.which(_ == "image/svg+xml")
}
}
}
}
这里是我的堆栈跟踪:
[info] The score feedback badge api should
[error] ! deliver a correct svg file
[error] There is no started application (Play.scala:71)
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:71)
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:71)
[error] play.api.Play$.current(Play.scala:71)
[error] setup.TestSetup$.setup$TestSetup$$cypher(TestSetup.scala:80)
[error] setup.TestSetup$.clearNeo4JData(TestSetup.scala:23)
[error] setup.TestSetup$.populateNeo4JData(TestSetup.scala:32)
[error] integration.PublicAPISpec.before(PublicAPISpec.scala:15)
[error] integration.PublicAPISpec.before(PublicAPISpec.scala:13)
编辑 事实证明,像堆栈跟踪明明指出的主要问题是在TestSetup类。这个类取决于一个游戏应用程序运行,而不应该。经过一些重构后,它现在就像一个魅力。
谢谢你的答案,但是我得到了完全相同的异常 –
我拉了代码,但我没有找到该文件。 – roterl
这是在一个分支,我只是推它:[这里](https://github.com/gitlinks/gitrank-web/blob/feature/giveFeedbackBadge/test/integration/PublicAPISpec.scala)你去。谢谢您的帮助 ! –