← .NET Core learning path
.NET Core · Module 9 of 10

Testing .NET applications

Write unit and integration tests.

📖 Key ideas

  1. Test frameworks: xUnit, NUnit, MSTest.
  2. Mock dependencies with Moq or NSubstitute.
  3. WebApplicationFactory runs integration tests in memory.
  4. Use Testcontainers for real databases in tests.
  5. Run dotnet test in CI pipelines.
💡 Real-life example: Tests are smoke detectors: quiet most of the time, loud the moment something breaks.
xUnitPopular .NET test framework
MoqMocking library
WebApplicationFactoryIn-memory test server
[Fact]xUnit test method attribute