没有任何数据可供显示
| 开源项目社区 | 当前位置 : |
|
| www.trustie.net/open_source_projects | 主页 > 开源项目社区 > fsunit |
|
fsunit
|
| 1 | 0 | 128 |
| 贡献者 | 讨论 | 代码提交 |
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:
One object equals or does not equal another:
1 |> should equal 1
1 |> should not (equal 2)A List, Seq, or Array instance contains or does not contain a value: [1] |> should contain 1
[] |> should not (contain 1)A List or Array instance has a certain length: anArray |> should haveLength 4A Collection instance has a certain count: aCollection |> should haveCount 4A function should throw a certain type of exception: (fun () -> failwith "BOOM!" |> ignore) |> should throw typeofA number of assertions can be created using the be keyword: 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"
[]
type ``Given a LightBulb that has had its state set to true`` ()=
let lightBulb = new LightBulb(true)
[] member test.
``when I ask whether it is On it answers true.`` ()=
lightBulb.On |> should be True
[] member test.
``when I convert it to a string it becomes "On".`` ()=
string lightBulb |> should equal "On"
[]
type ``Given a LightBulb that has had its state set to false`` ()=
let lightBulb = new LightBulb(false)
[] member test.
``when I ask whether it is On it answers false.`` ()=
lightBulb.On |> should be False
[] member test.
``when I convert it to a string it becomes "Off".`` ()=
string lightBulb |> should equal "Off"
标签:
