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

c# FsCheck cannot convert lambda expression

I'm trying to get a C# FsCheck generator to generate a series of commands which are initialized with random strings. I came up with the following solution: public Gen> Next(B value) { var gen1 = Arb.Default.String().Generator; var…
mto_19
  • 135
  • 6
1
vote
1 answer

Speed up FsCheck Arbitrary generation

I'm writting some generators and an Arbitrary, but is too slow (see the GC numbers also). I think I have an error on my code, but I can't figure out where. Or my approach (map2 (fold)) is "weird"?. Generators: type Generators () = static let…
user1229323
1
vote
1 answer

Calling default FsCheck generator from a custom generator of the same type

I defined a type with a few custom generators to make FsCheck generate customized instances of a few types. But for one of the complex types I want to use default FsCheck generation first and then adjust the result. Here's a (simplified) code: type…
Vagif Abilov
  • 9,835
  • 8
  • 55
  • 100
1
vote
1 answer

Generate events/commands using a property based testing tool?

As I understand it, most property testing tools operate at the level of functions. Given a set of arguments, such tools will generate random input and test output against some invariant. I have read that ScalaCheck is now starting to include…
Shahbaz
  • 10,395
  • 21
  • 54
  • 83
1
vote
0 answers

Generating random objects as test cases

This question is part of larger question that can be found here We have classes that come from Entity Framework. In other words they are not Records that are immutable they are quite posit list of mutable properties without constructor. FsCheck…
Icen
  • 441
  • 6
  • 14
1
vote
1 answer

Is there a way to go from Gen to Gen while specifying a bound?

module BirthdayLibrary = type Birthday = { day :int month :int } module DataGen = let birthdayGenerator (months:option>) = let monthGen = match months with | Some m ->…
Hohohodown
  • 718
  • 1
  • 8
  • 23
1
vote
1 answer

Testing a list of types with FsCheck

I have a property that tests a type can be successfully round tripped to JSON and back. let roundTrip<'a when 'a : equality> (x: 'a) = (toJSON >> ofJSON) x = x which I currently run by calling Check.Quick roundTrip What I would like is…
Brownie
  • 7,688
  • 5
  • 27
  • 39
1
vote
0 answers

Exception upon using FsCheck

Upon running with xUnit the simplest test from FsCheck open FsCheck [] let revRevIsOrig (xs:list) = List.rev(List.rev xs) = xs I receive the exception ---- System.InvalidCastException : Unable to cast object of type…
nicolas
  • 9,549
  • 3
  • 39
  • 83
1
vote
0 answers

Using FsCheck in VS 2010

I am trying to use FsCheck 0.8.3 in Visual Studio 2010 for F#. I have created a project, and wrote the example line: let revRevIsOrig (xs:list) = List.rev(List.rev xs) = xs from the quick-start guide. After this, I added the FsCheck.dll to the…
Teknophilia
  • 758
  • 10
  • 23
0
votes
1 answer

Removing usage of Arb.registerByType from Xunit test using FsCheck

I am testing a round-trip of a Thoth.Json Encoder / Decoder pair. It looks like this: type CustomArbitrary = static member String() = Arb.Default.String() |> Arb.filter (not << isNull) [] let ``Encode.foo Decode.foo round-trip`` ()…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
0
votes
0 answers

How to run the specific test on FsCheck using replay?

I have a test using FsCheck, when it fails it give me the information about the seed to put on the Replay property to reproduce the failed test. But to debug this is really hard, because it will not fail on the first value. FsCheck also give me the…
thur
  • 964
  • 1
  • 15
  • 27
0
votes
0 answers

Scoping contant FsCheck generator to each test

I am trying to test a domain model for a SaaS application with FsCheck and XUnit. Each model entity has a column TenantId with some unique tenant identifier. There are numerous Asserts checking that TenantIds are not mixed up. For now, I have this…
Michael Korbakov
  • 2,147
  • 1
  • 18
  • 20
0
votes
1 answer

How to force any decimal value (be it part of a type or not) generated with fscheck to be within a certain range?

I'm using fscheck to write some unite tests and I would like to narrow down the range of decimal automatically generated and that regardless of the parameter I'm passing. What I mean by that is that let's say I have the types…
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
0
votes
1 answer

FsCheck not using registered Arbs/Gens

I am trying to use FsCheck for Property based testing but I cannot seem to figure out how to get FsCheck to use the gens I have registered. Here is the code for generating types for the domain: module Flips.Gens open Flips.Domain open FsCheck type…
Matthew Crews
  • 4,105
  • 7
  • 33
  • 57
0
votes
0 answers

Logging to output with FsCheck.Xunit

I am struggling to be able to log to output during FsCheck.Xunit unit tests in C#. I am using ITestOutputHelper as I believe this is the recommended approach with Xunit. In the example tests below, Test1 will not pipe "Hi" to the output but Test2…
MFL
  • 69
  • 1
  • 8