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

Your test is a ninja


The reason that your test fails should be exact because it doesn't fulfill the promise of how the test is named. There should be no other reason for the test to fail, and it should be given no chance of failing because of anything else.

In many cases, we need to run a lot of code in order to get to the state that we want to test. This is a potential problem, because the code that we're passing through might fail and give us a failing test, but for a completely other reason than why the test was written. This is bad, because it makes the test suite hard to understand and hard to bug trace.

The only way to get around this problem is to limit the amount of code needed in order to run our tests, and that we can only do by refactoring the SUT. Bring in a state record that can be sent into the routine that we want to test and fake. This is one way to shorten the path to our unit. Another way is to reduce dependencies and reduce the size of the function. Often, we have to deal...