Questions tagged [fscheck]

FsCheck is a framework for random testing of .NET programs. FsCheck is a port of Haskell's QuickCheck written in F#.

FsCheck is a framework for random testing of .NET programs. FsCheck is a port of Haskell's QuickCheck written in F#.

To test a program with FsCheck, you provide a specification of the program, in the form of properties which functions, methods or objects should satisfy, and FsCheck then tests that the properties hold in a large number of randomly generated cases. While writing the properties, you are actually writing a testable specification of your program. Specifications are expressed in F#, C# or VB, using a flexible and clean API. It sounds lofty, but it's more fun than unit testing!

You can write properties, observe the distribution of test data, and define test data generators. When a property fails, FsCheck automatically displays a minimal counter example - this process, called shrinking, is very useful to quickly find the bug. Instead of digging through a potentially large randomly generated test case to find the part that actually triggers the bug, FsCheck can do that work for you!

151 questions
6
votes
1 answer

Why am I not able to use the latest version of NUnit and FsCheck with F#?

I would like to use the latest versions of NUnit, FsCheck, and F#. However, when I point to the latest versions of my packages, my unit tests do not get discovered. However, my property-based tests are discovered (i.e. FsCheck). My packages are the…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
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
1 answer

FsCheck Generators by Selecting From Pools of Possibilities

Is there a way to generate a string in FsCheck by selecting just one item from each of a list of strings and then concatenating the result? I'm just completely stuck and can't seem to figure it out. I've looked at the docs and in the github repo…
Thomas Sobieck
  • 1,416
  • 1
  • 20
  • 27
5
votes
3 answers

Using FSCheck generators

I have a function to generate doubles in a range: let gen_doublein = fun mx mn -> Arb.generate |> Gen.suchThat ( (>) mx ) |> Gen.suchThat ( (<) mn ) and then a function to generate an array of 2 of these: let gen_params:Gen
b1g3ar5
  • 335
  • 2
  • 9
5
votes
2 answers

In FsCheck, how to generate a test record with non-negative fields?

In F#, I have a record with a few fields: type myRecord = { a:float; b:float; c:float } I am using FsCheck to test some properties which use this record. For (a contrived) example, let verify_this_property (r:myRecord) = myFunction(r) =…
David H
  • 1,461
  • 2
  • 17
  • 37
5
votes
1 answer

What is a concise, general method of property testing against nan values in F#?

I am doing some property testing in F# using FsCheck. I therefore wish to guarantee that certain conditions always hold, regardless of input arguments. Consider I define a trivial identity function for float values. let floatId (x : float) = x I…
TheInnerLight
  • 12,034
  • 1
  • 29
  • 52
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
1 answer

fscheck generating string with size between min & max

I try to write a FsCheck generator that generates strings with length in a given interval. My attempt is the following: let genString minLength maxLength = let isValidLength (s : string) = s.Length >= minLength && s.Length <=…
vidi
  • 2,056
  • 16
  • 34
5
votes
2 answers

Preventing FsCheck from generating NaN and infinities

I have a deeply nested datastructure with floats all over the place. I'm using FsCheck to check if the data is unchanged after serializing and then deserializing. This property fails, when a float is either NaN or +/- infinity, however, such a case…
phaz
  • 872
  • 9
  • 23
5
votes
2 answers

How to guarantee FsCheck reproducibility

We want to use FsCheck as part of our unit testing in continuous integration. As such deterministic and reproducible behaviour is very important for us. FsCheck, being a random testing framework, can generate test cases that potentially sometimes…
Daniel Fabian
  • 3,828
  • 2
  • 19
  • 28
5
votes
2 answers

FsCheck and NUnit integration

I want to integrate FsCheck tests with NUnit tests. Specifically, when I declare several FsCheck properties, I want them to be visible and runnable from the VS runner. I have found the following description of xUnit usage alongside FsCheck (under…
Lakret
  • 127
  • 2
  • 7
4
votes
1 answer

Can't figure out how to make a generator from a generator

I'm having trouble figuring out how to make fscheck generators WITHOUT using the gen workflow syntax and assume there must be a good way to do it. I end up with a nested Gen
JustinM
  • 913
  • 9
  • 24
4
votes
1 answer

Does F# have a language construct to access the lexical scope (like python locals()/globals())

When writing tests in F# I am trying to generate useful messages about the state that caused errors. In python I would include all the locals(), so they are easily accessible in the test trace. Is there a similar construct in F#? I have been…
4
votes
3 answers

Generating custom data in FsCheck

I’ve got an FsCheck question: I have the following record type (and I say upfront, I have been told that my Single-Case DUs are maybe an overkill, but I find them descriptive of the domain, and therefore necessary, and I will not remove them unless…
user2369099
4
votes
1 answer

How to make FsCheck generate random strings that respect MaxLengthAttribute?

Is it possible for FsCheck to generate random records that respect the MaxLengthAttribute. Example record type: type Person = { Id: int [] FirstName: string …
bbqfrito
  • 198
  • 2
  • 9
1
2
3
10 11