NUnit interview questions and answers for .NET developers and SDETs
NUnit interview questions check whether you can write .NET tests that are readable, isolated and reliable: how fixtures and setup attributes run, how to parameterize tests with TestCase and TestCaseSource, how the constraint model of Assert.That works, and how to test async code and exceptions. Senior rounds move to shared state in fixtures, parallel execution, categories in CI, and why a suite that passes alone fails in the pipeline. Strong answers show you know the lifecycle well enough to predict what runs when.
By Evin JohnPublished 6 min read
Where NUnit questions come up
NUnit is one of the long-standing test frameworks for .NET, alongside xUnit and MSTest. You meet NUnit questions in C# developer interviews ("how do you test this class?"), in SDET and automation roles where NUnit drives Selenium or API tests, and in teams that maintain older .NET Framework code as well as modern .NET. Interviewers rarely want trivia about every attribute. They want to see clean tests, a correct mental model of the lifecycle, and good judgment about isolation. Language questions such as LINQ or async internals are on the C# interview questions page.
- Framework basicsAttributes, lifecycle, assertions and how tests are discovered and run.
- Write tests liveA small class is shared, often a calculator, validator or service with a dependency, and you write tests for it.
- Framework designFor SDET roles: how NUnit fits a Selenium or API framework, with base classes, configuration and reporting.
- Debugging the suiteTests that fail only in CI, only in parallel, or only after another test runs.
NUnit fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What do TestFixture and Test mark? | Structure | A fixture is a class holding tests and their setup; each Test method is one test. NUnit can find fixtures without the attribute when they contain tests, but marking them keeps intent clear. |
| SetUp versus OneTimeSetUp? | Lifecycle | SetUp runs before every test in the fixture; OneTimeSetUp runs once before any of them. TearDown and OneTimeTearDown mirror them afterwards. |
| Does NUnit create a new fixture instance per test? | Instance model | By default one instance is shared by all tests in a fixture, so fields keep values between tests unless SetUp resets them. Later NUnit releases add an attribute to opt into one instance per test case. xUnit, by contrast, creates a new instance for every test. |
| How do you run NUnit tests from the command line? | Tooling | With dotnet test, which needs the test SDK and the NUnit test adapter packages referenced in the test project. IDEs use the same adapter. |
| What is the constraint model? | Assertions | Assertions read as Assert.That(actual, Is.EqualTo(expected)), with constraints such as Is.Null, Has.Count.EqualTo, Does.Contain or Is.InRange. Constraints compose and give clear failure messages. |
| What happened to Assert.AreEqual? | Versions | The classic assertion style still exists, but in NUnit 4 it moved to a legacy ClassicAssert class, so new code usually uses Assert.That. Check which version the project uses before answering in detail. |
| How do you assert that code throws? | Exceptions | Assert.Throws<T>(() => ...) returns the exception for further checks, or use Throws.TypeOf<T>() with Assert.That. Use Assert.ThrowsAsync for async code. |
| Ignore versus Explicit? | Control | Ignore skips a test and reports it as ignored with a reason. Explicit runs a test only when it is selected directly, which suits slow or manual tests. |
| What does Category do? | Organization | Tags tests so runs can include or exclude them, such as Smoke or Integration, through runner filters in the IDE or CI. |
| How should an async test be declared? | Async | Return async Task, never async void, so NUnit can await it and see failures. |
Writing and parameterizing tests
using System;
using NUnit.Framework;
[TestFixture]
public class PriceCalculatorTests
{
private PriceCalculator _calc = null!;
[SetUp]
public void CreateCalculator() => _calc = new PriceCalculator();
[TestCase(10000, 0, 10000)]
[TestCase(10000, 10, 9000)]
[TestCase(8000, 25, 6000)]
public void Applies_percentage_discount(int priceCents, int percent, int expectedCents)
{
Assert.That(_calc.Discount(priceCents, percent), Is.EqualTo(expectedCents));
}
[Test]
public void Rejects_discount_over_100_percent()
{
Assert.That(() => _calc.Discount(10000, 120),
Throws.TypeOf<ArgumentOutOfRangeException>());
}
}- TestCase or TestCaseSource? TestCase holds constant values in the attribute, which suits a few simple rows. TestCaseSource points to a static member that yields cases, for objects, generated data or many rows.
- What do Values, Range and Combinatorial do? Values and Range supply data per parameter; by default NUnit combines every value with every other. Sequential pairs them up in order instead, and Pairwise reduces the combinations.
- How do you name tests? Describe the behavior and condition, for example a method under test, a scenario and the expected result. TestCase can also set TestName for readable reports.
- How do you check several things without stopping at the first failure? Group assertions in a multiple-assert block so all failures are reported together. Use it for checking several properties of one result, not for unrelated checks.
- How do you compare floating-point values? Add a tolerance with
.Within(...), since exact equality on doubles fails on rounding. - How do you assert on collections? Constraints such as Is.EquivalentTo for order-insensitive comparison, Is.Ordered, Has.Exactly(n).Matches(...), and Is.Unique.
- What is TestContext for? Reading the current test's name and result, writing output to the test log, and attaching files such as screenshots to a result.
Isolation, mocking and parallel run questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How do you test a class that calls a database or an API? | Isolation | Inject the dependency through an interface and replace it with a fake or a mock in unit tests. NUnit has no mocking library of its own; teams pair it with libraries such as Moq or NSubstitute. |
| Mock or stub? | Test doubles | A stub returns canned answers so the code can run. A mock also verifies interactions, such as a method called once with certain arguments. Over-verifying interactions makes tests brittle. |
| Why do tests pass alone but fail together? | Shared state | A shared fixture field, a static, a singleton or a real database left dirty by an earlier test. Reset state in SetUp, avoid statics, and give each test its own data. |
| How does parallel execution work? | Parallelism | Parallelizable with a scope (self, children, fixtures, all) opts tests in; NonParallelizable opts them out; LevelOfParallelism sets worker count. Tests in parallel must not share mutable state. |
| Should you use the Order attribute? | Design smell | It exists, but tests that need a specific order are usually coupled through state. Prefer independent tests and use Order only for rare cases you can justify. |
| What do Retry and Timeout do? | Reliability | Retry reruns a test that fails an assertion, up to a count. Timeout fails a test that runs too long. Retry can hide real flakiness, so track how often it triggers. |
| How do you run only smoke tests in CI? | Filtering | Tag them with a category and pass a filter to dotnet test. Keep fast unit tests in every build and slower suites on a schedule or before release. |
| Where does SetUpFixture fit? | Global setup | A class marked SetUpFixture runs its one-time setup before all fixtures in its namespace, or the whole assembly when placed outside any namespace. Useful for starting a test server or configuring logging once. |
Senior and scenario questions
| Scenario | What to suspect | What a strong answer covers |
|---|---|---|
| A Selenium suite on NUnit is flaky only when run in parallel. | Shared driver | One WebDriver held in a shared field. Create a driver per test or per thread, store it safely, close it in TearDown, and make test data unique per test. |
| CI shows failures that never happen on laptops. | Environment | Time zones and cultures, file paths, missing configuration, slower machines exposing race conditions, or test order. Log environment details through TestContext and reproduce with the same filter and settings. |
| The test suite takes 40 minutes. | Speed | Profile which fixtures are slow, move true integration tests to a separate stage, share expensive setup with OneTimeSetUp where it is safe, and enable parallel runs for isolated fixtures. |
| A team uses Retry on half the tests. | Hidden flakiness | Report retries as a metric, fix root causes (waits, data, shared state), and remove Retry where it masks bugs. |
| Tests assert on private methods through reflection. | Design | Test public behavior instead; if a private method needs its own tests, it may belong in a separate class. |
| Choosing between NUnit and xUnit for a new project. | Judgment | Both are capable. Consider the team's experience, existing suites, the instance-per-test model in xUnit versus shared fixtures in NUnit, and how each handles parameterized tests. Consistency across a codebase matters more than the choice. |
- How do you structure a test project for a large solution? Mirror the production namespaces, keep unit and integration tests in separate projects, and share builders for test data instead of copy-pasted setup.
- What makes a test readable? Arrange, act and assert are visible, the name says what is checked, and the failure message explains the problem without opening the code.
- How do you test time-dependent code? Inject a clock abstraction so tests set the time, instead of reading the system clock directly.
- How do you measure test quality beyond coverage? Whether tests fail when behavior breaks: mutation testing, review of assertions, and tracking escaped defects back to missing tests.
Fictional example
- Interviewer
- A fixture has a List field that two tests add to. Each passes alone; together, one fails on the count. Why?
- Candidate
- NUnit by default creates one fixture instance and reuses it for every test in that fixture, so the list keeps items from the first test. The fix is to create the list in a SetUp method so each test starts fresh, or to make it a local variable if only one test needs it. If the project's NUnit version supports it, I could also switch the fixture to one instance per test case, but I would rather fix the state handling explicitly so it is obvious to the next reader. Then I would check the other fixtures for the same pattern, because it tends to repeat.
NUnit practice plan
- Days 1 and 2: write tests for a small class with TestCase, TestCaseSource and exception checks, using only Assert.That.
- Day 3: add a dependency behind an interface and test it with a mocking library, then remove one over-specified verification and explain why.
- Day 4: create a shared-state bug on purpose and fix it with SetUp; then try running fixtures in parallel.
- Day 5: tag tests by category and run filtered subsets with dotnet test.
- Days 6 and 7: if the role involves UI automation, wire NUnit to a small Selenium or API test with per-test setup, screenshots attached through TestContext, and a short explanation of your framework structure.
Testing interviews reward candidates who explain why a test is written a certain way, not only what it does. Natively, an AI interview assistant for Mac and Windows, transcribes your mock coding rounds on your own computer, so you can review whether you explained the lifecycle or just typed attributes. In practice it can read a failing test or a class under test from a screenshot and suggest cases you missed, and with Pro or the free trial it can work from the résumé and job description you add. Transcripts and notes are there to look back on.
Questions people ask
What NUnit questions are asked in interviews?
TestFixture and Test, SetUp versus OneTimeSetUp, the shared fixture instance, TestCase and TestCaseSource, Assert.That constraints, exception and async tests, categories, Retry, and running tests in parallel.
Does NUnit create a new instance for each test?
Not by default. One fixture instance is shared by its tests, so reset state in SetUp. Later NUnit releases let you opt into one instance per test case, which is the default behavior in xUnit.
NUnit or xUnit: which should I mention in an interview?
Use whichever the job description names, and be ready to compare them: lifecycle model, setup style and parameterized tests. Consistency within a codebase matters more than the choice.
How is NUnit used with Selenium?
NUnit runs and organizes the tests while Selenium drives the browser. Interviewers check that each test gets its own driver and data, that cleanup runs in TearDown, and that parallel runs stay isolated.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
