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
1
vote
1 answer

FsCheck custom generator of lists satisfying a predicate

For a given predicate pred : 'a list -> bool and generator gen : Gen<'a>, consider the following generator of well-formed lists that satisfy the predicate: let wellFormedList pred gen = Gen.ofList gen |> Gen.filter pred As mentioned in the…
1
vote
1 answer

FSCheck shrinker isn't called

I can't seem to get the FSCheck shrinker to work. Say I have this let arb_chars = Arb.fromGenShrink( Arb.generate, fun cs -> seq { printfn "shrinking..." for i in…
Ray
  • 2,974
  • 20
  • 26
1
vote
1 answer

Prohibit parameter combinations

I'm trying to use FsCheck to write a basic property based test for a class that generates random DateTimeOffset values in a given interval. [Property] public void ValueBetweenMinAndMax(DateTimeOffset min, DateTimeOffset max) { var sut = new…
Sebastian Weber
  • 6,766
  • 2
  • 30
  • 49
1
vote
1 answer

Getting empty value in F# generator

I have problem with this code, I tried to generate list of non-Empty string like this: let! x = Arb.generate |> Gen.filter(fun (x) -> x<>null && x <>""&& x<>" ")|>Gen.nonEmptyListOf after running my code I am getting this output: val it :…
1
vote
1 answer

FsCheck: Generate Arbitrary of a ArrayList with its elements as Arbitraries in C#

I am using FsCheck in C#, I want to generate Arbitrary of an ArrayList to do PropertyBasedTesting by having 100's of ArrayList. I have this ArrayList with defined Arbitraries (they cannot be changed) for each element in it - E.g.…
grindlewald
  • 323
  • 3
  • 10
1
vote
1 answer

FsCheck. Difference between the object and the model

I have heard recently about Model Based Testing and searched for tools that can follow this approach. As the result i found FsCheck. At the Experimental page, the author describes how to create a model based test which can be executed. That is all…
GrimSmiler
  • 561
  • 1
  • 4
  • 21
1
vote
1 answer

How to use Property-based testing using FsCheck.NUnit or XUnit?

I new to property-based and unit testing, and in my project I want to to use this technique, but unfortunately it is easy to say... I watched a talk about FsCheck.XUnit library, but the guy was testing numeric function (modulus)... And I want to…
alex_z
  • 416
  • 5
  • 12
1
vote
2 answers

Should function composition and piping be tested?

In F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable.flatmap ObservableJson.jsonArrayToObservableObjects or : let jsonArrayToObservableObjects<'t> = …
Mohsen
  • 4,000
  • 8
  • 42
  • 73
1
vote
1 answer

How to accumulate a list of FsCheck generators into a single value?

I wrote an FsCheck generator that yields random glob syntax patterns (e.g. a*c?) along with a random string that matches the pattern (e.g. abcd). However my solution uses a mutable variable and I'm rather ashamed of that. Have a look: open…
Good Night Nerd Pride
  • 8,245
  • 4
  • 49
  • 65
1
vote
0 answers

Why are preconditions failing to work in this FsCheck example?

I am trying to use the FsCheck library. I can do some tests but preconditions do not seem to work. The code below provides an example: let sortEven (xs: int list) = xs |> List.filter (fun x -> x % 2 = 0) |> List.sort let lengthGT0 (xs:…
Soldalma
  • 4,636
  • 3
  • 25
  • 38
1
vote
1 answer

Is FSCheck suitable for testing type construction?

Background: I have a large number of commands that satisfy following rules: no setters (immutable) one constructor parameter name matches the name of the property being set (other than casing) I would like to write a tester that tests…
epitka
  • 17,275
  • 20
  • 88
  • 141
1
vote
1 answer

Can there be multiple asserts per one test?

I started looking at FsCheck yesterday, and I am trying to write a simple test, that any instance of DiscountAmount will always have negative value. My question is, is it ok to have multiple asserts within one test. For example, here I am saying…
epitka
  • 17,275
  • 20
  • 88
  • 141
1
vote
1 answer

How to exclude null value when using FsCheck Property attribute?

I need to write a simple method that receives a parameter (e.g. a string) and does smth. Usually I'd end up with two tests. The first one would be a guard clause. The second would validate the expected behavior (for simplicity, the method shouldn't…
Serhii Shushliapin
  • 2,528
  • 2
  • 15
  • 32
1
vote
3 answers

Using FsCheck with NUnit: receiving exception on using Arbitrary types (or: how to use Arbitrary types with attributes)

In my previous question Kurt pointed me to this code of FsCheck about setting the Arbitrary type. I have the following Arbitrary (disclaimer: I have no idea what I am doing..., still finding FsCheck notoriously hard to understand but I'm dead set on…
Abel
  • 56,041
  • 24
  • 146
  • 247
1
vote
1 answer

Cannot get model based test working

As an exercise I wanted to implement a 2-3 finger tree. That should be the perfect opportunity to try out FsCheck's model-based testing. I decided to try the newer experimental version. So far I only coded one command for the test machine because I…
primfaktor
  • 2,831
  • 25
  • 34