Unit testing in F#

There are several libraries for writing unit tests in F#. FsUnit allows us to reuse xUnit, NUnit or MbUnit.

So using FsUnit with xUnit do the following

  1. Add a new Library project
  2. Using NuGet, add a reference to FsUnit.Xunit

Now we can write our tests using the following

open FsUnit.Xunit
open Xunit

module Tests =

   [<Fact>]
   let ``add two numbers`` () =
      let m = new Mathematics()
      m.add 1 3 |> should equal 4

using backtick notation for identifers is useful for helping us write human readable test names.