Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle unit tests in F#?

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.

like image 958
esac Avatar asked Sep 23 '09 22:09

esac


People also ask

What are the steps required to perform unit testing?

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.


2 Answers

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#.

like image 52
ctford Avatar answered Oct 15 '22 16:10

ctford


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).

like image 24
Mauricio Scheffer Avatar answered Oct 15 '22 17:10

Mauricio Scheffer