Setting up a NUnit Project

Introduction

Unit tests test code. Before writing unit tests, you will need to write and run code. Given that the course focuses on the NUnit testing framework, and that NUnit tests code written in the .NET supported languages (including C#), you will need to write and execute code in the C# language. To write and execute C# code, you will need to set up the requisite environments. Thereafter, you may set up the NUnit testing environment.

Setting up developing in C#

To develop in C# and to test C# code, you will need to set up the .NET environment. Fortunately, setting up the .NET environment is a seamless process. Follow the steps below to set up a .NET environment:

  • Source a computer with the Microsoft Windows/MacOS operating system (preferably Windows 10).
  • Download Visual Studio 2022 (community edition) with .NET at the following link.
  • Ensure that the option selected includes “Visual Studio with .NET.”
  • Wait for the installer to completely download. Once downloaded, open the installer. If User Account Control prompts you to allow the app to make changes to your device, you may select “yes.”
  • Wait for the installer to finish downloading and installing Visual Studio.

Writing your first C# application

You will exclusively write code as console applications and test the code contained in the console application. Follow the steps below to get started:

  • Open Visual Studio.
  • Select “Create new Project.”
  • Select “Console App.” This option may be found more easily by filtering by C#, Windows and Console for the language, platform and application type search criteria, respectively.
  • Assign a project name and location in your preferred directory.
  • Select your preferred latest release of the .NET framework.

Choose an appropriate directory for your project. You can create a separate projects folder for this course and place all your projects in that folder. This will ensure that you can navigate to your projects quickly and effortlessly.

Our solution is currently called MyApp and this solution contains one project called “MyApp”. In the Program.cs file, paste the following code:

Get hands-on with 1200+ tech skills courses.