wasAsked.

Describe a practical strategy for unit, integration, contract, and end-to-end testing in a .NET full-stack product.

BrowserStack · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, React, Testing

Community answers

Posted by wasAsked editorial collection

Use a test pyramid driven by risk. Unit-test pure domain rules, integration-test database mappings and external adapters, and keep a smaller set of end-to-end tests for critical user journeys. Example: [Fact] public void Rejects_negative_quantity() => Assert.Throws<ArgumentOutOfRangeException>(() => new Line(-1, 10m)); For API integration tests, use WebApplicationFactory, a real disposable database matching production, and authenticated test identities. Test success, validation, authorization, tenant isolation, concurrency, cancellation, and dependency failures. Make tests deterministic: control time and IDs, avoid shared mutable fixtures, and assert observable behavior rather than implementation details.

Backbencher Developer · · 0 likes

Use a test pyramid shaped by risk: many fast unit tests, fewer integration and contract tests, and a small set of end-to-end tests for critical journeys. Unit tests (xUnit/NUnit on the backend, Vitest/Jest with React Testing Library on the frontend) - Cover domain rules, validation, calculations and component behaviour. - No database or network; dependencies replaced with fakes. - Run in seconds on every commit. Integration tests (backend) - Use WebApplicationFactory to host the real API in memory. - Run against a real database engine in a disposable container (Testcontainers for SQL Server or PostgreSQL) rather than the EF in-memory provider, which hides SQL behaviour. - Test endpoints end to end inside the service: routing, model binding, validation, authorization, EF mappings, migrations and error responses. Contract tests - Protect the boundary between the React app (consumer) and the API (provider), or between microservices. - Pact-style consumer-driven contracts, or validating responses against a published OpenAPI schema, catch breaking changes before deployment. End-to-end tests (Playwright or Cypress) - A handful of journeys: sign in, the main purchase or create flow, payment, permissions. - Run against a deployed test environment with seeded data; keep them stable with test IDs and explicit waits for state, not fixed sleeps. Supporting practices: - Run unit and integration tests on every pull request, E2E on merge or before release. - Track flaky tests and fix or quarantine them quickly. - Measure coverage as a signal, not a target; focus on critical paths and bug-prone areas. - Add a regression test for every production bug. - Include non-functional checks where relevant: accessibility (axe), performance smoke tests, security scanning. The goal is fast feedback for developers and confidence that a release will not break the paths that make money or protect data.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics