A minimal template for setting up a .Net Console App project with unit tests using NUnit in VSCode.
References
- https://code.visualstudio.com/docs/languages/csharp
- https://code.visualstudio.com/docs/csharp/get-started
- https://code.visualstudio.com/docs/csharp/testing
- https://docs.nunit.org/articles/nunit/getting-started/installation.html#im-using-visual-studio-code-as-my-development-tool
- https://docs.nunit.org/articles/nunit/running-tests/Index.html
Pre-requisites: Have the .Net SDK installed on your local machine.
dotnet run --project ConsoleApp
Run all unit tests
dotnet test
ConsoleApp
and TestProject
can be renamed to any other new name by renaming all the files and replacing all occurences of the original names to their new names. See this repository for an example.
If you have a different .Net SDK version, change the <TargetFramework>
field in AdventOfCode.csproj and UnitTests.csproj to the corresponding version that you have.
The setup steps used to create this template.
In root directory, using VSCode Command Pallete with C# Dev Kit installed: .Net: New Project > Console App.
Name the project ConsoleApp
.
In the ConsoleApp
directory, Run the following to create a .gitignore
file.
dotnet new gitignore
In the ConsoleApp
directory, Run the following command to run the Program.cs
file.
dotnet run
In root directory, using VSCode Command Pallete with C# Dev Kit installed: .Net: New Project > NUnit 3 Test Project.
Name the project TestProject
In the TestProject
directory, Run the following to create a .gitignore
file.
dotnet new gitignore
In the root directory, run the following command to reference the main project ConsoleApp
in the test project TestProject
.
dotnet add TestProject/TestProject.csproj reference ConsoleApp/ConsoleApp.csproj