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

Stubbing with Foq


There are two specific types of test doubles, namely stubs and mocks. A stub is a least effort implementation of an abstract class or interface. Sometimes, it is prepared with some stub data, meaning data that is necessary in order to run our tests.

A mock is also a test double, but it will record any interaction and be able to answer asserts on those interactions. You can ask the mock questions such as: was the GetUsers() method called with the ID 42 parameter? And in this way, you can verify the interactions of an isolated unit with its outside world.

There are many .NET mocking frameworks that would work well with F#, like Rhino Mocks, Moq, and NMock. Foq is, however, one framework that is specific to F# and uses its code quotations, as we've already seen with Unquote.

You can install Foq directly to your project from the NuGet Package Manager, as shown in the following screenshot:

This will add Foq as a reference to your project and you can use it to start writing your...