Join Kit Eason for an in-depth discussion in this video Working with the sample code, part of F#: Automated Testing for Developers.
- [Instructor] If you have access to the exercise files for the course, you can download them to a convenient location. I've got them here in my downloads folder. They come as a zip file, and I'm going to unzip that just to the root folder of my C drive. There they are there. When choosing a place to unzip to, just bear in mind that some of the NuGet packages that these projects use have quite long names, so if you unzip them deep into the file system, you may get errors as a result of the overall path being too long.
That's why I put them right up here. Once you've unzipped them, you'll see that there's a folder for each video in the course, and within that, there's a begin and an end folder. The begin folder is the state your code needs to be in at the start of the video. The end folder is the state the code would be if you followed along with the whole video and typed everything I typed. If the video expects you to create everything from scratch, there won't be a begin like in this example.
On the other hand, if the video doesn't involve changing anything, there won't be an end. Let's open an example up. Here's the official Studio solution you need to be opening. I'm just going to open the code file. Most of the examples involve a code file called ParseName.fs, and you'll see there's a comment here that tells you what you need to do to get the program compiling, and that is to copy this command, go to tools, NuGet package manager, package manager console.
You can ignore this message about NuGet packages being missing. That's the thing we're going to fix, but don't click restore here. Instead, paste that command, go back to the code file, copy that command, and paste that. I do explain this in more detail within the videos, but if you happen to dive in halfway through, you may not know about this, so you'll need to do these two commands, and they will download the necessary NuGet packages.
You'll need to be on a reasonable internet connection for this. If I go to build, rebuild solution, you'll find that the rebuild succeeded. You'll see a message down here. However, you may also notice if you open up some of the code files, you may occasionally see red squigglies. In that case, yes, actually look here's a red squiggly up here. If that happens, you may need to close the file, wait a little while, try reopening it, and the problem may go away.
Kit Eason explains how to use xUnit—a .NET unit-testing package—to do some test-driven development, and demonstrates how to improve your test run experience using NCrunch, a test runner. He shows how to use FsCheck to generate test cases, and how to use Expecto to move into the world of tests as first-class values. He also covers the use of Canopy to automate the testing of web user interfaces, and of mocking to tame dependencies.
- Solving issues with early versions of Visual Studio 2017
- Classical unit testing with F#
- Creating a testable project and installing Paket and xUnit
- Test driving an implementation
- Improving your test run experience with NCrunch
- Going beyond test cases with FsCheck and Unquote
- Making tests first class using Expecto
- Using mocking to tame dependencies
- Web UI testing with Canopy