Skip to content
VirtualLP Virtual Learning Platform
Testing Tools P20a intermediate

Unit-test an authentication class with NUnit in Visual Studio

Create a .NET 8 class library and an NUnit test project in Visual Studio 2022, wire the project reference, implement AuthService, and verify valid, invalid, empty-input and lock-out scenarios in Test Explorer and with dotnet test.

What you'll do

  • Create class library and NUnit projects
  • Add a project reference
  • Write [Test] and [TestCase] tests with Assert.That and Assert.Throws
  • Run tests in Test Explorer and from the dotnet CLI

Lab tasks

  1. 1 Create the class library AuthSystem
  2. 2 Add the NUnit test project AuthSystem.Tests
  3. 3 Reference AuthSystem from the test project
  4. 4 Implement AuthService and build
  5. 5 Write the tests and run them – 10 passed
  6. 6 Watch a test fail
  7. 7 Run the suite with dotnet test