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

No more untyped constraints and tests like

1 |> should equal "1"

FsUnitTyped from NuGet

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


With FsUnitTyped, you can write unit tests like this:

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 FsUnitTyped
val shouldEqual: expected: 'a -> actual: 'a -> unit (requires equality)
val shouldNotEqual: expected: 'a -> actual: 'a -> unit (requires equality)
val shouldBeGreaterThan: expected: 'a -> actual: 'a -> unit (requires 'a :> System.IComparable)
val shouldBeSmallerThan: expected: 'a -> actual: 'a -> unit (requires 'a :> System.IComparable)
val shouldContainText: expected: string -> actual: string -> unit
val shouldContain: expected: 'a -> actual: seq<'a> -> unit
val shouldNotContain: expected: 'a -> actual: seq<'a> -> unit
val shouldBeEmpty: actual: seq<'a> -> unit
val shouldHaveLength: expected: int -> actual: seq<'a> -> unit
val failwith: message: string -> 'T
<summary>Throw a <see cref="T:System.Exception" /> exception.</summary>
<param name="message">The exception message.</param>
<returns>Never returns.</returns>
<example id="failwith-example"><code lang="fsharp"> let failingFunction() = failwith "Oh no" // Throws an exception true // Never reaches this failingFunction() // Throws a System.Exception </code></example>
val shouldFail<'exn (requires 'exn :> exn)> : f: (unit -> unit) -> unit (requires 'exn :> exn)
Namespace System
Multiple items
type Exception = interface ISerializable new: unit -> unit + 2 Überladungen member GetBaseException: unit -> exn member GetObjectData: info: SerializationInfo * context: StreamingContext -> unit member GetType: unit -> Type member ToString: unit -> string member Data: IDictionary member HResult: int member HelpLink: string member InnerException: exn ...
<summary>Represents errors that occur during application execution.</summary>

System.Exception() : System.Exception
System.Exception(message: string) : System.Exception
System.Exception(message: string, innerException: exn) : System.Exception
val ignore: value: 'T -> unit
<summary>Ignore the passed value. This is often used to throw away results of a computation.</summary>
<param name="value">The value to ignore.</param>
<example id="min-example"><code lang="fsharp"> ignore 55555 // Evaluates to () </code></example>
Fork me on GitHub