Questions tagged [property-based-testing]
144 questions
5
votes
1 answer
How to change max number of test cases generated by hypothesis?
The famous property-based testing framework hypothesis is capable to generate massive test case.
But is there any way to restrict the quantity of test case generated by hypothesis in order to make testing period shorter?
For example feeding specific…

Audra Jacot
- 139
- 7
5
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
- 1,199
- 15
- 26
5
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
- 2,109
- 2
- 20
- 32
5
votes
1 answer
Test valid state transitions with scalacheck
Suppose I have this class:
case class Receipt(id: Long, state: String) {
def transitionTo(newState: String) = {
if (!canTransitionTo(newState)) {
throw new IllegalStateExcetion(s"cant transition from $state to $newState")
}
…

Pablo Fernandez
- 103,170
- 56
- 192
- 232
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
- 11,206
- 11
- 54
- 118
5
votes
2 answers
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
- 8,385
- 10
- 40
- 59
4
votes
1 answer
Is there a simpler way to test all permutations with Kotest property-based testing?
I'm working with kotlin + Kotest property testing and trying to test all permutations of 2 parameters with list generators like this:
"Some test"{
forAll(4 ,
Exhaustive.collection(listOf(
"a",
…

janicedn
- 53
- 5
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…

Anentropic
- 32,188
- 12
- 99
- 147
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,907
- 1
- 21
- 34
4
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
- 137
- 8
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…

Zaphod
- 1,387
- 2
- 17
- 33
3
votes
3 answers
How to enforce relative constraints on hypothesis strategies?
Say I have 2 variables a and b where it is given that b > a, how then can I enforce this relative constraint on the hypothesis strategies?
from hypothesis import given, strategies as st
@given(st.integers(), st.integers())
def test_subtraction(a,…

MShakeG
- 391
- 7
- 45
3
votes
0 answers
How to check async method throws with FsCheck?
I want to define async property which is about throwing an exception asynchronously.
However, I could find only Prop.throws which accepts lazy, but not Asyn, Task or ValueTask.
Isn't async supported?

Pavel Voronin
- 13,503
- 7
- 71
- 137
3
votes
0 answers
How do I write a Hedgehog generator for a wrapped function?
I'm currently working through the book Thinking with Types. In the third chapter Variance, the author provides an exercise in which the reader should implement the functor instance for T1.
newtype T1 a = T1 (Int -> a)
I found a couple of ways to…

Jezen Thomas
- 13,619
- 6
- 53
- 91
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
- 2,959
- 4
- 29
- 41