fscheck / FsCheck

Random Testing for .NET
https://fscheck.github.io/FsCheck/
BSD 3-Clause "New" or "Revised" License
1.17k stars 156 forks source link

Model-based testing examples in C#? #651

Open baynezy opened 9 months ago

baynezy commented 9 months ago

I have been using your library for property-based testing in my C# projects and I am pretty comfortable with that. However, I now have a complex cache that I have built and wanted to use model-based testing to exercise that to make sure I have any edge cases covered.

I have been looking at your documentation and I am struggling to get my head around it as I do not know F#.

Do you have any simple examples testing something like a Dictionary in C# available? I should be able to work it out from there.

I found this article, but as I do not understand the system under test I am struggling to follow the implementation.

isberg commented 8 months ago

@baynezy I have seen several interesting youtube videos where John Hughes talks about Property-Based Testing and I am pretty sure he talks about model based testing as one specific strategy. The same is true also for Scott Wlaschin. Hopefully these will provide some guidance.

kurtschelfthout commented 7 months ago

Hey, yes the docs leave much to be desired. That seems to be the general tune as I work through the backlog of issues!

Anyway, this may get you started: https://aaronstannard.com/fscheck-property-testing-csharp-part2/

There's also a hidden implementation of a model-based test for an Erlang-like process registry here: https://github.com/fscheck/FsCheck/blob/master/src/FsCheck/Script.fsx#L44 but it is F#.

If you get something working, please consider sending a PR to the docs...even if it's just a C# snippet we can put somewhere.