- 範囲指定有りとか
- 本当はsetにrngを与えればどうにかなりそうなんだけど…
- "org.scalacheck" %% "scalacheck" % "1.10.0"
import org.specs2.{ ScalaCheck, Specification }
import org.scalacheck._
// format: OFF
class SampleSpecs extends Specification with ScalaCheck { def is=
"1 to 10 random" ! e1().ex1 ^ endp^
"Range normal random" ! e2().ex2 ^ end
// format: ON
case class e1() {
implicit def a = Arbitrary { for { a <- Gen.oneOf(1 to 10) } yield a }
def ex1 = prop { (a: Int, b: Int) =>
println(a + "/" + b)
(a + b) must_== (b + a)
}.set(minTestsOk -> 10)
}
case class e2() {
def ex2 = prop { (a: Int, b: Int) =>
println(a + "/" + b)
(a + b) must_== (b + a)
}.set(minTestsOk -> 10)
}
}
-
DBのsetup/cleanup等を行なう時
- Specsは基本並列で動作
- 且つSpecファイル単位でも並列
- 従って注意が必要
- 参考
-
なんか本当はもっとうまくいく気がする
import org.specs2._
/**
* Dbを使用するUnitTestを実行するためのTestSuiteみたいな
* 各Specificationを順次実行するようにsequentialを明記
*/
class UseDbSpec extends Specification {def is =
args(sequential = true) ^
new HogeSpecification ^
new FugaSpecification ...
}
/**
* 個々で実行するやつも sequential にする
*/
class HogeSpecification extends Specification with … {def is =
args(sequential = true) ^
...
}
- sbtで実行時は「*Spec」クラス以外も対象になるので設定を書く※
// どのクラスを実行対象とするかを明記
testOptions := Seq(Tests.Filter(s => Seq("Spec", "Unit").exists(s.endsWith(_))))