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
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

Can internal code be tested without having to mark the test code as internal?

I have an F# library with lots of non-public stuff I want to test. Currently all code that is not part of the assembly's public API are marked internal (specifically, it's placed in modules that are marked internal). I use the…
cmeeren
  • 3,890
  • 2
  • 20
  • 50
4
votes
2 answers

Customise FsCheck output

I am testing with FsCheck and NUnit in VisualStudio. The problem currently is: I managed to generate random graphs (for testing some graph functionality) but when a test fails, FsCheck spits out the whole graph and it does not use ToString so it…
Friedrich Gretz
  • 535
  • 4
  • 14
4
votes
1 answer

How to create a generator with a fixed list of items for FsCheck

I originally tried to create a generator that have the first 5 elements fixed (and on any test using Prop.forAll the first five would always run), but failed in doing so. Now I am trying to simplify this by having one generator for random data…
Abel
  • 56,041
  • 24
  • 146
  • 247
4
votes
1 answer

How do I implement multiple argument generation using FsCheck?

How do I implement multiple argument generation using FsCheck? I implemented the following to support multiple argument generation: // Setup let pieces = Arb.generate |> Gen.filter (isKing >> not) |>…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
4
votes
1 answer

How do I write a FsCheck generator for an interface in C#

Suppose I have an interface IPerson with 2 read properties age (int) and name (string). I also have a class Person implementing IPerson. How do I write a FsCheck generator for generating instances of IPerson type?
sthiers
  • 3,489
  • 5
  • 34
  • 47
4
votes
1 answer

Is size value used for a Gen's sample taking a custom generator?

I'm generating custom data using FsCheck's Gen. Suppose you have a function returning Gen<'T>: let chooseRectangle widthMax heightMax offset = gen { let! left = Gen.choose(0, widthMax-offset) let! top = Gen.choose(0,…
Horia Toma
  • 1,099
  • 2
  • 17
  • 29
4
votes
1 answer

How do I create an Arbitrary for a System.Type?

I am attempting to initialize my model entities using FsCheck. The models live in C# and are normally initialized via Entity Framework via their private setters. For example (contrived): public class Model { public string One { get; private set;…
Daws
  • 692
  • 4
  • 11
4
votes
2 answers

FsCheck test change the range of values used for testing

My code is automatically testing for values from -99 to 99 while using FsCheck. Check.Quick test where my test function takes integer values. I would like to test using values from 1 to 4999.
Philip John
  • 5,275
  • 10
  • 43
  • 68
3
votes
2 answers

FsCheck: Override generator for a type, but only in the context of a single parent generator

I seem to often run into cases where I want to generate some complex structure, but a special variation with a member type generated differently. For example, consider this tree type Tree<'LeafData,'INodeData> = | LeafNode of 'LeafData |…
farlee2121
  • 2,959
  • 4
  • 29
  • 41
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
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
3
votes
2 answers

Using FsCheck to Generate Records

I'd like to use FsCheck (with XUnit) to create records of type: type QueryRequest = {Symbol: string; StartDate: DateTime; EndDate: DateTime} where Symbol is limited to 3 options - ORCL, IBM, AAPL, and StartDate and EndDate are limited to the range…
Ari
  • 4,121
  • 8
  • 40
  • 56
3
votes
1 answer

Formulate an Arbitrary for pair of lists of ints of the same length

I need some help to do this exercise about generators in f#. The functions List.zip : ('a list -> 'b list -> ('a * 'b) list) and List.unzip : (('a * 'b) list -> 'a list * 'b list) are inverse of each other, under the condition that they operate…
bennius
  • 111
  • 7
3
votes
1 answer

"file may be locked by F# Interactive process" when opening FsCheck

When i try to open FsCheck through #r "FsCheck" open FsCheck commands, in a .fsx file, i get this error. Tried googling but noone of the answers i found solved my problem. #r "FsCheck" - open FsCheck;; --> Referenced '/*/FsCheck.dll' (file may…
A.Fish
  • 143
  • 11
1 2
3
10 11