Back to course

Introduction to Unit Testing

C# Zero to Hero: Comprehensive Programming Masterclass

Unit Testing with xUnit

Unit testing ensures that individual units of source code work as expected.

A Simple Test

csharp [Fact] public void Add_ShouldReturnCorrectSum() { // Arrange var calculator = new Calculator(); // Act int result = calculator.Add(2, 2); // Assert Assert.Equal(4, result); }

Writing tests makes your software more reliable.