Questions tagged [property-based-testing]
144 questions
16
votes
2 answers
What to use property testing for
I'd like to know what is the property testing aiming for, what is it's sweet point, where it should be used. Let' have an example function that I want to test:
f :: [Integer] -> [Integer]
This function, f, takes a list of numbers and will square…

ryskajakub
- 6,351
- 8
- 45
- 75
15
votes
2 answers
Property based testing in PHP?
In various more functional based languages there are tools (like Quickcheck) which allow for property based testing.
How would I go about property based testing in PHP?
I would like to be able to specify the in and output properties of a PHP method,…

Ward Bekker
- 6,316
- 9
- 38
- 61
13
votes
3 answers
Difficulty thinking of properties for FsCheck
I've managed to get xUnit working on my little sample assembly. Now I want to see if I can grok FsCheck too. My problem is that I'm stumped when it comes to defining test properties for my functions.
Maybe I've just not got a good sample set of…

Benjol
- 63,995
- 54
- 186
- 268
12
votes
2 answers
What is the difference between Agitar and Quickcheck property based testing?
A number of years ago a Java testing tool called Agitar was popular. It appeared to do something like property based testing.
Nowadays - property based testing based on Haskell's Quickcheck is popular. There are a number of ports to Java…

hawkeye
- 34,745
- 30
- 150
- 304
11
votes
3 answers
Generating list of lists with custom value limitations with Hypothesis
The Story:
Currently, I have a function-under-test that expects a list of lists of integers with the following rules:
number of sublists (let's call it N) can be from 1 to 50
number of values inside sublists is the same for all sublists…

alecxe
- 462,703
- 120
- 1,088
- 1,195
9
votes
2 answers
What is the difference between Property Based Testing and Mutation testing?
My context for this question is in Python.
Hypothesis Testing Library (i.e. Property Based Testing):
https://hypothesis.readthedocs.io/en/latest/
Mutation Testing Library:
https://github.com/sixty-north/cosmic-ray

Will Flowers
- 101
- 6
8
votes
3 answers
Is it a good or a bad thing that a suite of quickcheck tests match the implementations?
I'm trying to get started with Haskell's QuickCheck, and while I am familiar with the concepts behind the testing methodology, this is the first time I am trying to put it to use on a project that goes beyond testing stuff like reverse . reverse ==…

danbroooks
- 2,712
- 5
- 21
- 43
8
votes
1 answer
Skipping falsifying examples in Hypothesis
The Story:
I'm currently in the process of unit-testing a function using hypothesis and a custom generation strategy trying to find a specific input to "break" my current solution. Here is how my test looks like:
from solution import answer
#…

alecxe
- 462,703
- 120
- 1,088
- 1,195
7
votes
1 answer
Difference between generating random input through 'Gen' or through 'forAll' in Hedgehog
Suppose, I want to test the following associativity property for Sum with the help of hedgehog library in Haskell:
a <> (b <> c) ≡ (a <> b) <> c
I have actually two ways to generate random input.
1. Generate all in Gen (using Gen's Applicative and…

Shersh
- 9,019
- 3
- 33
- 61
7
votes
1 answer
Safest way to generate random GADT with Hedgehog (or any other property-based testing framework)
I have GADT like this one:
data TType a where
TInt :: TType Int
TBool :: TType Bool
I want to have a function like this one:
genTType :: Gen (TType a)
Which can generate random constructor of TType type. I can do this simply by creating…

Shersh
- 9,019
- 3
- 33
- 61
6
votes
1 answer
FsCheck: How to generate test data that depends on other test data?
FsCheck has some neat default Arbitrary types to generate test data. However what if one of my test dates depends on another?
For instance, consider the property of string.Substring() that a resulting substring can never be longer than the input…

Good Night Nerd Pride
- 8,245
- 4
- 49
- 65
6
votes
2 answers
Expecto FsCheck getting stack overflow exception when generating string
I'm trying to learn how to use FsCheck properly, and integrating it with Expecto at the moment. I can get property tests to run if I'm using the default FsCheck config, but when I try to use my own Generator, it causes a stack overflow…

kaeedo
- 458
- 2
- 13
6
votes
1 answer
How to use FsCheck to generate random numbers as input for property-based testing
I thought it's time to try out FsCheck but it proves tougher than I thought. There's a lot of documentation on Arb, generators and so on, but there doesn't seem to be any guidance in how to apply that knowledge. Or I'm just not getting it.
What may…

Abel
- 56,041
- 24
- 146
- 247
6
votes
3 answers
How can I re-try a property-based-test if the randomly-generated inputs are not useful?
I am a n00b to unit testing. I have installed FsCheck.Nunit and NUnitTestAdapter from Nuget, and I'm trying to do property-based-testing, largely inspired by the inestimable Scott Wlaschin.
I am using the [] attribute, and I would like the…

Overlord Zurg
- 3,430
- 2
- 22
- 27
6
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
- 21,881
- 15
- 82
- 180