Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Created November 27, 2010 23:18
Show Gist options
  • Select an option

  • Save panesofglass/718375 to your computer and use it in GitHub Desktop.

Select an option

Save panesofglass/718375 to your computer and use it in GitHub Desktop.
Expressive testing with NUnit in F#
module TestModule
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``
@panesofglass
Copy link
Copy Markdown
Author

According to NUnit's docs, the TestAttribute should not be required. However, TestDriven.net does not pick up tests starting with the text "test." Also, TestDriven.net will not run the above tests from solution explorer, only from the file. Replacing the back-tick names with something more standard will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment