我试过了
val arbLong: Gen[Long] = {
Gen.frequency((20, Arbitrary.arbLong), (20, null)).sample.get.arbitrary
}
"arbLong" should "be able to generate null values" in {
forAll(arbLong) { (generatedLong: Long) =>
println(generatedLong)
}
}
所以它确实会为 long 生成一个 null,但是我NullPointerException
很可能是因为Long
无法持有null
使用任意 long 生成器的正确方法,其中包括nulls
?