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
3
votes
1 answer

Not empty string generator with FsCheck using c# fluent interface

I'm trying to create a not empty string generator but when running the test I still have empty strings as inputs. Here is the code I wrote: [Test] public void MyTest() { Func> generateNotEmptyString = () => { …
user1095973
3
votes
1 answer

Properties throw off xUnit and the Test Explorer

I'm trying to figure out how to set up and use FsCheck by going through the following blog post: http://www.clear-lines.com/blog/post/FsCheck-2b-XUnit-3d-The-Bomb.aspx I've tried my best to mimic the whole process in the post, and everything works…
phaz
  • 872
  • 9
  • 23
3
votes
1 answer

In FsCheck.XUnit, how do I get verbose checking?

How do I get the runs generated when using [] to use the Check.VerboseAll style of generation?
nimish
  • 4,755
  • 3
  • 24
  • 34
3
votes
0 answers

Assembly redirect in multiple environment / eg, for F# 4.0.0.0

I received a new machine and thought plugging in some machine wide redirect would just work for my FsCheck tests would work like in my previous machine. That was not the case, and I received a similar error than on my old machine so I knew that it…
nicolas
  • 9,549
  • 3
  • 39
  • 83
3
votes
1 answer

How do I just generate data with fscheck?

Is it possible to generate data, specifically a list, with fscheck for use outside of fscheck? I'm unable to debug a situation in fscheck testing where it looks like the comparison results are equal, but fscheck says they are not. I have this…
Jack Fox
  • 953
  • 6
  • 20
2
votes
2 answers

FSCheck generating lists of a specific size

Probably a stupid question, but how do I generate a list of a specific size for FSCheck? I can restrict using: let fn_of_2_check xs = (xs.Length=2) ==> fn_of_2 xs but, obviously, this will throw away loads of lists. Here fn_of_2 does some test on…
b1g3ar5
  • 335
  • 2
  • 9
2
votes
1 answer

How do we use the generator with FsCheck?

This link explains the generator, but does not specify exactly how to use it. I am not sure how to test the contents of the list generated by the generator. I would like the following code. (forall is an imaginary function.) open FsCheck open…
thglafls
  • 25
  • 4
2
votes
1 answer

Set of N length generator in FSCheck

I'm still learning FSCheck, and recently needed a fixed collection of unique strings. This works, but I suspect there is a more efficient way. Arb.generate> |> Gen.filter (fun s -> Set.count s > 9) |> Gen.map (Seq.truncate 10)…
OrdinaryOrange
  • 2,420
  • 1
  • 16
  • 25
2
votes
1 answer

How do I register my own FsCheck Generator on Expecto

I've built my generator type that generates multiples of three. I want to use it in a test with Expecto. How can register this generator and tell my test to use it? let multipleOfThree n = n * 3 type ThreeGenerator = static member…
ntonjeta
  • 43
  • 5
2
votes
1 answer

Adjust string generator to avoid "\0" with FsCheck.Xunit in C#

When creating an FsCheck.Xunit unit test with string input I am struggling with frequent occurrences of strings containing "\0" which I believe feed into a C library and lead to string truncation. Strings containing "\0" are created frequently by…
MFL
  • 69
  • 1
  • 8
2
votes
1 answer

Issues Creating Records with FsCheck

This question is a follow-up to an earlier question on using FsCheck to generate records. The original question was answered with a well composed example solution. However, prior to the answer being shared, I attempted to create a generator which is…
Ari
  • 4,121
  • 8
  • 40
  • 56
2
votes
1 answer

Using FsCheck I get different results on tests, once 100% passed and the other time error

I created a generator to generate lists of int with the same lenght and to test the property of zip and unzip. Running the test I get once in a while the error Error: System.ArgumentException: list2 is 1 element shorter than list1 but it shouldn't…
bennius
  • 111
  • 7
2
votes
1 answer

How to override string generation for all properties in FsCheck

I have a bunch of types with strings all over the place. I want to write property tests for functions operating on these types, using FsCheck. For all of them, I know that I will never get strings that are null or are non alpha-numeric. Ergo I want…
Modern Ronin
  • 571
  • 1
  • 5
  • 13
2
votes
2 answers

Property Based Testing in F# using conditional parameters

I am currently writing a property based test to test a rate calculation function in f# with 4 float parameters, and all the parameters have specific conditions for them to be valid (for example, a > 0.0 && a < 1.0, and b > a). I do have a function…
2
votes
1 answer

How do you run async tests in FsCheck?

How can I get repeatable async tests with FsCheck? Here is a sample code that I run in FSI: let prop_simple() = gen { let! s = Arb.generate printfn "simple: s = %A" s return 0 < 1 } let prop_async() = async { let s =…
Ray
  • 2,974
  • 20
  • 26