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 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.

Syntax

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
val shouldBeSmallerThan: expected: 'a -> actual: 'a -> unit
val shouldContainText: expected: string -> actual: string -> unit
val shouldContain: expected: 'a -> actual: 'a seq -> unit
val shouldNotContain: expected: 'a -> actual: 'a seq -> unit
val shouldBeEmpty: actual: 'a seq -> unit
val shouldHaveLength: expected: int -> actual: 'a seq -> 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 = 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
Fork me on GitHub