90 people like it.
Like the snippet!
NUnit Sugar
Some simple functions for writing more idiomatic F# tests with NUnit.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
|
// You need NUnit (http://nunit.org/)
#r "nunit.framework.dll"
open NUnit.Framework
let inline (==) (actual:#obj) (expected:#obj) = Assert.AreEqual(expected, actual)
let inline (!=) (actual:#obj) (expected:#obj) = Assert.AreNotEqual(expected, actual)
let inline (<->) (actual:#obj) expected = Assert.IsInstanceOf(expected, actual)
let inline (<!>) (actual:#obj) expected = Assert.IsNotInstanceOf(expected, actual)
let ``is null`` anObject = Assert.IsNull(anObject)
let ``is not null`` anObject = Assert.NotNull(anObject)
[<Test>]
let ``1 + 1 = 2``() = 1 + 1 == 2
[<Test>]
let ``1 + 1 + 1 <> 2``() = 1 + 1 + 1 != 2
[<Test>]
let ``"Howdy"B is a byte[]``() = "Howdy"B <-> typeof<byte[]>
[<Test>]
let ``"Howdy" is not a byte[]``() = "Howdy" <!> typeof<byte[]>
[<Test>]
let ``null is null``() = null |> ``is null``
[<Test>]
let ``new obj() is not null``() = let o = obj() in o |> ``is not null``
|
val actual : 'a
type obj = System.Object
Full name: Microsoft.FSharp.Core.obj
val expected : 'b
val ( is null ) : anObject:'a -> 'b
Full name: Script.( is null )
val anObject : 'a
val ( is not null ) : anObject:'a -> 'b
Full name: Script.( is not null )
val ( 1 + 1 = 2 ) : unit -> 'a
Full name: Script.( 1 + 1 = 2 )
val ( 1 + 1 + 1 <> 2 ) : unit -> 'a
Full name: Script.( 1 + 1 + 1 <> 2 )
val ( "Howdy"B is a byte[] ) : unit -> 'a
Full name: Script.( "Howdy"B is a byte[] )
val typeof<'T> : System.Type
Full name: Microsoft.FSharp.Core.Operators.typeof
Multiple items
val byte : value:'T -> byte (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.byte
--------------------
type byte = System.Byte
Full name: Microsoft.FSharp.Core.byte
val ( "Howdy" is not a byte[] ) : unit -> 'a
Full name: Script.( "Howdy" is not a byte[] )
val ( null is null ) : unit -> 'a
Full name: Script.( null is null )
val ( new obj() is not null ) : unit -> 'a
Full name: Script.( new obj() is not null )
val o : System.Object
More information