Book Image

Testing with F#

By : Mikael Lundin
Book Image

Testing with F#

By: Mikael Lundin

Overview of this book

Table of Contents (17 chapters)
Testing with F#
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Create a new F# library project:

  2. Add a reference to Microsoft.VisualStudio.QualityTools.UnitTestingFramework. This will later be referred to as MSTest:

  3. 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)
  4. After compiling the test, go to Test | Run All Tests in...