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#
About the Author
About the Reviewers

The test is not complex

You should avoid complexity in your test at all costs. A few lines of straightforward workflow should be enough for arrange, act, and assert.

This means that we disallow the following in our tests:

  • Conditional statements such as if, match, and function

  • Looping constructs such as while, for

  • Additional types, interfaces, discriminated unions, or classes apart from the SU.

  • Threads

  • Exception handling, except asserting for thrown exceptions

  • Manipulation of lists, sequences, maps, or tuples

In short, your test should be as simple as the following steps:

  1. Set up the prerequisites to run the test.

  2. Run the test.

  3. Assert the result.

If anything else is needed, you probably have a too complex system that needs refactoring in order to bring down the complexity of your tests. Complexity in your tests will hurt you in several different ways. The most common is that your test will fail even before touching the SUT because the initialization logic assumes conditions of the SUT that might change...