Thursday, December 1, 2011

Enhancements to FsUnit (version

A new version ( of FsUnit -- a DSL for writing unit tests in F# -- is now available on the NuGet gallery.

This version includes the following improvements:

 - Libraries for frameworks 3.5 and 4.0.
 - Support for NUnit version
 - Several new functions including: greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, shouldFail, endWith, startWith, and ofExactType.

Examples of the functions mentioned above are shown below:
module FsUnit.``Given a bunch of random tests``

open NUnit.Framework
open FsUnit

let ``When 11 it should be greater than 10``() =
    11 |> should be (greaterThan 10)

let ``When 11 it should be greater than or equal to 10``() =
    11 |> should be (greaterThanOrEqualTo 10)

let ``When 10 it should be less than 11``() =
    10 |> should be (lessThan 11)

let ``When 10 it should be less than or equal to 11``() =
    10 |> should be (lessThanOrEqualTo 11)

let ``When an empty List it should fail to contain item``() =
    shouldFail (fun () -> [] |> should contain 1)

let ``When fsharp it should end with rp``() =
    "fsharp" |> should endWith "rp"

let ``When fsharp it should start with fs``() =
    "fsharp" |> should startWith "fs"

let ``When 1 it should be of exact type int``() =
    1 |> should be ofExactType<int>

An example of what this looks like when run in Resharper's Test Runner is shown below:

A Side Note: If you haven't written many tests in F#, the lack of spaces in the test names may surprise you. This is a feature of F# that allows almost any sequence of characters to be enclosed in double-backtick characters (i.e. ``) and consequently treated as an identifier.

I hope you enjoy the latest enhancements to FsUnit. You can find the full source at

No comments:

Post a Comment