FsUnit


What is FsUnitTyped?

FsUnitTyped is a statically typed set of FsUnit operators that makes unit-testing with FsUnit even more safe and enjoyable (Available only for NUnit).

No more untyped constrains and tests like

1 |> should equal "1"

FsUnitTyped from NuGet

The FsUnit.Typed is part of FsUnit package for NUnit and can be installed from NuGet.

Syntax

With FsUnitTyped, you can write unit tests like this:

open NUnit.Framework
open FsUnitTyped

One object equals or does not equal another:

1 |> shouldEqual 1
1 |> shouldNotEqual 2

One comparable value greater or smaller than another:

11 |> shouldBeGreaterThan 10
10 |> shouldBeSmallerThan 11

A string contains specified substring:

"ships" |> shouldContainText "hip"

A List, Seq, or Array instance contains, does not contain a value or empty:

[1] |> shouldContain 1
[] |> shouldNotContain 1
[] |> shouldBeEmpty

A List or Array instance has a certain length:

[|1;2;3;4|] |> shouldHaveLength 4

A function should throw a certain type of exception:

(fun _ -> failwith "BOOM!") |> shouldFail<System.Exception>

A function should fail

shouldFail (fun _ -> 5/0 |> ignore)
namespace NUnit
namespace NUnit.Framework
namespace FsUnitTyped
val shouldEqual : expected:'a -> actual:'a -> unit (requires equality)
val shouldNotEqual : expected:'a -> actual:'a -> unit (requires equality)
val shouldBeGreaterThan : x:'a -> y:'a -> unit (requires 'a :> System.IComparable)
val shouldBeSmallerThan : x:'a -> y:'a -> unit (requires 'a :> System.IComparable)
val shouldContainText : x:string -> y:string -> unit
val shouldContain : x:'a -> y:seq<'a> -> unit
val shouldNotContain : x:'a -> y:seq<'a> -> unit (requires equality)
val shouldBeEmpty : list:seq<'a> -> unit
val shouldHaveLength : expected:int -> list:seq<'a> -> unit
val failwith : message:string -> 'T
val shouldFail<'exn (requires 'exn :> exn)> : f:(unit -> unit) -> unit (requires 'exn :> exn)
namespace System
Multiple items
type Exception =
  new : unit -> Exception + 2 overloads
  member Data : IDictionary
  member GetBaseException : unit -> Exception
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member GetType : unit -> Type
  member HResult : int with get, set
  member HelpLink : string with get, set
  member InnerException : Exception
  member Message : string
  member Source : string with get, set
  ...

--------------------
System.Exception() : System.Exception
System.Exception(message: string) : System.Exception
System.Exception(message: string, innerException: exn) : System.Exception
val ignore : value:'T -> unit
Fork me on GitHub