πŸ§ͺ

Testing

Testing Intermediate 2 min read 300 words

Testing strategies, frameworks, and best practices for .NET applications.


Contents

Core Guides

Testing Types


Quick Reference

Testing Pyramid

Layer Tests Speed Scope
Unit 70% Fast Single function/class
Integration 20% Medium Component interactions
E2E 10% Slow Full user workflows

Test Double Types

Type Purpose Use Case
Dummy Fill parameters Required but unused dependency
Stub Provide canned answers Repository returning test data
Mock Verify interactions Assert email service was called
Fake Working implementation In-memory database
Spy Record calls Track method invocations

Framework Comparison

Framework Style Best For
xUnit Modern, opinionated New .NET projects
NUnit Attribute-based Full-featured testing
MSTest Microsoft’s framework VS integration
Playwright Browser automation E2E testing

Best Practices

  1. Test behavior, not implementation - Focus on what, not how
  2. Keep tests fast and independent - No shared state between tests
  3. Use meaningful test names - MethodName_Scenario_ExpectedResult
  4. Follow the testing pyramid - More unit tests, fewer E2E tests
  5. Use realistic test data - Builders and fixtures for consistency
  6. Mock at boundaries - External services, not internal classes

πŸ“š Related Articles