Created
November 27, 2010 23:18
-
-
Save panesofglass/718375 to your computer and use it in GitHub Desktop.
Expressive testing with NUnit in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`` |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.