2016-09-02 10 views
0

私はテストを実行するためにspecs2を使用しています。私はscalacheckを走らせることができますが、以下では(私がsbtテストを実行すると)反例を表示しません。これは反例せずに、ほとんど役に立たない。その代わりSpecs2はscalacheck反例を印刷しませんか?

import org.specs2.mutable.Specification 

import org.scalacheck.Properties 
import org.scalacheck.Prop 
import org.specs2.ScalaCheck 
import org.specs2.scalacheck.Parameters 
import org.scalacheck.Gen 

class StripeExportSpec extends Specification with ScalaCheck { 
    import StripeExportJob._ 

    //.verbose makes no difference 
    implicit val params = Parameters().setVerbosity(10) 

    val p2: Properties = new Properties("dayIntervals") { 

    val dayEpochs = for { 
     n <- Gen.choose(1l, 500l) 
     m <- Gen.choose(n, 500l) 
    } yield (n*twentyFourHours,m*twentyFourHours) 

    property("aligns start to first parameter") = Prop.forAll(dayEpochs) { x: (Long,Long) => 
     val (a, b) = x 
     val result = dayIntervals(a, b) 
     result.head._1 == a 
    } 

    property("aligns end correctly to 24 hours after b") = Prop.forAll(dayEpochs) { x: (Long,Long) => 
     val (a, b) = x 
     val result = dayIntervals(a, b) 
     result.last._2 == b+twentyFourHours 
    } 

    } 

    //s2"dayIntervals respects ${properties(p2)}" 

    "dayIntervals respects " >> addFragments(properties(p2)) 

} 

私が得るすべてである:これは、あなたがAssertionErrors(またはプロパティでjava.lang.Errorのいずれかの種類を投げるときに発生するspecs2のバグである

[info] StripeExportSpec 
[info] 
[info] dayIntervals respects 
[info] 
[error]  ! dayIntervals.aligns start to first parameter 
[error]  java.lang.AssertionError: assertion failed (StripeExport.scala:157) 
[error] com.handy.pipeline.jobs.StripeExportJob$.dayIntervals(StripeExport.scala:157) 
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$2.apply(StripeExportSpec.scala:28) 
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$2.apply(StripeExportSpec.scala:26) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713) 
[error] org.scalacheck.Prop$.secure(Prop.scala:457) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.org$scalacheck$Prop$$anonfun$$result$1(Prop.scala:713) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.getFirstFailure$1(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.shrinker$1(Prop.scala:730) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:752) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:707) 
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:292) 
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:291) 
[error] org.scalacheck.PropFromFun.apply(Prop.scala:22) 
[error] org.scalacheck.Test$.org$scalacheck$Test$$workerFun$1(Test.scala:294) 
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323) 
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323) 
[error] org.scalacheck.Platform$.runWorkers(Platform.scala:40) 
[error] org.scalacheck.Test$.check(Test.scala:323) 
[error] com.handy.pipeline.jobs.StripeExportSpec.check(StripeExportSpec.scala:14) 
[info] 
[error]  ! dayIntervals.aligns end correctly to 24 hours after b 
[error]  java.lang.AssertionError: assertion failed (StripeExport.scala:157) 
[error] com.handy.pipeline.jobs.StripeExportJob$.dayIntervals(StripeExport.scala:157) 
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$5.apply(StripeExportSpec.scala:34) 
[error] com.handy.pipeline.jobs.StripeExportSpec$$anon$1$$anonfun$5.apply(StripeExportSpec.scala:32) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$3.apply(Prop.scala:713) 
[error] org.scalacheck.Prop$.secure(Prop.scala:457) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.org$scalacheck$Prop$$anonfun$$result$1(Prop.scala:713) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1$$anonfun$4.apply(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.getFirstFailure$1(Prop.scala:720) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.shrinker$1(Prop.scala:730) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:752) 
[error] org.scalacheck.Prop$$anonfun$forAllShrink$1.apply(Prop.scala:707) 
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:292) 
[error] org.scalacheck.Prop$$anonfun$apply$5.apply(Prop.scala:291) 
[error] org.scalacheck.PropFromFun.apply(Prop.scala:22) 
[error] org.scalacheck.Test$.org$scalacheck$Test$$workerFun$1(Test.scala:294) 
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323) 
[error] org.scalacheck.Test$$anonfun$3.apply(Test.scala:323) 
[error] org.scalacheck.Platform$.runWorkers(Platform.scala:40) 
[error] org.scalacheck.Test$.check(Test.scala:323) 
[error] com.handy.pipeline.jobs.StripeExportSpec.check(StripeExportSpec.scala:14) 

答えて

1

これが。 。。3.8.4-20160905063548-8470e96に固定されている

また、あなたが仕様を使用しているので、あなたがScalaCheck Propertiesを使用する必要はありませんあなたは書くことができます。

"dayIntervals" >> { 

    "aligns start to first parameter" >> Prop.forAll(dayEpochs) { x: (Long,Long) => 
    val (a, b) = x 
    val result = dayIntervals(a, b) 
    result.head._1 === a 
    } 

    // another way of using generators 
    "aligns end correctly to 24 hours after b" >> prop { x: (Long,Long) => 
    val (a, b) = x 
    val result = dayIntervals(a, b) 
    result.last._2 === b+twentyFourHours 
    }.setGen(dayEpochs) 

} 

val dayEpochs = for { 
    n <- Gen.choose(1l, 500l) 
    m <- Gen.choose(n, 500l) 
} yield (n*twentyFourHours,m*twentyFourHours) 
+0

ありがとう、私はこれを後でテストします - 私はちょうど裸のscalacheckに落ちて仕事をしました。 – Marcin

関連する問題