Lesson 40. Unit testing in F#
Let’s start this unit with a quick review of basic unit-testing tools and how they relate to F#. You’ll see
- How to approach unit testing in F#
- How to write unit tests with F# and Visual Studio
- How to use F# DSLs for popular unit-testing libraries
Earlier in this book, I touched briefly on unit testing and indicated that in F# you might not need as much unit testing as you have previously. This section provides an overview of what I consider different levels of unit testing, and how and where they’re appropriate in F#. This section also covers various forms of unit-testing practices, including test-driven development (TDD).
Let’s start by stating plainly and simply that, yes, there’s still a place for unit testing in F#. Although its type system allows you to implement some kinds of business rules in code so that illegal states are unrepresentable (and this is a worthy goal), many rules aren’t easily encoded within F#’s type system. Let’s partition tests into three groups—basic type system tests, simple rules, and complex rules—and see in which languages you might more commonly write these sorts of automated unit tests for them. Table 40.1 provides the details.