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

how to check if a path is well formed with FsCheck in FSharp

I'm struggling getting an answer to this: Define a function functionWF and functionPath that takes an FsTree and returns a boolean that check whether the given tree is well-formed as a filesystem and whether the path (represented as a list of…
2
votes
1 answer

Can an FsCheck generator create an ever-increasing sequence

I'm using FsCheck to make a generator to create fake database records. Depending upon the field in question it uses chooseFromList, or generators for ints, floats, etc. However, one troublesome field is a primary key field that must be sequential.…
StevePoling
  • 319
  • 1
  • 15
2
votes
1 answer

F# test if the result is Some(any)

I need to check whether my validation function returns something when fails or none. If it returns Some, there is a validation error, otherwise it's valid and the function returns None. This is my attempt , but it's not refactoring…
Mohsen
  • 4,000
  • 8
  • 42
  • 73
2
votes
1 answer

Combining two generators to a single arbitrary in FsCheck

I have a property I want to test on a collection of Stuff, where one of the Stuff satisfies a certain property. I have a way to generate a Stuff satisfying the property, and a way to generate a Stuff that doesn't. Today, I'm doing something like…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
2
votes
2 answers

How to use FsCheck generator to generate two records of same type where one record's property differs from the other

I have this fscheck nunit test that generate two records which i then have to update so that both records always have different values for Direction property [] let ``calculate Net Worth 2`` (first:Bill,second:Bill) = …
Samuel
  • 1,295
  • 16
  • 21
2
votes
1 answer

How to generate null for nullable types with FsCheck?

I have this generator that seems to work, but when I check the values generated, it never picks the null value. How does one write generator that will pick null value. This code never picks null value for "end" date. public static Gen
epitka
  • 17,275
  • 20
  • 88
  • 141
2
votes
1 answer

How to pass a Type as an attribute parameter using F# syntax?

FsCheck allows a custom Arbitrary in its NUnit integration: [])>] static member MultiplyIdentity (x: int64) = x * 1 = x This syntax doesn't work. I feel a bit embarrassed to ask,…
Abel
  • 56,041
  • 24
  • 146
  • 247
2
votes
1 answer

How to run FsCheck with Xunit

Hi I am trying to run FsCheck.Xunit tests with xunit.runner.console and getting the following exception: Kata.TennisProperties.Given advantaged player when advantaged player wins score is correct [FAIL] System.Reflection.TargetInvocationException…
Adrian
  • 1,006
  • 2
  • 9
  • 20
2
votes
1 answer

How to check if an Exception is thrown by a method with xUnit and FsCheck in F#

I'm doing the Diamond Kata in C# with tests writen in F# using xUnit and FsCheck, and I'm having some trouble when trying to check if an Exception is thrown in case of a invalid input by the user (any char that isn't an alphabet letter without any…
Liordino Neto
  • 59
  • 1
  • 13
2
votes
0 answers

How to take advantage of shrinking in a complex case

I'm just getting started with FsCheck. I need to generate some test data, here TestData represents the input to my test: type Interval = { Start : DateTime; End : DateTime } type Frob = { Interval : Interval; MustFrob : bool } type TestData = {…
Asik
  • 21,506
  • 6
  • 72
  • 131
2
votes
1 answer

How do I apply a configuration to a suite of property-based tests?

How do I apply a configuration to a suite of property-based tests? I tried the following: let config = { Config.Quick with MaxTest = 10000 QuietOnSuccess = true } [] // Doesn't work because…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
2
votes
1 answer

How can I generate a value so that it's reflected as an element of another generated value?

How can I generate a value so that it's reflected as an element of another generated value? For example take the following code: type Space = | Occupied of Piece | Available of Coordinate // Setup let pieceGen = Arb.generate
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
2
votes
0 answers

How can I use FsCheck with a portable class library?

How can I use FsCheck with a portable class library? I receive the following error: Error Could not install package 'FsCheck.Xunit 2.5.0'. You are trying to install this package into a project that targets …
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
2
votes
1 answer

How can I establish conditions on test inputs when performing Property-based testing?

How can I establish conditions on test inputs when performing Property-based testing? For example, the following code generates bools when I need ints: Gen.map (fun v -> v > 0) Here's the function: [] let ``number…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
2
votes
2 answers

Why am I receiving a "No arguments provided" error on a property-based test?

The following test fails: open FsCheck open FsCheck.NUnit open NUnit.Framework let ``Property: double negation equals no negation`` list = list = List.rev (List.rev list) [] let ``reversing list two times is equal to not reversing list…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118