← Home
.NETTestingReported by candidates

How do you unit test your .NET code? What do you test, and how is a test laid out?

Asked as "how would you test this?" and "your experience with unit testing" at Wipro (October 2026), TCS (August 2026), Codebase Solutions and Saviant.

Say this first · about 30 seconds
Make it yours · UDC payoff quote tests (invented example)
The code, simplified

Invented to show the shape, in C#. Tap Next to walk one row.

UDC.sln · where this file sits
  • Tests/
Diagram · step 1xUnit runs the test once per row. This row: 24 months left, 480 expected.
BreakFeeTests.cs · line 2 · 1 of 3One old quote: 24 months left, break fee 480.

Fix later in your repo The ten cases come from old quotes; a property-based test could try many more inputs.

Say it out loud, then check

Show the 30-second answer
  • A unit test checks one small piece of logic on its own, fast, with no database or network. I use xUnit.
  • Each test follows Arrange, Act, Assert: set up the inputs, call the one method, check the result.
  • I test business rules and their edges, like the last free day of a grace period, and I use an xUnit Theory, one test run over several input rows, instead of copying tests.
  • Anything outside the class, like the database, the clock or an HTTP API, I pass in as a parameter or through the constructor, so the test can hand it fixed values. Integration tests then check the real pieces together.
Check your answer: tick what you said

You said 0 of 7

Then add your example: UDC payoff quote tests (invented example)
  • Situation: at UDC Finance the early adds a break fee that depends on how many months are left. A refactor changed it, and nobody could say for sure the old answers still held.
  • What I did: before the refactor I wrote a [Theory] with ten real quotes from the old code as : months left in, fee out. Then I refactored until they all passed.
  • Result: the refactor shipped with no change in any quote, and the tests stayed as a safety net for the next change.
  • What I'd say: when I touch money logic I first write tests that record what the current code returns, then change the code until they still pass.

See it

1/6Before: the late-fee rule was checked by hand in a test environment, once per release.

In plain words

The senior answer · about 2 minutes
What I test
  • The business rules, because that's where bugs cost money: a late fee, a amount, an eligibility check. For each rule I test the normal case and the edges, like day 10 versus day 11 of a grace period, a minimum and a maximum.
  • I don't test what the framework already guarantees, like that a property returns what I set or that ASP.NET Core routes a request. Those tests break on every refactor and catch nothing.
How a test is written
  • Arrange, Act, Assert, with a blank line between them, and one behaviour per test. The name says the behaviour: No_fee_inside_grace_period, so a failure reads like a sentence in the build log.
  • When the same rule needs several inputs, an xUnit [Theory] with [InlineData] rows instead of five copied tests. xUnit builds a new test class for every test, so nothing leaks from one test into the next.
  • Anything I don't control, the database, an HTTP API, the clock, comes in from outside: through the constructor, which DI fills in the real app, or as a parameter. In the test I pass a fixed date or a fake repository. Since .NET 8 there's for the clock.
Where unit tests stop
  • Unit tests can't tell me the SQL is right or that the API is wired up. For that I write fewer, slower integration tests with and a real database in a container. Most tests are unit tests; a few are integration; a handful are end-to-end, driving the real Angular portal in a browser with Playwright.
  • In the pipeline every runs the tests, and a red test blocks the merge. A flaky test is a bug in the test or the code, so I find the cause rather than re-running until it's green.

All in one flow

Coming Not written yet: the card pass adds it.

The story

  1. Before

    BMW FS charges a late fee when an instalment is paid more than 10 days after its due date: 5% of the instalment, at least 25, at most 100. So day 10 is the last free day. For a long time the rule was checked by hand in the test environment before each release.

  2. Why it had to change

    A change to the grace period moved it by a day. The manual check tried a payment 20 days late, which was still right. Nobody tried day 10. Customers who paid on day 10 were charged a fee they didn't owe, and it was found from complaints.

  3. How it works now

    The rule now has unit tests. Each sets up its inputs, calls once and checks the answer: Arrange, Act, Assert. The date is an input, not the computer's clock, so the result is the same on every run. One test pins day 10 (no fee); a [Theory] runs day 11 with three amounts to hit the minimum, a normal fee and the maximum. The diagram walks one test.

  4. What happens next

    Every runs the tests in seconds, and a change that breaks day 10 fails the build before review.

  5. What we gained

    Edges are written down once and checked forever, the build log names the broken rule, and refactoring the calculator is safe. The try-first exercise shows the one thing that can still make a test lie.

In the lending API

One test per behaviour, laid out as Arrange, Act, Assert.

Only the key lines are shown; Deep walks the whole file.

Lending.sln · where this file sits
  • tests/Domain.Tests/
⋯ 2 lines in Deep⋯ 1 line in Deep⋯ 2 lines in Deep
LateFeeCalculatorTests.cs · line 8 · 1 of 4[Fact]: one test, one case.

The code, file by file

BMW FS late fees in the lending API: the rule, then its tests. Tap Next to walk the diagram with the code.

Lending.sln · where these 2 files sit
  • tests/Domain.Tests/
  • src/Domain/Fees/
Diagram · step 2Fees should start on day 11. A change started charging on day 10. Nobody checked day 10.
LateFeeCalculatorTests.cs · line 1 · 1 of 12Without tests like these, the day-10 bug in the diagram reached customers. xUnit finds every public method marked as a test in this class and runs it.

What they ask next

The follow-ups interviews really ask. Answer out loud, then tap to check.

Follow-up tree

Answer, then open the next level. That is the order an interviewer digs in.

Reporteda candidate was asked Intervieweran interviewer asks it

Production bugs, and how to tell them

Each one: what you see, why, the fix in code, and the line to say.

Production incident

Not on this card A basic concept card: its production story is the try-first flaky test and the day-10 fee bug in the story.

Traps

Traps

What should you say instead? Tap to check.

Live coding

Easy first, then harder. Set a timer and type it before you look.

Task 1

Question index: Musteasy · 15 minutes

Write xUnit tests for a late-fee rule: no fee up to 10 days late, then 5% of the instalment, at least 25 and at most 100. Cover the edges.

Question index (Must): write xUnit tests for a LoanService method, AAA and Theory
Stuck? Hints
  1. Which days matter most? Look at where the rule changes.
  2. How do you test 25, 40 and 100 without three copies of the same test?
  3. Where does today's date come from in your test?
Show a solution
Lending.sln · where this file sits
terminal · line 5 · 1 of 1The Fact and the three InlineData rows: four tests.
What the interviewer checks
  • Day 10 (no fee) and day 11 (fee) are both tested.
  • Minimum and maximum hit, plus one normal value.
  • [Theory] with [InlineData] for the amounts.
  • Fixed dates; nothing reads the real clock.
  • Arrange, Act, Assert, names that describe the behaviour.
  • Senior extra: says what an integration test would add.
With AI tools

AI assistants write unit tests quickly, and interviewers now ask how you check them. The common problems: tests that assert only , tests that check the mock returned what the test told it to return, and missing edges like day 10. I use Copilot to draft the test list and the boilerplate, then I add the boundary rows myself and make sure each test fails if I break the rule.

Glossary: every name, one line each →

My notes

Paste the NOTES block from your doubt chat here. The grader never reads notes; the coach reads "Still unclear".

Read moreWhere it was asked