Questions tagged [property-based-testing]
144 questions
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,558
- 23
- 30
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
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
- 4,000
- 8
- 42
- 73
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
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
- 14,435
- 1
- 30
- 57
3
votes
1 answer
Negative Property-Based Tests
Property-based testing is good when you can express simple and well-defined properties.
I've also had luck with "negative properties" in the case of testing parsers, e.g. by generating invalid identifiers or mismatching indentation for…

sshine
- 15,635
- 1
- 41
- 66
3
votes
2 answers
clojure.test.check generate two ints, one less than the other
I want to write a property like the following:
(prop/for-all [x (gen/nat)
y (gen/nat)]
(= (g x y) (f x y)))
However, the property only holds when x > y. What is the correct way to express that precondition for this property?…

Dan Burton
- 53,238
- 27
- 117
- 198
3
votes
2 answers
Does property based testing make you duplicate code?
I'm trying to replace some old unit tests with property based testing (PBT), concreteley with scala and scalatest - scalacheck but I think the problem is more general. The simplified situation is , if I have a method I want to test:
def…

Chirlo
- 5,989
- 1
- 29
- 45
3
votes
1 answer
Check for unexpected exceptions using ScalaTest + ScalaCheck
I'm trying to write a property that basically states "it should either not throw an exception, or throw one of a list of possible exceptions" using ScalaTest and it's GeneratorDrivenPropertyChecks which in turn uses scalatest. The issue is that I…

c089
- 4,951
- 2
- 25
- 37
2
votes
1 answer
Can QCheck (OCaml property-based testing library) be used to perform exhaustive testing?
Regarding the OCaml QCheck library (https://github.com/c-cube/qcheck),
say we have a complete generator g: typ Gen.t for a finite type typ or a finite subset s: typ -> bool of typ, is it possible (with or without resorting to hacky techniques and/or…

haochenx
- 143
- 1
- 4
2
votes
0 answers
FP in Scala: How is test cases per random generator size calculated?
Chapter 8 in FP in Scala talks about property based testing and covers how to build a library from scratch. A high level summary of the API is included below:
//generator of random test cases
case class Gen[+A](sample: State[RNG,A])
…

Rupam Bhattacharjee
- 359
- 1
- 10
2
votes
1 answer
when to use Property-Based Testing?
I am trying to learn Propery-Based Testing(PBT)I think I know how to implement it but when should I apply PBT?
For example in this case I am trying to compare if the function getCurrentName() returns the expected name. Should I randomize this…

jorge.munin
- 27
- 1
- 5
2
votes
1 answer
How to come up with properties in propety based testing
This question applies to any particular programming language.
Let us imagine I have a function that converts a data structure to a string of hex.
func toHex(input: data) => string
Let's say I now want to use property based testing to test this. How…

Finlay Weber
- 2,989
- 3
- 17
- 37
2
votes
3 answers
How do I generate random email addresses in test.check?
I'm trying to use gen/fmap with two random alphanumeric strings. Then I concatenate them with "@" and append ".com". But I'm struggling with the syntax.
First attempt:
(gen/fmap str (gen/string-alphanumeric) "@" (gen/string-alphanumeric)…

triplej
- 269
- 4
- 9
2
votes
3 answers
Does non-deterministic nature of property-based testing hurt build repeatability?
I am learning FP and got introduced to the concept of property-based testing and for someone from OOP world PBT looks both useful and dangerous. It does check a lot of options, but what if there is one (or some) options that fail, but they didn't…

Leonid Bor
- 2,064
- 6
- 27
- 47