How to guarantee reproducibility of FsCheck

We want to use FsCheck as part of our unit testing in continuous integration. Because such deterministic and reproducible behavior is very important to us.

FsCheck, being a random testing framework, can generate test cases that can sometimes be interrupted. The key is that we are not only using properties that we would have to hold on to each input , say say List.rev >> List.rev === id. But rather, we make some numbers, and some test cases can cause the test to break due to poor conditioning.

Question: how can we guarantee that once a test is successful, it will always be successful?

So far I see the following options:

  • hard seed code, for example. 0. This would be the easiest solution.
  • Create very specific custom generators that avoid bad examples. Of course, it is possible, but it can turn out quite difficult, especially if there are many objects to generate.
  • live with him, which in some cases, the assembly may be red due to pathological cases and just restart.

What is the idiomatic way to use FsCheck in such a setup?

+4
source share
2 answers

(I started writing a comment, but he had guessed for so long that he deserves his own answer).

FsCheck, . , FsCheck List.rev, list<float>.

- - FsCheck FsCheck, (FsCheck , ...). "", , . , ? , ? , , - ... .

, FsCheck, - . ==> , . , - , , - . !

- , . , , : , " "?

+3

- .

, :

let isOk x =
    match x with
    | 42 -> false
    | _ -> true

let MyProperty (x:int) = isOk x ==> // check x here...

(, 42.)

+4

Source: https://habr.com/ru/post/1529783/


All Articles