In this course, you'll learn about the basics of writing and running unit tests with F#. You'll learn about some of the specific tools and techniques unique to the combination of F# and unit testing. Among other topics, you'll learn about the importance of using F#'s Structural Equality to your advantage, and you'll get a comprehensive introduction to the Unquote open source assertion library.
Mark Seemann is the author of Dependency Injection in .NET and the inventor of AutoFixture. He is a professional programmer and software architect living in Copenhagen, Denmark, and currently an independent advisor. He enjoys reading, drawing, playing the guitar, good wine, and gourmet food.
Introduction Hello. My name is Mark Seemann, and this is the Unit Testing with F# course, module one, Introduction. Before I subject you to all the boring details of the prerequisites of this course, its table of contents, and so on, I'd like you to know that unit test with F# is easy. In fact, I find it much easier than with C#. This may sound surprising, so perhaps this parable will help. A long time ago, programmers couldn't imagine programming without the GOTO statement. Then in 1968, Dijkstra published his famous paper, Go To Statement Considered Harmful. In that paper, he argued that code could be written better without GOTO statements. Although this claim triggered much controversy, ultimately Dijkstra's viewpoint won, and today we consider GOTO statements residue from the past. When was the last time you used a GOTO statement in our code? Consider the situation before and after. Before, programmers had various language features available, such as GOTO, IF, and WHILE. Then after Dijkstra's viewpoint won, you had fewer language features than before. Programming without GOTO is easier. This is surprising. Removing a language feature makes programming easier. You'll have to learn to think about programming problems in a new way, but once you've mastered that, the lack of a redundant feature turns out to be beneficial, because your code becomes easier to reason about. This is similar to functional programming. With object oriented programming, there are many language features that you can do without; null, state mutation, or side effects, reference equality, and cyclic dependencies. You'll need to learn to program without these language constructs, but once you do, you'll find that since there's less variability to consider, code is easier to reason about. It's also easier to unit test.
Test Frameworks and Runners Hello. My name is Mark Seemann, and this is the Unit Testing with F# course, module 2, Test Frameworks and Runners. The easiest way to write and run automated tests is to use existing frameworks. For. NET, there are three major frameworks to choose from. NUnit is the oldest. MSTest is Microsoft's built in framework, which comes with most versions of Visual Studio, and xUnit. net is the most recent. There are other frameworks available, but these are the three dominant players. It's not enough to be able to write test code, you also have to run it. For this, you need a test runner. NUnit comes with a command line runner, as well as a dedicated GUI runner. Likewise, MSTest as an associated console runner, but you can also use Visual Studio to run your unit tests. And keeping with this pattern, xUnit. net also has a dedicated command line runner, and a GUI runner. Since Visual Studio 2012, Visual Studio has had a plugin model for running unit tests, so you can also use Visual Studio to run NUnit and xUnit. net tests. Apart from these basic test runners, various commercial third-party plugins for Visual Studio exist. For example, ReSharper can be used to run unit tests, besides all the other things it can do. Another add-in for Visual Studio, is NCrunch, which runs tests continuously by detecting whenever your code changes. A third add-in is TestDriven. Net, which may look unsexy, but has the advantage that it's very keyboard friendly. This is why I like it, so I use it for my daily work, as well as in this course, together with xUnit. net.