Testing in .NET in Testing & Verification
Testing in .NET is the third chapter of the free Testing & Verification course. It repeats the main ideas of the course for C# and ASP.NET Core teams.
What each lesson covers:
- Testing in .NET with xUnit: facts, theories, Assert.Equal and Assert.Throws, decimal for money, fakes, and AI mistakes in a C# diff.
- Spec First and Mutation Testing in .NET: fail first in C#, tests from a ticket, and Stryker.NET mutation testing.
- Properties and Integration in .NET: FsCheck properties, contracts with System.Text.Json, WebApplicationFactory, and characterization tests.
- .NET Gates, Security and Capstone: the test-diff guard, the definition of done, CI with dotnet test and Stryker.NET, secrets, injection and NuGet checks.
Every C# box runs in your browser on the site's .NET runner, with the real xUnit library: [Fact], [Theory], [InlineData] and Assert. A file of test classes runs like dotnet test. Exercises run your xUnit tests on the correct code and on planted bugs, and compare the result with the answer key.
Lessons in this section
- Testing in .NET with xUnit
The course ideas in .NET: xUnit facts and theories, Assert.Equal and Assert.Throws, decimal for money, fakes behind interfaces, and the AI mistakes to look for in a C# diff.
- Write xUnit facts and theories
- Use Assert.Equal and Assert.Throws correctly
- Use decimal for money and round correctly
- Fake the edges behind an interface
- Spec First and Mutation Testing in .NET
Make C# tests fail on the old code first, turn ticket criteria into xUnit tests, and measure them with mutants: Stryker.NET in real projects, hand-made mutants in the lab, and how to read the report.
- Show a C# test fails on the old code first
- Turn acceptance criteria into xUnit tests
- Explain what Stryker.NET does and read its report
- Kill surviving mutants with exact checks at the edges
- Properties and Integration in .NET
Property tests with FsCheck and shrinking, API contracts with System.Text.Json, integration tests with WebApplicationFactory, and characterization tests with old-vs-new checks before an AI refactor of C# code.
- Write properties and read shrunk counterexamples
- Check API responses against a contract with System.Text.Json
- Explain how WebApplicationFactory runs real integration tests
- Pin old C# code and compare old vs new on many inputs
- .NET Gates, Security and Capstone
The gates for .NET teams: a test-diff guard for xUnit and Stryker.NET config, the definition of done in C#, dotnet test and Stryker.NET in CI, secrets in appsettings.json, SQL and HTML injection, NuGet package checks, and a short capstone.
- Guard xUnit tests and Stryker.NET config against fake green
- Write the definition of done in C#
- Wire dotnet test and Stryker.NET into CI
- Catch secrets, SQL injection, HTML injection and risky NuGet packages