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

Tests that require excessive setup


A slight indication that your system under test is too complex is that the test setup becomes excessive. The easiest way to identify this is when you have 20 lines of setup code in order to run one line of test code. Some of it you might also need to tear down after the test is complete.

The test itself doesn't have to be very complex, but the complexity of the system under test forces the excessive setup on the test. What often happens is that this setup is duplicated from test to tests, causing a lot of duplicated code. The most commonly seen solution is then to extract the method once the test is set up, but this is really bad. Instead, the problem should be addressed in the system under test.

The excessive setup code is usually as follows:

  • Setup of dependencies necessary to execute the test

  • Setup of states necessary to execute the test

In most modern systems, there is a dependency injection framework in the middle that handles dependencies through the system...