Here are some guides to setup a Shouldly project.
In this guide, we will set up a project with Shouldly unit tests.
We won't use Visual Studio, we will build our project bare bones with Dotnet CLI and a text editor.
Install Dotnet CLI Tools.
You need to install a text editor (Notepad++, VSCode, etc...).
The project structure will be as follows:
/project-nameproject-name.sln/program.../test
Create your root directory, name it your project name.
Open a terminal in your root directory.
Run dotnet new sln
.
Go into program folder and run dotnet new classlib
.
Rename Class1.cs to Program.cs.
Add the following code to Program.cs:
using System;​public static class Program{public static string TestWorks(){return "Works";}}
Go to the root folder and run dotnet sln add program/program.csproj
, in order to add program to your solution.
In this part we will create the unit tests for the main program.
Move to test folder and run dotnet new nunit
(you can use others unit tests frameworks but in this guide we will stick to nunit).
Add a reference to the main program by running dotnet add reference ../program/program.csproj
In the root folder add the tests to the solution by running dotnet sln add test/test.csproj
.
Now comes the important part, when we actually add Shouldly.
Go to the test folder and run dotnet add package Shouldly
, to add Shouldly as a NuGet Package.
Add the following code to UnitTest1.cs:
using NUnit.Framework;using Shouldly;​public class Tests{[Test]public void Test1(){Program.TestWorks().ShouldBe("Works");}}
To test your project, in your root folder run dotnet test
.
And there you go, you have a basic project with unit tests using Shouldly.
We created a classlib project using Dotnet CLI Tools, then added unit tests and added Shouldly as a NuGet package to be able to use Shouldly in our tests.