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
8
votes
1 answer

Difference between ScalaCheck Arbitrary[T] and Scalacheck Gen[T]

In my tests I am making quite an extensive usage of Specs2 + ScalaCheck and there are some patterns to factor out. I still haven't found out if my functions should use an Arbitrary[T] or a Gen[T], since they are very similar: sealed abstract class…
Edmondo1984
  • 17,841
  • 12
  • 55
  • 99
8
votes
3 answers

How can I test Java programs with ScalaCheck?

I have read in the ScalaCheck user guide that it's a tool for testing Scala and Java programs. I wonder, is it just marketing, or testing Java-only codebase with it would be a reasonable idea? And if so, what's the best way to integrate it with the…
siledh
  • 3,000
  • 1
  • 14
  • 28
8
votes
4 answers

Scalacheck: Generate list corresponding to list of generators

I want to generate a list of integers corresponding to a list of generators in ScalaCheck. import org.scalacheck._ import Arbitrary.arbitrary val smallInt = Gen.choose(0,10) val bigInt = Gen.choose(1000, 1000000) val…
dips
  • 1,557
  • 13
  • 21
7
votes
1 answer

Why does sbt give "object scalacheck is not a member of package org" after successful scalacheck resolve?

I have added the following in build.sbt: libraryDependencies <<= scalaVersion { scala_version => Seq( "org.scalacheck" %% "scalacheck" % "1.10.0" % "test", ) } Upon compile the project in sbt, the dependencies…
dips
  • 1,557
  • 13
  • 21
6
votes
2 answers

Is ScalaCheck's Gen.pick really random?

I observed the following unexpected behaviour when using ScalaCheck's Gen.pic, which (for me) indicates that its picking is not quite random, even though its documentation says so: /** A generator that picks a given number of elements from a list,…
bugfoot
  • 657
  • 4
  • 17
6
votes
1 answer

Scalacheck Shrink

I am fairly new to ScalaCheck (and Scala entirely) so this may be a fairly simple solution I am using ScalaCheck to generate tests for an AST and verifying that the writer/parser work. I have these files AST.scala package com.test object Operator…
Chase Walden
  • 1,152
  • 1
  • 11
  • 30
6
votes
0 answers

Is it possible to automatically derive a sealed trait family/ADT?

I have a method that is able to persist any type, as long as that type has a io.circe.Encoder[A] instance, something like this: def persist[A](a: A)(implicit ea: Encoder[A]): Boolean Now while testing this, I can create any old case class, or set…
Noel M
  • 14,881
  • 7
  • 35
  • 45
6
votes
2 answers

ScalaCheck: choose an integer with custom probability distribution

I want to create a generator in ScalaCheck that generates numbers between say 1 and 100, but with a bell-like bias towards numbers closer to 1. Gen.choose() distributes numbers randomly between the min and max value: scala> (1 to 10).flatMap(_ =>…
jjst
  • 2,363
  • 1
  • 17
  • 33
6
votes
1 answer

PlayFramework + ScalaTest + ScalaCheck

I'm using the frameworks mentioned in the title with the following configuration: "com.typesafe.play" % "sbt-plugin" % "2.4.2" "org.scalacheck" %% "scalacheck" % "1.12.4" % "test" "org.scalatest" %% "scalatest" % "2.2.5" %…
Taig
  • 6,172
  • 4
  • 37
  • 63
6
votes
1 answer

Generate Strings from Grammar in ScalaCheck

In Scala, I have a grammar implemented using the Parser Combinators library. Now, what I want to do is generate random strings given a grammar from the parser combinators library. It seems to me, that what the ScalaCheck library does it somehow the…
Felix
  • 7,999
  • 10
  • 37
  • 58
6
votes
1 answer

ScalaCheck - Ordered array generator

I am trying out ScalaCheck for the first time and I want to generate an ordered array of Ints. I read the documentation and did some search but I didn't find a way to do it. Can someone shed some light on this? Thanks
rmorais
  • 219
  • 1
  • 5
6
votes
2 answers

How to display entire stack trace for thrown exceptions from ScalaCheck tests?

I'm running ScalaCheck tests in sbt, and if my test fails because the code under test throws an exception, the test report shows the failed test, the thrown exception and the message, but not the entire stack trace (note the mere Exception:…
Martijn
  • 11,183
  • 10
  • 46
  • 92
6
votes
2 answers

How to get ScalaTest correctly reporting tests results when using scalacheck with Propspec and PropertyCheck?

I'd like to test my scala program using property based testing with scalacheck. I wrote : class MyProperties extends PropSpec with PropertyChecks { property("My property") { val myProperty: org.scalacheck.Prop = new MyProperty //…
ygu
  • 245
  • 1
  • 15
5
votes
1 answer

Help with ScalaCheck

I'd like to use ScalaTest's Checkers trait to use ScalaCheck from ScalaTest cases. A simple case I'm playing with is: test("can create local date UTC from millis") { check(localDate.toTimestampUTC.toLocalDateUTC == localDate) } I need to…
Alex Baranosky
  • 44,548
  • 39
  • 95
  • 146
5
votes
2 answers

ScalaCheck specificy minimum successful tests for property

I'm trying to make sure that my ScalaCheck property runs 500 times instead of the default 100 times. I'm having trouble configuring this though. class BlockSpec extends Properties("BlockSpec") with BitcoinSLogger { val myParams =…
Chris Stewart
  • 1,554
  • 1
  • 27
  • 58
1
2
3
17 18