Questions tagged [property-based-testing]
144 questions
1
vote
1 answer
How to use Property-based testing using FsCheck.NUnit or XUnit?
I new to property-based and unit testing, and in my project I want to to use this technique, but unfortunately it is easy to say... I watched a talk about FsCheck.XUnit library, but the guy was testing numeric function (modulus)... And I want to…

alex_z
- 416
- 5
- 12
1
vote
1 answer
Force specific input with JSVerify
I'm starting to use JSVerify for property based testing.
Given a function (just an example) that accepts a string as parameter, I use JSVerify to pass in a large number of arbitrary strings and see if the function behaves as intended for all of…

abl
- 5,970
- 4
- 25
- 44
1
vote
1 answer
How to accumulate a list of FsCheck generators into a single value?
I wrote an FsCheck generator that yields random glob syntax patterns (e.g. a*c?) along with a random string that matches the pattern (e.g. abcd). However my solution uses a mutable variable and I'm rather ashamed of that. Have a look:
open…

Good Night Nerd Pride
- 8,245
- 4
- 49
- 65
1
vote
1 answer
ScalaCheck not failing?
I'm trying to use ScalaTest with ScalaCheck to do property based testing. I've got the tests outlined below:
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, Matchers}
object Calc {
def add(a:Int, b:Int) = a+b
def…

ashic
- 6,367
- 5
- 33
- 54
1
vote
0 answers
How can I Property-based Test a Function that takes a list of functions?
How can I Property-based Test a Function that takes a list of functions?
Take the following function:
let handleAll handlers item =
handlers |> List.collect(fun handler -> handler item)
Additional context is as follows:
let handleAll handlers…

Scott Nimrod
- 11,206
- 11
- 54
- 118
1
vote
1 answer
How can I interpret property based test code?
How can I interpret property based test code?
I'm struggling to translate the instructions on the following snippet:
let myProperty = Prop.forAll fiveAndThrees <| fun number ->
let actual = transform number
let expected =…

Scott Nimrod
- 11,206
- 11
- 54
- 118
1
vote
1 answer
In Erlang's PropEr, how to get a sample of a generator?
I'm using PropEr to write my property based test.
How can I see what kind of data my generator produces?
Let's say I have the following generator:
-module(my).
-include_lib("proper/include/proper.hrl").
-export([valid_type_gen/0]).
valid_type_gen()…

aronisstav
- 7,755
- 5
- 23
- 48
1
vote
1 answer
Calling default FsCheck generator from a custom generator of the same type
I defined a type with a few custom generators to make FsCheck generate customized instances of a few types. But for one of the complex types I want to use default FsCheck generation first and then adjust the result. Here's a (simplified) code:
type…

Vagif Abilov
- 9,835
- 8
- 55
- 100
1
vote
2 answers
Property-based test continues to pass when I expect it to fail
I'm sure this is trivial. However, the following test will always pass:
let transform number =
match number % 3, number % 5 with
| 0, 0 -> "FizzBuzz"
| _, 0 -> "Buzz"
| 0, _ -> "Fizz"
| _ -> number.ToString()
[]
let…

Scott Nimrod
- 11,206
- 11
- 54
- 118
1
vote
1 answer
Why is my precondition being ignored on my Property-based test?
Why is my precondition being ignored on my Property-based test?
The precondition for my test is the following:
fun rowCount -> rowCount >= 0
Thus, my actual test is:
[]
let ``number of cells in grid equals rowcount squared`` () =
…

Scott Nimrod
- 11,206
- 11
- 54
- 118
1
vote
1 answer
Generate events/commands using a property based testing tool?
As I understand it, most property testing tools operate at the level of functions. Given a set of arguments, such tools will generate random input and test output against some invariant.
I have read that ScalaCheck is now starting to include…

Shahbaz
- 10,395
- 21
- 54
- 83
1
vote
0 answers
Generating random objects as test cases
This question is part of larger question that can be found here
We have classes that come from Entity Framework. In other words they are not Records that are immutable they are quite posit list of mutable properties without constructor. FsCheck…

Icen
- 441
- 6
- 14
1
vote
1 answer
property-based-test for simple object validation
consider this simple example:
Theres a Person object
It must have one of: FirstName and LastName (or both, but one is mandatory)
It must have a valid Age (integer, between 0 and 150)
How would you property-base-test this simple case?

Pablo Fernandez
- 103,170
- 56
- 192
- 232
0
votes
0 answers
How to create and compare syrupy snapshots in hypothesis's stateful testing?
I want to create a hypothesis.stateful.RuleBasedStateMachine to run stateful testing in Python. When the test is running, I want it to be deterministic and either update some snapshots or compare with existing, so that I can manually review whether…

Yang Bo
- 3,586
- 3
- 22
- 35
0
votes
0 answers
How to rerun ScalaCheck Commands tests given a seed
I have a scalacheck Commands test suite. When I run it it fails in a particularly interesting way, and prints out a seed. I would like to re-run the tests with that seed.
I've tried the following:
sbt Test/runMain MyTest -initialSeed

Jonas Kölker
- 7,680
- 3
- 44
- 51