O'Reilly logo

Testing with F# by Mikael Lundin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test doubles

The definition of a test double is a dependency you inject into your program, instead of ordinary functionality, in order to isolate the thing you want to test. We've already seen what you can do by making in-memory versions of your dependencies built in. Sometimes, we want our tests to be able to inject a specific tests dependency that is not built in, and this is where the SUT needs to be extensible enough to allow it.

Just as in C#, we use an interface or abstract class to enable extensibility and allow for dependency injection. To enable this, F# provides us with the ability to implement interfaces using object expressions. This is a great feature for testing.

As an example, lets start with defining an interface. This interface ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required