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 .

275 questions
4
votes
2 answers

how to use forAll in scalatest to generate only one object of a generator?

Im working with scalatest and scalacheck, alsso working with FeatureSpec. I have a generator class that generate object for me that looks something like this: object InvoiceGen { def myObj = for { country <- Gen.oneOf(Seq("France",…
Joe
  • 2,543
  • 3
  • 25
  • 49
4
votes
1 answer

suchThat usages in ScalaCheck

I'm learning scala by reading the code from ScalaCheck and find many combinators are suffixed by suchThat. However, in many cases suchThat doesn't look quite necessary. I'm wondering why they are designed in this way. Here's some excerpted from…
cfchou
  • 1,239
  • 1
  • 11
  • 25
4
votes
1 answer

Create custom Arbitrary generator for testing java code from ScalaTest ScalaCheck

Is it possible to create a custom Arbitrary Generator in a ScalaTest (which mixins Checkers for ScalaCheck property) which is testing Java code? for e.g. following are the required steps for each test within forAll val fund = new Fund() val…
user2066049
  • 1,371
  • 1
  • 12
  • 26
4
votes
2 answers

generating *interesting* strings at random in Java

I've been using ScalaCheck for automatic unit testing. Its default String generator (i.e., its default Arbitrary[String] instance) is a little too powerful, generally producing an unreadable jumble made up mainly of characters I'm not trying to…
Yuvi Masory
  • 2,644
  • 2
  • 27
  • 36
3
votes
1 answer

How to override some generators for ScalaCheck to force to (automatically) generate refined types? Non empty lists only, for example

I have a quite big structure of case classes and somewhere deep inside this structure I have fields which I want to refine, for example, make lists non-empty. Is it possible to tell ScalaCheck to make those lists non-empty using automatic derivation…
Albert Bikeev
  • 375
  • 6
  • 16
3
votes
1 answer

A property over positive numbers shouldn't shrink to negative numbers

In ScalaCheck, I have a property test that uses a generator of positive integers that when it fails ScalaCheck will shrink to a non-positive value. Shrinking is supposed to help find the minimal failing case. Shrinking to values outside of the…
ashawley
  • 4,195
  • 1
  • 27
  • 40
3
votes
2 answers

How do I shrink a list but guarantee it isn't empty?

In ScalaCheck, I have written a generator of non-empty lists of strings, val nonEmptyListsOfString: Gen[List[String]] = Gen.nonEmptyListOf(Arbitrary.arbitrary[String]) And then, assume I wrote a property using…
ashawley
  • 4,195
  • 1
  • 27
  • 40
3
votes
1 answer

Scalacheck Try: Monadic Associativity law passes with generated functions

When i run the following property it passes: import org.scalacheck.Prop.forAll import scala.util.Try forAll { (m: Try[String], f: String => Try[Int], g: Int => Try[Double]) => m.flatMap(f).flatMap(g) == m.flatMap(x =>…
jen
  • 357
  • 2
  • 10
3
votes
1 answer

Combine scalacheck Gen with Future In Scala

Basically I am trying to make generators which are the result of HTTP requests, due to this I often end up with types like Gen[EitherT[Future, Error, T]]. The problem is that there doesn't appear to be any monadic instances (so I can do sequence, or…
mdedetrich
  • 1,899
  • 1
  • 18
  • 29
3
votes
1 answer

How to get pretty output from specs+scalacheck with maven?

When I run Specs + Scalacheck tests with IDEA, I get nice pretty output: Specification "CoreSpec" The core grammar should + parse any encoded string + fail to parse an empty encoded string + parse an expected empty string +…
3
votes
2 answers

Testing Recursive Data Structure

ScalaCheck: The Definitive Guide explains how to create generators for recursive data structures. First, it defines the data structure: trait Tree[T] { def size: Int } case class Leaf[T](item: T) extends Tree[T] { def size = 1 } case class…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
3
votes
1 answer

Scalacheck nested forall throws "oneOf called on empty collection" on failure in Scalatest test

I have a nested forAll call which depends on the value generated by the previous one. This value is a collection that should not be empty according to its generator's definition: "test" in { val listGen: Gen[List[Int]] = Gen.listOfN(3,…
3
votes
1 answer

Generating arbitrary A => Date with scalacheck

I'm running in an odd issue with scalacheck 1.13.3: arbitrary instances of A => java.util.Date generate different values depending on the time they are called. Here's a concrete, reproducible example: import org.scalatest.FunSuite import…
Nicolas Rinaudo
  • 6,068
  • 28
  • 41
3
votes
1 answer

ScalaCheck, different behaviour when calling Test.check or Test.checkProperties

I have the following code that uses ScalaCheck properties to test some class package quickcheck.tests import org.scalacheck.Arbitrary._ import org.scalacheck.Gen._ import org.scalacheck.Prop._ import org.scalacheck._ import…
Josep M Beleta
  • 581
  • 4
  • 19
3
votes
2 answers

How do I ensure that alphaStr does not generate empty strings?

I am using the ScalaCheck generator alphaStr to generate Strings but they always come back empty. For eg. the following test fails on the first string. class GenSpec extends FunSuite with GeneratorDrivenPropertyChecks with Matchers { implicit val…
Saket
  • 3,079
  • 3
  • 29
  • 48