My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
Code license: MIT License
Labels: unittest, testing, fsharp, spec
Show all Featured wiki pages:
5MinuteIntro FsUnit
Links:
Blogs:
Feeds:
People details
Project owners:
  R.Vernagus

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.


Syntax

With FsUnit, you can write unit tests like this:

FULL EXAMPLE

Here 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"








Hosted by Google Code