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

Controlling your dependencies


Control your dependencies before they take control of you. If you have a unit test where you need to stub out three dependencies, then you're spending more time dealing with the coupling of the SUT than actually testing that it's doing in the right thing. Dependencies are a huge problem in programming and something that needs to be dealt with very carefully.

When you're using a dependency injection framework, you're making life easy for yourself by letting the framework create your object and all its dependencies. This means that there is no problem for you to add more and more dependencies to the class under test, because there is no punishment for doing so. Not until you start writing tests.

When you're writing tests, you can tolerate one dependency of your unit, but not more than this. This is why your SUT needs to be abstracted so that one unit never has more than one dependency. This will make your code easier to read and follow. The downside is that the...