Questions tagged [scalacheck]

ScalaCheck is a powerful tool for automatic unit testing of Scala and Java programs.

ScalaCheck is a powerful tool for automatic unit testing of Scala and Java programs. It features automatic test case generation and minimization of failing test cases. ScalaCheck started out as a Scala port of the Haskell library QuickCheck, and has since evolved and been extended with features not found in Haskell QuickCheck .

265 questions
25
votes
3 answers

Why do you need Arbitraries in scalacheck?

I wonder why Arbitrary is needed because automated property testing requires property definition, like val prop = forAll(v: T => check that property holds for v) and value v generator. The user guide says that you can create custom generators for…
Val
  • 1
  • 8
  • 38
  • 59
22
votes
1 answer

java.lang.IncompatibleClassChangeError: Implementing class with ScalaCheck and ScalaTest

I'm facing a nasty exception when trying to write a test using ScalaCheck and ScalaTest. Here's my dependencies: libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "2.2.6" % "test", "org.scalacheck" %% "scalacheck" % "1.13.0" %…
Jeroen Rosenberg
  • 4,254
  • 2
  • 24
  • 37
21
votes
2 answers

Generate Option[T] in ScalaCheck

I am trying to generate optional parameters in ScalaCheck, without success. There seems to be no direct mechanism for this. Gen.containerOf[Option, Thing](thingGenerator) fails because it cannot find an implicit Buildable[Thing, Option]. I tried…
Synesso
  • 34,066
  • 32
  • 124
  • 194
17
votes
1 answer

High-Order ScalaCheck

Consider the following definition of a category: trait Category[~>[_, _]] { def id[A]: A ~> A def compose[A, B, C](f: A ~> B)(g: B ~> C): A ~> C } Here's an instance for unary functions: object Category { implicit def fCat = new…
Hugo Sereno Ferreira
  • 8,665
  • 6
  • 41
  • 88
16
votes
4 answers

Make ScalaCheck tests deterministic

I would like to make my ScalaCheck property tests in my specs2 test suite deterministic, temporarily, to ease debugging. Right now, different values could be generated each time I re-run the test suite, which makes debugging frustrating, because you…
Robin Green
  • 29,408
  • 13
  • 94
  • 178
15
votes
1 answer

How to have SBT re-run only failed tests

Is there a way to have SBT re-run only the tests that have failed in the last run of the test suite? For example, if I run sbt test and 3 out of the 20 tests I run fail, is there any command I can run to have SBT just re-run those 3 tests that…
Christopher Wells
  • 1,796
  • 1
  • 14
  • 20
15
votes
2 answers

Sized generators in scalacheck

UserGuide of scalacheck project mentioned sized generators. The explanation code def matrix[T](g:Gen[T]):Gen[Seq[Seq[T]]] = Gen.sized {size => val side = scala.Math.sqrt(size).asInstanceOf[Int] //little change to prevent compile-time exception …
Jeriho
  • 6,779
  • 9
  • 39
  • 56
15
votes
3 answers

scalacheck case class random data generator

I'm trying to generate random data with Scalacheck. I have a hierarchy of case classes with many properties. The only way I've found so far to populate the case classes is like this : case class Data(a: String, b: String, …
KaC
  • 501
  • 5
  • 13
14
votes
3 answers

scalacheck Arbitrary implicits and recursive generators

I'm seeing what seems to be a very obvious bug with scalacheck, such that if it's really there I can't see how people use it for recursive data structures. This program fails with a StackOverflowError before scalacheck takes over, while constructing…
Daniel Martin
  • 21,725
  • 6
  • 46
  • 64
13
votes
1 answer

Why is my Scalacheck/Scalatest PropertyCheckConfig being ignored?

I have a project with a lot of Scalacheck generators that is getting a GeneratorDrivenPropertyCheckFailedException with the message "Gave up after 0 successful property evaluations. 2 evaluations were discarded." I want to have it try to evaluate it…
myyk
  • 1,471
  • 15
  • 32
12
votes
2 answers

scalacheck: Generate a non empty string

What is the best way to generate a non empty string, when in the context of something like this private def createIndexFn() = { for{ someChar <- Gen.alphaString aNumber <- Gen.choose(1,100) //... } …
roundcrisis
  • 16,035
  • 14
  • 55
  • 91
11
votes
2 answers

Scalacheck generate Gen.alphastr with the same length

I need to generate strings with the same length. I can't realize how. Many thanks val s = for { x <- Gen.alphaStr } yield ...
petrn
  • 175
  • 2
  • 8
11
votes
1 answer

Scalacheck won't properly report the failing case

I've wrote the following spec "An IP4 address" should "belong to just one class" in { val addrs = for { a <- Gen.choose(0, 255) b <- Gen.choose(0, 255) c <- Gen.choose(0, 255) d <- Gen.choose(0, 255) } yield…
10
votes
2 answers

How to use Specs2 with Scalacheck to automate testing of String arguments?

The rewritten specs2 testing framework for Scala integrates automated testing with scalacheck. The examples given in the specs2 documentation on how to use scalacheck together with specs2 either use integers or more complicated custom generators as…
Steffen
  • 7,783
  • 1
  • 26
  • 34
9
votes
2 answers

How to get ScalaCheck's Arbitrary to always generate some special case values?

I'd like to have all my properties always be tested with at least a fixed set of special values in addition to some random values. I'd like to define this in my generator specification, not in every test using that generator type. For instance, if I…
mpartel
  • 4,320
  • 1
  • 22
  • 30
1
2 3
17 18