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
0
votes
0 answers

Using FsCheck.Xunit in C#, how do I clean up/tear down after all tests have been executed?

I am using FsCheck - specifically the FsCheck.Xunit package - in my C# code. I want to run some setup before my tests execute and some cleanup/teardown code after my tests have all run. NUnit has a [CleanUp] attribute; Xunit uses Dispose to clean…
Claus Appel
  • 379
  • 1
  • 4
  • 13
0
votes
1 answer

How to limit the input values in FsCheck?

I have a FsCheck-Property that is like this: [Property] public Property ConversionCanBeInversedForAllUnits(double input, string unit1, string unit2) { ... } FsCheck will feed it random values. I want to limit the input of the strings to members…
Michael K.
  • 423
  • 1
  • 4
  • 13
0
votes
1 answer

FsCheck generate POCO with ICollection

I'm using xunit and FsCheck from C# to generate random class data. Because of EF some of them are containing a ICollection Children {get; set;} properties. Because of such properties generator gets stuck. I'm aware of possiblity to…
python_kaa
  • 1,034
  • 13
  • 27
0
votes
1 answer

Fsharp / how to change type Node of (string * FsTree) list into a list where 2paths cannot be identical

In FSharp, I would like to do the following given a type : type FsTree = Node of (string * FsTree) list I would like to define a predicate toStringList so that : toStringList myFsTree gives the bellow result result : [ ["n1"]; ["n2";…
0
votes
2 answers

How to pass FsCheck Test Correctly

let list p = if List.contains " " p || List.contains null p then false else true I have such a function to check if the list is well formatted or not. The list shouldn't have an empty string and nulls. I don't get what I am missing since…
wolf
  • 399
  • 1
  • 6
  • 19
0
votes
2 answers

FsCheck generator over the Cartesian product of discrete fields

Sorry to resort to math-speak in the subject line. I'll unpack it a little. I want to create an FsCheck generator of records where each field is restricted to discrete values. For instance, a shirt size can be expressed as collar and sleeve…
StevePoling
  • 319
  • 1
  • 15
0
votes
1 answer

FsCheck Generator for List with Pairwise Restrictions (C#)

Using FsCheck in C#, I need to generate a list of values where certain values may not occur next to each other. This is a list of tokens for a lexer. So for example, I need to not generate two identifiers next to each other, or a keyword next to an…
Jeff Walker Code Ranger
  • 4,634
  • 1
  • 43
  • 62
0
votes
1 answer

Using Property in fscheck with filtered items

I am just starting with FsCheck and wanted to dig a little deeper, I have the following test case: [Property] public void some_test(HttpStatusCode httpStatusCode) Now, I only want httpStatusCode which are failures, how do I achieve that using…
Ruskin
  • 1,504
  • 13
  • 25
0
votes
0 answers

FsCheck displaying exception C#

I am playing with FsCheck. And it fails on 0: [|-1; 1|] shrink: [|-1; 0|] shrink: [|1; 0|] shrink: [|0; 0|] Falsifiable, after 1 test (3 shrinks) (StdGen (1052297207,296308070)): Label of failing property: original (0,0) first sum 0, second…
A191919
  • 3,422
  • 7
  • 49
  • 93
0
votes
1 answer

Is this a good strategy for composing arbitraries?

Just started looking at FsCheck, wrote several tests, and now I am wondering what is a good strategy for composing more complex arbitraries. Is registering arbitraries within arbitrary good approach? Something like this public class…
epitka
  • 17,275
  • 20
  • 88
  • 141
0
votes
0 answers

how to use xUnit and FsCheck with IoC and mocking in F#

I want to write unit tests F# using property base testing technic. however I came across several obstacle. Code I want to test is in C# Domain objects come from EF i.e. no constructors only mutable properties sut is a class that will require a…
Icen
  • 441
  • 6
  • 14
0
votes
1 answer

How would I perform property-based testing on a card game's Deal function?

I am studying property-based testing and am curious how I would apply this type of testing to a BlackJack game's Deal function. Here's a unit test (aka: Example-based test): [] let ``deal two cards`` () = let hand = 2 let dealPlayer…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
0
votes
1 answer

Property test ran as unit test fails even though it really passes

It appears that my property test that's running as a unit test fails even though it really passes. The code is as follows: module Tests.Units open FsUnit open NUnit.Framework open NUnit.Core.Extensibility open FsCheck.NUnit open…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
0
votes
1 answer

Using FsCheck, the propertyCheck function is NOT recognized

The "propertyCheck" function that is referenced within my test method is NOT recognized when I attempt to build my test. I thought that propertyChecked was a core function of the FsCheck framework? What other ceremony do I need to perform? module…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
0
votes
1 answer

Approach to testing with FsCheck

I am trying to make the paradigm shift to FsCheck and random property-based testing. I have complex business workflows that have more test cases than I can possibly enumerate, and the business logic is a moving target with new features being…
John Zabroski
  • 2,212
  • 2
  • 28
  • 54
1 2 3
10
11