📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

.NET Testing Tools

xUnit, NUnit, MSTest, Moq, NSubstitute, FakeItEasy, FluentAssertions and its alternatives, AutoFixture, Testcontainers, WebApplicationFactory and WireMock.Net.

  1. How do you share an expensive resource, such as a database container, across many xUnit test classes without starting it once per test?

    Sharing an expensive test resource (such as a SQL Server container) across xUnit test classes with IAsyncLifetime, class, collection and xUnit v3 assembly fixtures, and keeping tests independent with Respawn or unique keys.

    Junior Theory .NET Testing Tools Β· πŸ”— 1 follow-ups
  2. What are the different kinds of test doubles (dummy, stub, fake, mock, spy), and when would you write a hand-rolled fake instead of using a mocking library?

    The five kinds of test double (dummy, stub, fake, mock, spy), how they differ in state versus interaction verification, and when a hand-rolled fake beats a mocking library in .NET 10 tests.

    Junior Coding .NET Testing Tools Β· πŸ”— 1 follow-ups
  3. When would you use snapshot testing with Verify instead of writing explicit assertions?

    When snapshot testing with Verify beats explicit assertions, how .verified and .received files, scrubbing and accepting changes work, and how to keep snapshots reviewable and maintainable.

    Intermediate Theory .NET Testing Tools
  4. How do you stop a package update from silently changing the licence of a dependency in your solution?

    Preventing a NuGet update from silently bringing in a new licence: Central Package Management, pinned majors and lock files, Dependabot ignore rules, CI licence allow-lists (dependency-review-action, nuget-license), and treating test packages like production dependencies.

    Intermediate Theory .NET Testing Tools
  5. How do you combine WebApplicationFactory with Testcontainers so each test class gets a real SQL Server database?

    Wiring a Testcontainers SQL Server into WebApplicationFactory: container lifecycle with IAsyncLifetime, overriding the connection string, migrating once, resetting with Respawn, and sharing one container across classes with a database per class.

    Mid-Level Coding .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  6. How do you configure and test retries, timeouts and circuit breakers for an HttpClient in .NET 10?

    Configuring HttpClient resilience in .NET 10 with Microsoft.Extensions.Http.Resilience (the standard handler's strategies and defaults, attempt versus total timeout, no blind retries on unsafe methods, custom Polly pipelines) and testing it deterministically with WireMock.Net.

    Mid-Level Coding .NET Testing Tools Β· πŸ”— 1 follow-ups Β· πŸ›  1 real-world
  7. How do you manage test data across unit, integration and end-to-end tests without using production data?

    Managing test data at each level of the test pyramid without production data: builders and object mothers for unit tests, unique data and Respawn resets for integration tests, seeded synthetic data (Bogus) for end-to-end environments, edge cases, versioned seed scripts, and Australian privacy obligations.

    Intermediate Theory .NET Testing Tools Β· πŸ”— 1 follow-ups
  8. Flaky tests are blocking releases. How do you find the cause, decide whether to quarantine, and stop new flaky tests from appearing?

    A team-level approach to flaky tests in .NET: measuring flakiness from CI test reports, reproducing failures (loops, parallelism, limited CPU, blame options), the common root causes, a visible quarantine with an owner and deadline, and prevention with TimeProvider, banned-API analysers, xUnit analysers and a flaky-rate dashboard.

    Senior RealWorldScenario .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. xUnit, NUnit and MSTest: how do they differ? Compare the test lifecycle (instances, setup and teardown), shared fixtures, parameterised tests and parallelism, and explain what changed in xUnit v3.

    Compares xUnit, NUnit and MSTest on test-class lifecycle, setup and teardown, shared fixtures, data-driven tests and parallel execution, and covers xUnit v3 and Microsoft.Testing.Platform on .NET 10.

    Junior Theory .NET Testing Tools Β· πŸ”— 2 follow-ups
  10. How do you mock dependencies in .NET unit tests with NSubstitute and Moq? Show how you set up return values, use argument matchers, verify calls and simulate exceptions, and tell me what happened with Moq and SponsorLink in 2023.

    Covers creating substitutes with NSubstitute and Moq, configuring returns, argument matchers, verifying received calls, throwing exceptions, async members, analysers, and the 2023 Moq SponsorLink supply-chain controversy.

    Junior Coding .NET Testing Tools Β· πŸ”— 2 follow-ups
  11. Which assertion library would you use in a .NET test project in 2026? Explain what happened to FluentAssertions' licence, compare the alternatives (AwesomeAssertions, Shouldly, the framework's built-in asserts), and tell me how you'd decide.

    Covers the FluentAssertions v8 move to a commercial Xceed licence, the AwesomeAssertions fork, Shouldly, built-in xUnit/NUnit/MSTest asserts, structural equivalence, failure-message quality and how to choose and migrate.

    Intermediate Theory .NET Testing Tools Β· πŸ”— 2 follow-ups
  12. How do you test an ASP.NET Core API in memory with WebApplicationFactory? Show how you replace services for a test, handle authentication so protected endpoints can be called, and keep tests isolated from each other.

    Covers WebApplicationFactory and TestServer: bootstrapping Program, ConfigureTestServices to swap dependencies, a test authentication handler for protected endpoints, per-test configuration, isolation and what in-memory tests do and do not prove.

    Mid-Level Coding .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  13. How do you use Testcontainers for .NET to run tests against a real SQL Server and Redis? Show the fixture, explain how you keep the tests fast (sharing, reuse, resetting data) and what you need to run them in CI.

    Covers Testcontainers for .NET modules for SQL Server and Redis, IAsyncLifetime fixtures, sharing containers per class or collection, container reuse, resetting data with Respawn, wait strategies, Ryuk clean-up, and running in GitHub Actions and Azure Pipelines.

    Mid-Level Coding .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  14. Your service calls a third-party HTTP API. How do you use WireMock.Net to test it, including the API being slow, returning errors or sending malformed responses? Show how you wire it into the app under test and verify what was sent.

    Covers WireMock.Net as a real HTTP stub server for outbound calls: request matching, JSON responses, delays, faults and stateful scenarios, wiring the base URL into WebApplicationFactory, verifying requests from the log, and testing resilience pipelines.

    Mid-Level Coding .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  15. What are AutoFixture and the test data builder pattern? How do they reduce setup noise in tests, when do they hurt readability, and how would you choose between AutoFixture, Bogus and hand-written builders?

    Covers AutoFixture (Create, Build/With, AutoData, Frozen, AutoNSubstitute), hand-written test data builders and Object Mothers, Bogus for realistic synthetic data, and the trade-off between anonymous values and readable, intention-revealing tests.

    Intermediate Theory .NET Testing Tools Β· πŸ”— 2 follow-ups
  16. Code review: a test project for an order-processing service mocks every class including the repository and DbContext, waits for background work with Thread.Sleep(3000), shares a static list and DateTime.Now between tests, and asserts on exact log message text through a mocked ILogger. What is wrong, in order of severity, and how would you rewrite it?

    A senior code review of a brittle .NET test suite: tests that cannot fail, shared static state, Thread.Sleep waits, real clock usage, over-mocking and log-text assertions, ranked by severity, with a rewrite using FakeTimeProvider, FakeLogger, real infrastructure and deterministic waits.

    Senior CodeReview .NET Testing Tools Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me