|
Project Information
Members
Featured
Wiki pages
Links
|
ATTENTIONThis project has moved to CodePlex
FsUnit is a library for use with the F# programming language. It is a set of extensions that add a special testing syntax (see below) to your favorite unit-testing framework so that you don't have to learn a new testing framework but you also get to take advantage of everyone's favorite new language.SyntaxWith FsUnit, you can write unit tests like this:
1 |> should equal 1 1 |> should not (equal 2) [1] |> should contain 1 [] |> should not (contain 1) anArray |> should haveLength 4 aCollection |> should haveCount 4
(fun () -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>
true |> should be True false |> should not (be True) [] |> should be Empty [1] |> should not (be Empty) "" |> should be EmptyString "" |> should be NullOrEmptyString null |> should be NullOrEmptyString null |> should be Null anObj |> should not (be Null) anObj |> should be (sameAs anObj) anObj |> should not (be sameAs otherObj) FULL EXAMPLEHere is a complete set of tests from the FsUnit.NUnit examples: #r "FsUnit.NUnit.dll"
#r "nunit.framework.dll"
open NUnit.Framework
open FsUnit
type LightBulb(state) =
member x.On = state
override x.ToString() =
match x.On with
| true -> "On"
| false -> "Off"
[<TestFixture>]
type ``Given a LightBulb that has had its state set to true`` ()=
let lightBulb = new LightBulb(true)
[<Test>] member test.
``when I ask whether it is On it answers true.`` ()=
lightBulb.On |> should be True
[<Test>] member test.
``when I convert it to a string it becomes "On".`` ()=
string lightBulb |> should equal "On"
[<TestFixture>]
type ``Given a LightBulb that has had its state set to false`` ()=
let lightBulb = new LightBulb(false)
[<Test>] member test.
``when I ask whether it is On it answers false.`` ()=
lightBulb.On |> should be False
[<Test>] member test.
``when I convert it to a string it becomes "Off".`` ()=
string lightBulb |> should equal "Off"
|