Environment Setup - NUnit Tutorial

Configure Project with NUnit assemblies

We always creates separate project when creating project for NUnit. According to naming conventions test project name should be [Project Under Test].[Tests]. For example, if we are testing the project name "CustomerOrderService" then test project name should be "CustomerOrderService.Tests".

Now we have two projects in our solution. In CustomerOrderService project, we write code for business logic and in second project CustomerOrderService.Tests we write test cases for CustomerOrderService project.

Our next step is to add Nunit assemblies.

Right click on CustomerOrderService.Tests and choose "Manage NuGet Packages".

Include namespace NUnit.Framework in namespaces section. Write the above code exactly in Class. We'll learn more about TestFixture attribute, Test attribute and Assert class in our next posts. Now Build the solution.

Choose visual studio Test Menu -> Windows -> Test Explorer.

Text Explorer shows Test function in Not Run Tests section. Choose Run All button to execute test cases.

In below of Test Explorer, it will show the result of Test1 test result. In the below screenshot, it is showing the result 'Test Passed - Test1'.

Now our Test project and TestRunner is configured properly. In next posts, we'll learn more about Nunit attributes and classes.