Test-Driven Test Development

Writing a Red Test

Project Setup

Create an project folder somewhere. This is where you’ll be writing the test framework.

mkdir MiniSpec
cd MiniSpec

Consider making the folder a git repository to save changes as you walk thru this book:

git init

Let’s create a test project and write tests pretending that MiniSpec already works:

dotnet new console -n MyTests

A new console projects? Wait. What? Why in the… what? So: only console projects support
the new top-level statements in C# 9, so let’s define tests in a console project! This will
be an optional feature and, well, it’s just neato and I’d like to try it out! Let’s have fun.

This will create a new project folder MyTests/. Let’s go there and write our first test!

We’ll create a file containing 2 xUnit-style tests, one which should fail and the other should pass.

Rename the generated Program.cs file to Tests.cs and replace its content with the following: