Questions tagged [property-based-testing]

111 questions
5
votes
1 answer

When implementing property-based testing, when should I use an input generator over a precondition expression?

When implementing property-based testing, when should I use an input generator over a precondition expression? Are there performance considerations when selecting a particular option? Internally, does one method inevitably use the other? I would…
Scott Nimrod
  • 10,451
  • 8
  • 46
  • 94
5
votes
1 answer

Scalacheck, generator for lists between size 5 and 12

I can find many examples of setting maximum sizes for generators, but how do I generate lists between a min and max length?
Felix
  • 7,999
  • 10
  • 37
  • 58
5
votes
2 answers

Why should I really use Property-based testing if I already practice Example-based testing?

One caveat that some developers argue about TDD with Example-based tests is the possible lack of every valid input handling. Let's take a simple example where those developers could argue: Make a program that add two numbers. Bob, a developer…
Mik378
  • 20,929
  • 13
  • 73
  • 163
4
votes
1 answer

Sharing elements between generated objects in ScalaCheck using nested forAll

Started coding in Scala fairly recently and I tried to write some property based test-cases. Here, I am trying to generate raw data which mimics the system I am testing. The goal is to first generate base elements (ctrl and idz), then use those…
Ic3fr0g
  • 970
  • 13
  • 26
4
votes
1 answer

Hypothesis equivalent of QuickCheck frequency generator?

As a learning project I am translating some Haskell code (which I'm unfamiliar with) into Python (which I know well)... The Haskell library I'm translating has tests which make use of QuickCheck property-based testing. On the Python side I am using…
4
votes
0 answers

How to use `GenT` in `hedgehog`

In the hedgehog library, there is a GenT monad transformer. However the forAll function takes a Gen type. There is a forAllT function, but it is in an Internal module. So if I'd like to use a generator monad transformer with a specific monad (say…
Damian Nadales
  • 4,603
  • 1
  • 20
  • 30
4
votes
1 answer

How does Clojure spec differ from property-based testing libraries, such as Haskell QuickCheck?

Other languages have property based testing libraries, like Haskell QuickCheck. How does Clojure spec differ from such libraries? Or is it just a property based testing framework for Clojure?
dilvan
  • 1,730
  • 1
  • 15
  • 26
4
votes
1 answer

Pattern for generating negative Scalacheck scenarios: Using property based testing to test validation logic in Scala

We are looking for a viable design pattern for building Scalacheck Gen (generators) that can produce both positive and negative test scenarios. This will allow us to run forAll tests to validate functionality (positive cases), and also verify that…
Zac
  • 1,278
  • 1
  • 15
  • 27
3
votes
1 answer

FsCheck with Setup and Teardown

Summary Are there any events that can be run before every property case so that I can run setup and teardown for each run of a property? Full version I want to be able to test paired behaviors like "I can always fetch written records" or "output of…
farlee2121
  • 1,452
  • 1
  • 17
  • 33
3
votes
1 answer

How can I keep the transformation of arbitrary proptest values out of the test case body?

I want to thoroughly test an implementation of the intersection of two BTreeSets. I can write: use self::proptest::prelude::*; proptest! { #[test] fn intersect_this(s1: BTreeSet, s2: BTreeSet) { // ... } } But this has…
Stein
  • 1,297
  • 17
  • 25
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
  • 357
  • 5
  • 13
3
votes
2 answers

How to generate tuples by FsCheck

This is a json generation : let strGen = Arb.Default.String() |> Arb.toGen strGen |> Gen.arrayOf |> Gen.map (String.concat "\", \"") |> Gen.map (fun strs -> "[\"" + strs + "\"]") How can I have the string that the json…
Mohsen
  • 3,224
  • 7
  • 32
  • 62
3
votes
1 answer

C#, xunit, fscheck, writing a simple property based test using a custom generator or constrained random string

I am trying to solve the diamond kata in order to learn how to write property based tests with the fscheck library. I want to write the tests with C# and I am using Visual Studio 2017. I want to write a property based test that does not generate any…
Shakka
  • 127
  • 7
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
  • 38,251
  • 58
  • 190
  • 340
3
votes
3 answers

Generating unique strings in FsCheck

I need generate unique non-null strings to be used as Dictionary keys. I tried something like: public static Gen> UniqueStrings() { return from s in Arb.Default.NonNull().Generator select s; } Then I use…
rexcfnghk
  • 11,625
  • 1
  • 30
  • 55