小编Ged*_*ius的帖子

如何在测试之前启动Play应用程序,然后在specs2中将其关闭?

我的目标是让应用程序运行并在应用程序的同一个实例上执行多个测试.

我没有太多运气试过这个解决方案.这是我的测试:

class ApplicationSpec extends Specification { sequential


  object AppWithTestDb2 extends FakeApplication(additionalConfiguration = 
    Map(
    ("db.default.driver") -> "org.h2.Driver",
    ("db.default.url") -> (
//        "jdbc:h2:mem:play-test-" + scala.util.Random.nextInt +      // in memory database 
        "jdbc:h2:/tmp/play-test-" + scala.util.Random.nextInt +     // file based db that can be accessed using h2-browse in activator
        ";MODE=PostgreSQL;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1")
    ))

    running(AppWithTestDb2) {

      "Application" should {

        "send 404 on a bad request" in {
          route(FakeRequest(GET, "/boum")) must beNone
        }

        "post signup request" in {
          val res = route(FakeRequest(POST, "/user", FakeHeaders(), TestData.newUser)).get
                  status(res) …
Run Code Online (Sandbox Code Playgroud)

scala playframework specs2

4
推荐指数
1
解决办法
2311
查看次数

标签 统计

playframework ×1

scala ×1

specs2 ×1