Types of testing (from fastest and most isolated to broadest) 1. Unit testing - Tests a single class or function in isolation, with dependencies replaced by mocks or fakes. - Fast and numerous; tools: xUnit, NUnit or MSTest for .NET; Jest or Vitest for JavaScript. 2. Integration testing - Tests components working together: API plus database, repositories plus SQL, message handlers plus a queue. - In ASP.NET Core: WebApplicationFactory with a real database in a container (Testcontainers). 3. Contract testing - Verifies that a provider API and its consumers agree on request and response formats (Pact, or OpenAPI-based validation). 4. End-to-end (E2E) testing - Tests complete user journeys through the UI and backend (Playwright, Cypress, Selenium). Fewer, slower, more brittle — focus on critical flows. 5. Functional and acceptance testing - Verifies features against requirements and acceptance criteria, often written as scenarios (BDD with Gherkin and Reqnroll/SpecFlow) and validated by QA or business users (UAT). 6. Regression testing - Re-running tests after changes to ensure existing features still work; mostly automated. 7. Smoke and sanity testing - Quick checks after deployment that the main functions work. 8. Non-functional testing - Performance and load testing (k6, JMeter, Azure Load Testing), stress and soak tests. - Security testing (SAST, DAST with OWASP ZAP, dependency scanning, penetration testing). - Accessibility testing (axe, Lighthouse), usability and compatibility testing. 9. Other techniques - Mutation testing (Stryker) checks whether tests catch injected bugs. - Exploratory testing by humans. The test pyramid: many unit tests, fewer integration and contract tests, and few E2E tests — balancing speed, cost and confidence. Code coverage - Measures how much code is executed by tests: line, branch and method coverage. Branch coverage is more meaningful than line coverage because it checks both sides of conditions. - .NET tooling: Coverlet (dotnet test --collect:"XPlat Code Coverage"), ReportGenerator for HTML reports, or Microsoft's code coverage tools; SonarQube or Codecov for tracking over time and pull-request gates. - Use it wisely: coverage shows untested code but does not prove tests are good — tests without meaningful assertions still increase coverage. Many teams target 70–80% on business logic and enforce coverage on new code rather than chasing 100%. Exclude generated code, migrations and trivial DTOs.
Ravindra Wadile · · 0 likes