pum*_*ump 1 scala implicit-conversion scalatest scalacheck scala-ide
我正在尝试使用 ScalaTest 进行基于属性的测试。我使用 2 个自定义生成器编写了一些测试用例,它们运行良好。然而,当我使用一个自定义生成器定义 forAll 时,如下所示:
it should "generate a given number of weights whose total is less than the given total when the given number is > 0, with default upperBound, lowerBound and total" in {
// TODO: Find out why single parameter does not work. maxSize here is a workaround
forAll(reasonableSizes) { (size: Int) =>
whenever(size > 0) {
val range = random.nextLong.abs
val values = DataGenerator.generatePartialWeights(size)
values should have length size
every(values) should (be >= BigDecimal(0) and be <= BigDecimal(1))
values.sum should be < BigDecimal(1)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在Eclipse中编译错误如下:
类型不匹配; 找到:(org.scalacheck.Gen[A],DataGeneratorTest.this.PropertyCheckConfigParam*) 必需:?0C[?0E] 请注意,隐式转换不适用,因为它们不明确:类型 [A] 的对象 Predef 中的两种方法 ArrowAssoc (self: A)ArrowAssoc[A] 和方法 Ensuring in object Predef of type [A](self: A)Ensuring[A] 是来自 (org.scalacheck.Gen[A], DataGeneratorTest.this.PropertyCheckConfigParam* 的可能转换函数) 到 ?0C[?0E]
我尝试了 ScalaTest 文档中的示例:http://www.scalatest.org/user_guide/generator_driven_property_checks
通过做
it should "testing" in {
val evenInts = for (n <- Gen.choose(-1000, 1000)) yield 2 * n
forAll(evenInts) { (n) => n % 2 should equal(0) }
}
Run Code Online (Sandbox Code Playgroud)
并得到同样的错误。
但是,当我在SBT中编译它时,没有错误。
sbt compile Java HotSpot(TM) 64-Bit Server [info] 从 C:\xxx 加载项目定义 [info] 将当前项目设置为 cree(在构建文件中:/C:/xxx) [info] 将 20 个 Scala 源代码编译为 C :\xxx\target\scala-2.11\classes...
[成功]总时间:37秒,完成2015年3月26日20:04:15
我不确定出了什么问题。有人可以帮忙吗?谢谢。
环境:
小智 5
您可以发布完整的测试课程吗?
我遇到了完全相同的问题,发现与该Inspectors特征一起使用存在冲突PropertyChecks。从我的测试类中删除该Inspectors特征后,一切正常。
abstract class UnitSpec extends FunSpec
with Matchers
with OptionValues
with Inside
// with Inspectors <= this conflicts with PropertyChecks trait
with PropertyChecks
with ValidationMatchers
with MockFactory
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
963 次 |
| 最近记录: |