How do you create unit tests in F#? I typically use the UnitTest portion of Visual Studio with a [TestClass] and [TestMethod] attributes and use the Test View to run these. I know I can just create a script file and run these, but I like the way that it is currently handled.
A unit test typically comprises of three stages: plan, cases and scripting and the unit test itself. In the first step, the unit test is prepared and reviewed. The next step is for the test cases and scripts to be made, then the code is tested.
Check out fscheck. It's a port of Haskell's Quickcheck. Fscheck allows you to specify properties a function must satisfy which it will then verify against a "large number of randomly generated cases".
It's something you can't easily do with an imperative language like C#.
I'd rather use FsUnit or FsTest to write tests in F#, it feels more natural than OO xUnit style tests.
EDIT 2014: I now consider FsUnit/FsTest to be mostly useless syntax sugar. And "more natural than OO" doesn't mean absolutely anything. A few months ago I wrote my current thoughts on testing here (I recommend reading the entire thread).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With