C# VS2026
Lesson 30 of 30

Debugging and Unit Testing

C# in Visual Studio 2026 — a hands-on guide for developers at every level.

Debugging in Visual Studio 2026

Visual Studio's debugger is one of the most powerful tools in your arsenal. Master it to find bugs in minutes instead of hours.

Breakpoints

Click in the left margin of any line (or press F9) to set a breakpoint. Press F5 to run — execution stops at the breakpoint and you can inspect every variable.

Debug Windows

WindowShows
LocalsAll variables in the current scope
WatchVariables and expressions you add manually
ImmediateEvaluate C# expressions on the fly
Call StackChain of method calls that led here
AutosVariables recently used

Unit Testing with xUnit

// Install: dotnet add package xunit
//         dotnet add package xunit.runner.visualstudio

public class MathHelperTests
{
    [Fact]
    public void Add_TwoPositiveNumbers_ReturnsSum()
    {
        int result = MathHelper.Add(3, 4);
        Assert.Equal(7, result);
    }

    [Theory]
    [InlineData(0, 0, 0)]
    [InlineData(-1, 1, 0)]
    [InlineData(100, 200, 300)]
    public void Add_VariousInputs_ReturnsCorrectSum(int a, int b, int expected)
        => Assert.Equal(expected, MathHelper.Add(a, b));
}

Running Tests

Open Test Explorer (Test → Test Explorer) and click Run All Tests. Green = pass, red = fail. Click any failing test to see the expected vs actual values.

🎉 Congratulations!
You have completed all 30 lessons of C# in Visual Studio 2026. You now have a solid foundation in C# — from variables and loops, through OOP, async programming, and testing. Keep building!