Play2 Scala specs2 - 在单个应用程序WithServer中进行多次测试

时间:2015-10-16 13:59:11

标签: scala playframework-2.0 specs2

按照此post中的说明,我已经能够在单个FakeApplication实例中运行多个测试。这样可以显着缩短测试执行时间并避免与play-reactivemongo插件相关的一些问题。

所以我改变了我的测试类形式:

{
  "SomeController" should {
    "do this" in FakeApplication(additionalConfiguration = addConf) {
      ...
    }
    "do that" in FakeApplication(additionalConfiguration = addConf) {
      ...
    }
  }
}

到此:

def application = FakeApplication(additionalConfiguration = addConf)
step(play.api.Play.start(application))

"SomeController" should {
  "do this" in {
    ...
  }
  "do that" in {
  ...
  }
}

step(play.api.Play.stop())

现在问题是我有一些使用WithServer构造函数运行测试服务器的测试。像这样:

{
  "SomeOtherController" should {
    "do this" in new WithServer(app = FakeApplication(additionalConfiguration = addConf)) {
      ...
    }
  }
}

是否可以为所有测试运行单个测试服务器?

感谢。

1 个答案:

答案 0 :(得分:4)

我找到了解决方案:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
    <dir name="${project.root}/Modules/manager/manager-web/dist/classes">
        <exclude name="**/seam*.*"/>
    </dir>
    <dir name="${project.root}/Modules/common/common-web/dist/classes">
        <exclude name="**/seam*.*"/>
    </dir>
</classpath>
<web>
    <link target="/">
        <dir name="${project.root}/Modules/manager/manager-web/WebContent" />
        <dir name="${project.root}/Modules/common/common-web/WebContent" />
    </link>
</web>

再见