Unit test the business logic in isolation, faking only real boundaries. Then write integration tests that host the whole app in memory with WebApplicationFactory and call real endpoints over HTTP, against a real database engine, typically in a container, rather than the EF Core in memory provider, which does not behave like a relational database. Reset data between tests, and fake only the external services you do not own.
Why interviewers ask this
Testing strategy reveals how confident a developer can be about their changes. The interviewer wants a sensible split between unit and integration tests, knowledge of WebApplicationFactory, and awareness that the in memory provider gives false confidence, since it ignores constraints, transactions and SQL translation. Explaining how you keep integration tests fast and isolated shows you have maintained a suite rather than written a few tests once.
How to structure your answer
- Describe what you unit test and what you fake.
- Explain integration tests with WebApplicationFactory.
- Justify a real database over the in memory provider.
- Cover isolation, speed and external dependencies.
Example answer
I split it by what each kind of test can actually prove. Unit tests cover business logic with no framework involved, and I only fake true boundaries, not every class. Most of my confidence comes from integration tests. WebApplicationFactory hosts the whole application in memory, with the real middleware and dependency injection, and I call endpoints with an HttpClient exactly as a client would. For the database I use the real engine in a container, started once per test run. I avoid the EF Core in memory provider, because it does not enforce constraints, handles transactions differently, and will happily run queries that would fail to translate to SQL, so tests pass and production breaks. Each test either runs in a transaction that rolls back or resets its data with a quick cleanup step, so tests never depend on each other. External services I do not own, like a payment provider, are swapped for fakes in the factory configuration. That suite has caught migration and query bugs unit tests never could.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How do you override a service registration inside WebApplicationFactory?
- How would you test authorisation rules on an endpoint?
- How do you keep integration tests fast as the suite grows?
Related .net developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions