以下のコードで、Specs2 に最初のテストを実行させるにはどうすればよいですか? 「印刷物」テストは、失敗するはずのときに合格します。forAll()
が原因で、セクション内のコードが実行されていませんnew Scope
。
println
ステートメントは、トレース出力専用です。「一」で始まる行があれば教えてください。
空Scope
は問題を示すためだけのものです。これは、実際に変数を使用するコードから取り除かれていScope
ます。
import org.scalacheck.Gen
import org.scalacheck.Prop._
import org.specs2.ScalaCheck
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
class TestingSpec extends Specification with ScalaCheck {
"sample test" should {
"print ones" in new Scope {
println("The first test passes, but should fail")
forAll(Gen.posNum[Int]) { (x: Int) =>
println("one: " + x)
(0 < x) mustNotEqual true
}
}
"print twos" in {
println("The second test passes and prints twos")
forAll(Gen.posNum[Int]) { (x: Int) =>
println("two: " + x)
(0 < x) mustEqual true
}
}
}
}
ここに私の出力があります:
sbt> testOnly TestingSpec
The second test passes and prints twos
The first test passes, but should fail
two: 1
two: 2
two: 1
...
two: 50
two: 34
two: 41
[info] TestingSpec
[info]
[info] sample test should
[info] + print ones
[info] + print twos
[info]
[info] Total for specification TestingSpec
[info] Finished in 96 ms
[info] 2 examples, 101 expectations, 0 failure, 0 error
[info]
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 3 s, completed Apr 28, 2015 3:14:15 PM
PS プロジェクトの依存関係をバージョン 2.4.15 から specs2 3.5 に更新しました。まだこの問題があります...