O'Reilly logo

Testing with F# by Mikael Lundin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tools and frameworks

The built-in tools for unit testing in Visual Studio are not the greatest. To smoothen the process, you need to use some external frameworks and tools.

FsUnit

The tests in this book will mainly focus on FsUnit as the main tool to write unit tests. This is not a test framework like NUnit or xUnit, but more of a helper library to write tests in a more functionally idiomatic way.

Let's start with an example. This function will get the date and time for the Swedish Midsummer in a specified year:

// find date of midsummer eve in Sweden
let midsummerEve year = 
    // get a day in June
    let dateInJune day = new System.DateTime(year, 6, day)
    // is specified date a friday let isFriday (date : System.DateTime) = date.DayOfWeek = System.DayOfWeek.Friday ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required