
Welcome to the second edition of the course. This course has been refreshed from the ground up based on 4000 students' feedback and reviews.
To utilize xUnit optimally, we need to know what unit testing is and where it is used. After watching this lecture, ask yourself, "What is Unit Testing?" and answer your question using what you have learned to measure your understanding of unit testing and its application.
Learn about the main features and design goals of xUnit .Net
View and run unit tests in Visual Studio with Test Explorer, run all or selected tests, and debug with breakpoints using dotnet test in the project directory and ci/cd workflows.
Compare xUnit net v2 and v3 within the Microsoft Testing Platform, highlighting determinism, runtime transparency, and compile-time extension registration with zero dependencies.
Learn that how you will add the required NuGet packages and how you will write your first ever test method with XUnit
Learn to run and debug unit tests with the Microsoft Testing Platform in Visual Studio, using test menu, test explorer, breakpoints, and dotnet run or run failed tests.
Learn a common unit test naming style by composing the test: method name, predicate, and expected result, illustrated with a calculator add method and constant values.
Learn to use the xunit net assert class in the arrange-act-assert flow, test integer sums, and validate results with assert.equal, including decimal precision and rounding.
Learn to assert string values with xUnit by building a names class that returns a full name, and write tests for equality, ignore-case, contains, startswith, endswith, and regex.
Demonstrates asserting boolean and null values in a .NET 9 xUnit by testing a nickname is null before and after make full name, with null, not null, and empty checks.
In this coding practice, you will write unit tests for a real-world project.
Demonstrate asserting collections in a .NET 9 xUnit test by generating a fibonacci sequence with IEnumerable and yield return, then verify the first values and containment checks.
Explore asserting value ranges by implementing an age-based discount method and testing it with xUnit, ensuring discounts stay between 5% and 20% for ages over 18.
Showcases asserting exceptions for a discount percentage method when age is below 18, catching an invalid data exception with Assert.Throws and combining act and assert for safe test execution.
Assert object types in xUnit, distinguishing loyal and normal customers, using is type and is not type, with a factory and discount checks.
Explore fluent assertions to improve test readability, install the library via NuGet, and rewrite tests with should-style checks (not be null or empty, contains, regex, exact counts), including async compatibility.
Organize xUnit tests by applying trait categories such as calculator and fibo, then group or run them in parallel for faster feedback.
Learn to generate and capture test logs in xUnit with ITestOutputHelper, injecting it into tests and writing output visible in Visual Studio Test Explorer and CI CD tools.
Learn how to use class fixtures and IClassFixture in xUnit .NET v3 to share a singleton calculator instance across tests, with thread safety, in fibonacci tests.
Learn to share an object across test classes using Xunit.net collection definitions and collection fixtures, illustrated by an insurance example with a shared interest rate.
Learn to filter and order xunit tests at runtime using trait attributes, filtering by category such as calculator or fibo, and organizing execution with collections in xunit net v3.
Demonstrates parameterized unit testing in xUnit .net v3 using the theory and inline data attributes to test a calculator's add method with multiple inputs, avoiding hard-coded values.
Discover how to share test data across xUnit tests using member data, replacing inline data, and reuse values for int and decimal add tests.
Create a custom add data attribute to share test data across multiple unit test methods, enabling values from external resources like a csv, excel, or api.
Learn to mock the data access layer to unit test the business logic in .NET, using interfaces and frameworks like Moq, NSubstitute, and FakeItEasy.
Clone the repository, add a test project, and implement unit tests using the mocking technique for the core library and the personal photos app; configure database and appsettings for testing.
Write xUnit v3 tests for core and personal photos projects, starting with personal photos to learn mocking. Use mocked ILogins and HttpContextAccessor to test login controller with invalid model state.
Learn to unit test in .NET 9 with Moq by setting up mocks for get user and returning a user, then validate redirect to the login controller's photos display action.
Master moq, setupget, and advanced mocking to unit test the photos controller upload, mocking HttpContext, session, file storage, and view model to verify redirect to display action.
Master unit testing .NET 9 apps with xUnit by mocking file operations. Learn to introduce AI file operations, inject dependencies, and verify path.combine and directory exists calls with Moq.
Learn to test a minimal web API with xUnit v3 using a web application factory, calling the test me endpoint with id and asserting the id in the JSON response.
Test a minimal web api with dependencies by using a custom web application factory and an in-memory ef core database in a testing environment, avoiding sql server.
Write unit tests before code using a red-green-refactor cycle to drive production code in test driven development, gaining guardrails, safer refactoring, and better design, with awareness of learning curves.
Explore test driven development by writing tests first for a calculator and an add method that returns the sum of two ints, driving design with xUnit and Visual Studio.
Learn to unit test legacy code to prevent new bugs, despite old dependencies and missing SOLID principles, and explore techniques for adding tests incrementally to existing projects.
Apply the sprout method to legacy code by adding new testable methods and using test driven development to test them with xUnit in a .NET 9 context.
Apply the sprout class technique to isolate dependencies by adding a new class that mirrors the legacy one, drive tests with xUnit and mocks, and enable test driven development.
Learn how unit test coverage types—statement, branch, function, and condition—identify untested code, and compare Coverlet and Microsoft Testing Platforms Coverage Calculator formats like JSON, Cobertura, and XML.
Measure unit test coverage in xUnit.net with coverlet by running dotnet test with collect coverage, generating json or open cover reports for CI/CD pipelines.
Measure unit test coverage in xUnit.net with the Microsoft Testing Platform to generate coverage reports for a console app and an xUnit v3 project, using XML and cobertura outputs.
Master Unit Testing in .NET with xUnit v3 and Microsoft’s New Testing Platform
If you're a .NET developer aiming to write better, more reliable code, this second edition course is built for you. You'll dive deep into unit testing using xUnit v3 and Microsoft Testing Platform—the modern replacement for the legacy VSTest framework.
xUnit v3 is fully compatible with Microsoft’s new testing platform and comes packed with new features that make writing and running tests easier and more powerful. It's one of the most popular testing frameworks in the .NET ecosystem, and knowing how to use it is a must for any serious .NET developer.
In this course, we focus on practical, real-world .NET projects, including ASP .NET MVC and ASP.NET Minimal Web APIs. You'll learn how to:
Write effective unit tests using xUnit and MOQ
Apply Test-Driven Development (TDD) in your workflows
Work with the latest versions of .NET and C#
We’ll also tackle more advanced topics:
Testing legacy code
Measuring code coverage
Evaluating the quality of your tests—because 100% coverage doesn’t always mean 100% confidence
And we go a step further with a module on security testing—showing you how to catch vulnerabilities that functional tests often miss.
To help you level up your career, we’ve included interview questions and answers related to unit testing and xUnit, so you can walk into your next job interview with confidence.