Welcome to the "From Zero to Hero: Testing with xUnit in C#" course on Dometrain!
This comprehensive course teaches you everything you need to know about testing in .NET using xUnit.net. You'll learn testing fundamentals, advanced assertion techniques, data-driven testing, test lifecycle management, and how to extend it.
Whether you're new to testing or looking to master xUnit.net, this course provides practical, hands-on experience and exercises.
This repository contains the source code for the course, which you can use to follow along.
The main branch contains the most up-to-date version of the code, reflecting the latest improvements, updates, and fixes.
Each section in the course has folder in the repository. The folder contains the source code for the section, containing both a /start
and /end
directory—which aligns with the source code at a point in time as it relates to the course.
- Section 2: Getting Started with xUnit.net
- Section 3: Test Fundamentals
- Section 4: Assertions
- Section 5: Data-Driven Testing with Theories
- Section 6: Test Lifecycle and Fixtures
- Section 7: Test Execution and Control
- Section 8: Output and Diagnostics
- Section 9: Reporting and Integration
- Section 10: Extensibility and Customisation
Install .NET 9 https://dotnet.microsoft.com/en-us/download/dotnet/9.0
dotnet new install xunit.v3.templates
https://xunit.net/docs/getting-started/v3/microsoft-testing-platform
- Open Settings → Build, Execution, Deployment → Unit Testing → VSTest
- Ensure Enable Microsoft Testing Platform support is checked
- Apply settings and restart IDE if prompted
- Go to Tools → Manage Preview Features
- Enable Use testing platform server mode
- Restart Visual Studio to apply changes
- Install the extension Name: C# Dev Kit
- Go to the C# Dev Kit extension's settings
- Enable Dotnet > Test Window > Use Testing Platform Protocol
- Microsoft Testing Platform Documentation
- Microsoft Testing Platform vs VSTest
- Microsoft Testing Platform - Why we moved from VSTest
Microsoft Testing Platform:
dotnet run -p tests/OutputDiagnostics.Core.Tests --output detailed --filter-query "/OutputDiagnostics.Core.Tests/OutputDiagnostics.Core.Tests.DiagnosticMessages/OrderProcessorTests/ProcessOrder_WithInvalidCustomer_ProvidesContextualFailureInfo"
VSTest:
dotnet test --logger "console;verbosity=detailed" --filter "FullyQualifiedName=OutputDiagnostics.Core.Tests.DiagnosticMessages.OrderProcessorTests.ProcessOrder_WithInvalidCustomer_ProvidesContextualFailureInfo"
Microsoft Testing Platform:
dotnet run -p tests/OutputDiagnostics.Core.Tests --output detailed
VSTest:
dotnet test --logger "console;verbosity=detailed"
# Run tests by category dotnet test --filter "Category=Unit" # Run tests by trait dotnet test --filter "Priority=High" # Run tests by name pattern dotnet test --filter "Name~Calculator"