4

我正在使用 Play Framework 2.1.x 并希望有两个测试配置,一个用于小型测试,另一个用于大型测试。大型测试需要有自定义 javaOptions 值。我有以下配置,但似乎 javaOptions 设置没有被选中。

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val mySettings = Seq(...)

  val smallTestSettings = Defaults.testSettings ++ Seq(
    testOptions := Seq(Tests.Filter(smallTests))
  )

  val largeTestSettings = Defaults.testSettings ++ Seq(
    testOptions := Seq(Tests.Filter(largeTests)),
    javaOptions ++= Seq("-Dmysetting=1")  // <--- PROBLEM HERE
  )

  lazy val SmallTest = config("smalltest") extend(Test)
  lazy val LargeTest = config("largetest") extend(Test)

  val main = play.Project(appName, appVersion, appDependencies)
    .configs(SmallTest)
    .configs(LargeTest)
    .settings(mySettings: _*)
    .settings(inConfig(SmallTest)(smallTestSettings): _*)
    .settings(inConfig(LargeTest)(largeTestSettings): _*)
}

有趣的是,如果我将行更改为:

    javaOptions in Test ++= Seq("-Dmysetting=1")

然后它确实被大型和小型测试所接受。关于如何仅为大型测试配置设置此自定义 javaOptions 的任何想法?

4

1 回答 1

1
  val largeTestSettings = Defaults.testSettings ++ Seq(
    testOptions := Seq(Tests.Filter(largeTests)),
    testOptions in LargeTest += Tests.Argument("-Dmysetting=1")
  )

我得到的 specs2 测试只是为了读取属性,如果它们是用 JUnitRunner 注释的:

import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner

@RunWith(classOf[JUnitRunner])
class LargeScalaTest extends Specification {
  "mysetting should be 1" in {
        System.getProperty("mysetting") must beEqualTo("1")
  }
}

我的测试项目位于GitHub 上的一个分支中。

于 2013-10-30T07:44:09.323 回答