Setting Up Test Driven Development
Video
Setting Up For Unit Testing With MSTest
The stubbed project created by OpenAPI Generator has given us enough code so that we can write tests which reference the various controllers. One issue which developers often struggle with while practicing Test-Driven Development is that you cannot write a test for code which doesn't exist in strongly-typed languages, but the generated code allows us to overcome that difficulty.
- Add a new Tests project to your solutionbash
cd <solution root> dotnet new mstest -o src/RedHat.TodoList.Tests
- Change directory to the Tests project and add a reference to the project being testedbash
cd src/RedHat.TodoList.Tests dotnet add reference ../RedHat.TodoList/RedHat.TodoList.csproj
- Install the Moq package for mocking objects in testsbash
dotnet add package Moq
- From this point forward, we will attempt to write tests first and then implement our code to satisfy those tests.