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

FsUnit


The current state of unit testing in F# is good. You can get all the major test frameworks running with little effort, but there is still something that feels a bit off with the way tests and asserts are expressed:

open NUnit.Framework
Assert.That(result, Is.EqualTo(42))

Using FsUnit, you can achieve much higher expressiveness in writing unit tests by simply reversing the way the assert is written:

open FsUnit
result |> should equal 42

Please refer to Chapter 3, Setting Up Your Test Environment, on how to set up a testing environment with FsUnit.

The FsUnit framework is not a test runner in itself, but uses an underlying test framework to execute. The underlying framework can be of MSTest, NUnit, or xUnit. FsUnit can best be explained as having a different structure and syntax while writing tests.

While this is a more dense syntax, the need for structure still exists and AAA is more needed more than ever. Consider the following test example:

[<Measure>] type EUR
[<Measure&gt...