.NET Developer interview question

What is your .NET testing strategy?

Use unit tests for domain logic, WebApplicationFactory tests for the HTTP pipeline, integration tests with real data stores for EF queries, and focused end-to-end tests; control clocks, cancellation, and external clients.

Direct answer

What a strong answer covers

How it works

Domain logic is tested with xUnit or NUnit and no infrastructure. The HTTP pipeline is tested with WebApplicationFactory, which boots the real application in memory with test overrides for external clients and a test database, so routing, model binding, validation, filters, and authorisation run as in production. EF Core queries run against a real provider in a container rather than the in-memory provider, which does not behave like SQL. Time comes from an injected TimeProvider, external HTTP through a fake handler, and cancellation is tested by triggering the token. A few end-to-end tests cover critical journeys.

Example

OrdersApiTests uses WebApplicationFactory with a Testcontainers PostgreSQL instance and a fake payment handler; it posts an order, asserts 201 and the Location header, then asserts the row exists. A unit test for the pricing engine injects a FakeTimeProvider to check a promotion boundary at midnight, with no database involved.

Common mistakes

  • Using the EF in-memory provider and shipping SQL that fails on the real database.
  • Testing controllers by calling methods directly and skipping model binding and filters.
  • Depending on DateTime.UtcNow so time-sensitive tests fail on the wrong day.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
.NET Developer interview questions