Testing with Visual Studio
So far, we've been talking about interactive testing with F#. This is a basic concept in starting to write qualitative code, but what this book really is about is test automation.
Visual Studio Professional comes with some basic testing tools you can use to automate testing in your solution. They are, however, not made to work with F# and need some fiddling before you could begin using them, as explained in the following steps:
- Create a new F# library project:
- Add a reference to Microsoft.VisualStudio.QualityTools.UnitTestingFramework. This will later be referred to as MSTest:
- Create a new F# source file in your project with the
fs
extension. Now, you can write your first test, as follows:module MSTest open Microsoft.VisualStudio.TestTools.UnitTesting [<TestClass>] type CalculatorShould () = [<TestMethod>] member this.``add 1 and 2 with result of 3`` () = Assert.AreEqual(3, 1 + 2)
- After compiling the test, go to Test | Run All Tests...