My favorites | Sign in
Project Logo
                
Code license: MIT License
Labels: unittest, testing, fsharp, spec
Show all Featured wiki pages:
5MinuteIntro
Links:
Blogs:
Feeds:
People details
Project owners:
  R.Vernagus

FsUnit is a stand-alone specification framework for use with the F# programming language. Written itself in F#, it offers a functional alternative to traditional imperative frameworks.


Specification Syntax

With FsUnit, you can write specifications like this:

The specs and spec Keywords

Let FsUnit manage the storage and execution of your specs, use the specs keyword:

specs "My Specs" [
    spec "A number should equal itself."
        (1 |> should equal 1)
]

printfn "%s" (Results.summary())

For more examples of using the spec and specs keywords, see the examples.


FULL EXAMPLE

The full code for a specification in FsUnit looks like this:

#light
#r "FsUnit.dll"
open FsUnit

type LightBulb(state) =
    member x.On = state
    override x.ToString() =
        match x.On with
        | true  -> "On"
        | false -> "Off"

let onSpecs =   
    let lb = LightBulb(true)
    
    specs "On Specs" [
        spec "On should be true."
            (lb.On |> should be True)
        spec "String representation should equal \"On\"."
            (lb.ToString() |> should equal "On")
    ]

let offSpecs =
    let lb = LightBulb(false)
    
    specs "Off Specs" [
        spec "Off should be false."
            (lb.On |> should be False)
        spec "String representation should equal \"Off\"."
            (lb.ToString() |> should equal "Off")
    ]

printfn "%s" (Results.summary())








Hosted by Google Code