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: 
1 |> should equal "1"

FsUnitTyped from NuGet

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

FsUnitTyped with Paket

FsUnitTyped supports lightweight usage scenario with Paket.

In the case when you do not want to add dependency on FsUnit package to your project, you can add reference to FsUnitTyped.fs file and NUnit package.

Example of paket.dependencies file:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
source https://nuget.org/api/v2

nuget FSharp.Core
github fsprojects/FsUnit src/FsUnit.NUnit/FsUnitTyped.fs

group Test
    source https://nuget.org/api/v2
    nuget NUnit.Console
    nuget NUnit

Example of paket.reference file for test projects:

1: 
2: 
3: 
File:FsUnitTyped.fs
group Test
    NUnit

Syntax

With FsUnitTyped, you can write unit tests like this:

1: 
2: 
open NUnit.Framework
open FsUnitTyped

One object equals or does not equal another:

1: 
2: 
1 |> shouldEqual 1
1 |> shouldNotEqual 2

One comparable value greater or smaller than another:

1: 
2: 
11 |> shouldBeGreaterThan 10
10 |> shouldBeSmallerThan 11

A string contains specified substring:

1: 
"ships" |> shouldContainText "hip"

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

1: 
2: 
3: 
[1] |> shouldContain 1
[] |> shouldNotContain 1
[] |> shouldBeEmpty

A List or Array instance has a certain length:

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

A function should throw a certain type of exception:

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

A function should fail

1: 
shouldFail (fun _ -> 5/0 |> ignore)
namespace NUnit
namespace NUnit.Framework
namespace FsUnitTyped
val shouldEqual : expected:'a -> actual:'a -> unit (requires equality)

Full name: FsUnitTyped.TopLevelOperators.shouldEqual
val shouldNotEqual : expected:'a -> actual:'a -> unit (requires equality)

Full name: FsUnitTyped.TopLevelOperators.shouldNotEqual
val shouldBeGreaterThan : x:'a -> y:'a -> unit (requires 'a :> System.IComparable)

Full name: FsUnitTyped.TopLevelOperators.shouldBeGreaterThan
val shouldBeSmallerThan : x:'a -> y:'a -> unit (requires 'a :> System.IComparable)

Full name: FsUnitTyped.TopLevelOperators.shouldBeSmallerThan
val shouldContainText : x:string -> y:string -> unit

Full name: FsUnitTyped.TopLevelOperators.shouldContainText
val shouldContain : x:'a -> y:seq<'a> -> unit

Full name: FsUnitTyped.TopLevelOperators.shouldContain
val shouldNotContain : x:'a -> y:seq<'a> -> unit (requires equality)

Full name: FsUnitTyped.TopLevelOperators.shouldNotContain
val shouldBeEmpty : list:seq<'a> -> unit

Full name: FsUnitTyped.TopLevelOperators.shouldBeEmpty
val shouldHaveLength : expected:int -> list:seq<'a> -> unit

Full name: FsUnitTyped.TopLevelOperators.shouldHaveLength
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
val shouldFail<'exn (requires 'exn :> exn)> : f:(unit -> unit) -> unit

Full name: FsUnitTyped.TopLevelOperators.shouldFail
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 HelpLink : string with get, set
  member InnerException : Exception
  member Message : string
  member Source : string with get, set
  member StackTrace : string
  ...

Full name: System.Exception

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

Full name: Microsoft.FSharp.Core.Operators.ignore
Fork me on GitHub