Skip to content
Katabench
Try free

Free C# test-writing practice in the browser

C# unit testing exercises that test your tests

The implementation is already correct. You write the suite, then mutation-based grading checks whether it catches real mistakes across 38 focused C# exercises and 226 planted bugs.

All exercises are available on every plan. No SDK or test-project setup.

Katabench results after a real Submit on the Test the FizzBuzz Rule kata, of a suite with two tests that check 9 is Fizz and 15 is FizzBuzz. The verdict, Failed: mutation score, says the suite caught 3 / 5 planted bugs but needs 4, and that every test passes on the correct code. Under Mutants caught 3/5, Mutant #3 and Mutant #5 are marked survived and Mutants #1, #2 and #4 caught; each row shows only the mutant's number, not the bug.
A real Submit of two FizzBuzz tests: both pass on the correct code, and they catch 3 of 5 planted bugs.
test-writing exercises
38
planted bugs
226
test-writing exercises on the Free plan
38

Green is the start, not the proof

Find the inputs a buggy implementation fears

A passing test suite can still assert the wrong things, miss every boundary, or execute a branch without checking its outcome. Line coverage cannot tell those cases apart.

Each exercise supplies one correct subject and five to nine deliberately faulty versions. Your suite must stay green on the first and turn enough of the others red. The feedback marks each numbered mutant caught or survived, without saying what the bug was.

New to the craft? Read the unit testing best-practices guide and how to choose test cases at the boundaries, then use mutation grading to turn the advice into a repeatable judgment.

Your submission

Tests.cs

The implementation is supplied. Your inputs and assertions are the solution.

Correct implementation

Every test must pass

PASS

Five planted faulty versions

SURVIVED

Mutant #5

CAUGHT

Mutant #1

CAUGHT

Mutant #2

CAUGHT

Mutant #3

CAUGHT

Mutant #4

4 of 5 caught → grade passed

Green on correct code is necessary. Making planted bugs go red is the proof that the suite can detect regressions.

A C# unit test example

What a first test looks like, and what it has to catch

This is the starter for Test the FizzBuzz Rule. One test is written. The suite passes only when your tests stay green on the correct FizzBuzz and turn enough of the planted buggy versions red.

C#
// Write tests for the `FizzBuzz` class. Each public, parameterless method is one test; it passes
// if it doesn't throw. Make your suite pass on the correct code AND catch the hidden buggy versions.
// Think about every branch: plain numbers, multiples of 3, of 5, and of both.
public class Tests
{
    public void A_multiple_of_three_is_Fizz()
    {
        Assert.Equal("Fizz", new FizzBuzz().Convert(9));
    }

    // TODO: add tests for plain numbers, multiples of 5, and multiples of 15.
}

Read the full brief. When a subject depends on something you do not control, read about mocks, stubs, and fakes in C# and testing time with TimeProvider.

Four unit-testing skill families

Practice choosing cases, not memorizing framework syntax

The catalog moves from isolated decision boundaries to behavior that needs sequences, time, sorting, and state. Each family trains a different way shallow tests let defects survive.

Boundary and classification rules

10 exercises

Choose values on, just below, and just above a rule. These exercises build the habit that catches off-by-one defects, sign errors, and missing branches.

Parsing, encoding, and validation

9 exercises

Partition strings into meaningful input classes, then target ordering, normalization, invalid data, encoding, and representation edge cases.

Calculators and business rules

8 exercises

Turn prose into an executable contract across thresholds, sequencing rules, rounding, error cases, and combinations of behavior, including the calls a service makes to its collaborators.

Stateful and edge-heavy behavior

11 exercises

Design sequences where earlier calls change later outcomes. Timing and expiry, retries, eviction order, sorting, breaker trips, lease fencing, priority ties, refused state transitions, and calendar rollovers make shallow tests survive.

38 free C# unit testing exercises

Write every suite in the browser

Start with a single formula or classification boundary, then work toward caches, calendars, rate limits, and business rules. Every card opens the actual exercise.

10 focused reps

Boundary and classification rules

  1. Easy catch 4/5 bugs

    Test the Temperature Converter

    Choose inputs that expose each mistake in the conversion formula.

    Write this test suite: Test the Temperature Converter Read the brief: Test the Temperature Converter
  2. Easy catch 4/5 bugs

    Test the Clamp Function

    Cover values below, above, inside, and exactly on both boundaries.

    Write this test suite: Test the Clamp Function Read the brief: Test the Clamp Function
  3. Easy catch 4/5 bugs

    Test the FizzBuzz Rule

    Isolate plain, Fizz, Buzz, and combined FizzBuzz branches.

    Write this test suite: Test the FizzBuzz Rule Read the brief: Test the FizzBuzz Rule
  4. Easy catch 5/5 bugs

    Test Signed Time Buckets

    Write boundary tests for floor-based time buckets, where negative timestamps expose truncation bugs.

    Write this test suite: Test Signed Time Buckets Read the brief: Test Signed Time Buckets
  5. Medium catch 4/5 bugs

    Test the Leap-Year Rule

    Separate divisible-by-four, century, and four-hundred-year rules.

    Write this test suite: Test the Leap-Year Rule Read the brief: Test the Leap-Year Rule
  6. Easy catch 4/5 bugs

    Test the Grade Boundaries

    Test both sides of every cutoff to catch off-by-one defects.

    Write this test suite: Test the Grade Boundaries Read the brief: Test the Grade Boundaries
  7. Easy catch 4/5 bugs

    Test the Max-of-Three

    Prove each argument can win, including ties and negative values.

    Write this test suite: Test the Max-of-Three Read the brief: Test the Max-of-Three
  8. Easy catch 4/5 bugs

    Test the Palindrome Check

    Cover case, punctuation, empty text, and asymmetric strings.

    Write this test suite: Test the Palindrome Check Read the brief: Test the Palindrome Check
  9. Easy catch 6/6 bugs

    Test the Quiet-Hours Window

    Pin both edges of an overnight notification window and the day a held message goes out.

    Write this test suite: Test the Quiet-Hours Window Read the brief: Test the Quiet-Hours Window
  10. Medium catch 5/6 bugs

    Test the Triangle Classifier

    Cover each shape, impossible sides, and degenerate boundaries.

    Write this test suite: Test the Triangle Classifier Read the brief: Test the Triangle Classifier

9 focused reps

Parsing, encoding, and validation

  1. Medium catch 5/6 bugs

    Test the Bracket Matcher

    Pin bracket type, nesting order, and every unbalanced case.

    Write this test suite: Test the Bracket Matcher Read the brief: Test the Bracket Matcher
  2. Medium catch 5/6 bugs

    Test the Caesar Cipher

    Cover wraparound, letter case, punctuation, and normalized shifts.

    Write this test suite: Test the Caesar Cipher Read the brief: Test the Caesar Cipher
  3. Easy catch 4/5 bugs

    Test the Vowel Counter

    Distinguish every vowel, case, empty input, and tempting non-vowels.

    Write this test suite: Test the Vowel Counter Read the brief: Test the Vowel Counter
  4. Hard catch 5/6 bugs

    Test the Luhn Checksum

    Pin digit doubling, reduction, checksum validity, and rejected inputs.

    Write this test suite: Test the Luhn Checksum Read the brief: Test the Luhn Checksum
  5. Medium catch 4/5 bugs

    Test the Roman Numeral Converter

    Exercise each symbol and all six subtractive combinations.

    Write this test suite: Test the Roman Numeral Converter Read the brief: Test the Roman Numeral Converter
  6. Medium catch 5/6 bugs

    Test the Run-Length Encoder

    Cover run boundaries, multi-digit counts, singletons, and empty input.

    Write this test suite: Test the Run-Length Encoder Read the brief: Test the Run-Length Encoder
  7. Medium catch 6/6 bugs

    Test Unicode Scalar Counting

    Distinguish UTF-16 code units from Unicode scalars and reject unpaired surrogates at every position.

    Write this test suite: Test Unicode Scalar Counting Read the brief: Test Unicode Scalar Counting
  8. Hard catch 5/6 bugs

    Test the Version Comparer

    Prove version segments compare numerically rather than lexically.

    Write this test suite: Test the Version Comparer Read the brief: Test the Version Comparer
  9. Hard catch 5/6 bugs

    Test the CSV Record Parser

    Pin quoted commas, doubled quotes, empty fields, whitespace, and malformed records.

    Write this test suite: Test the CSV Record Parser Read the brief: Test the CSV Record Parser

8 focused reps

Calculators and business rules

  1. Hard catch 5/6 bugs

    Test the Bowling Scorer

    Exercise open frames, spares, strikes, and the final-frame bonus rolls.

    Write this test suite: Test the Bowling Scorer Read the brief: Test the Bowling Scorer
  2. Hard catch 9/9 bugs

    Test the Cart Discount Rules

    Build the carts where a wrong rule order or a wrong rounding step changes the total.

    Write this test suite: Test the Cart Discount Rules Read the brief: Test the Cart Discount Rules
  3. Medium catch 7/7 bugs

    Test the Checkout Service

    Write recording fakes that pin every charge, save, and receipt a checkout makes, in order.

    Write this test suite: Test the Checkout Service Read the brief: Test the Checkout Service
  4. Hard catch 5/6 bugs

    Test the Progressive Tax

    Prove each band is taxed marginally and every threshold is correct.

    Write this test suite: Test the Progressive Tax Read the brief: Test the Progressive Tax
  5. Medium catch 4/5 bugs

    Test the Password Policy

    Isolate each policy rule so dropping any one rule is detected.

    Write this test suite: Test the Password Policy Read the brief: Test the Password Policy
  6. Hard catch 5/6 bugs

    Test the RPN Calculator

    Pin operand order, chained operations, and invalid expressions.

    Write this test suite: Test the RPN Calculator Read the brief: Test the RPN Calculator
  7. Hard catch 5/6 bugs

    Test the Bill Splitter

    Prove every cent is allocated when a total divides unevenly.

    Write this test suite: Test the Bill Splitter Read the brief: Test the Bill Splitter
  8. Hard catch 5/6 bugs

    Test the Transfer Ledger

    Track both balances across applied, rejected, duplicate, and conflicting transfers.

    Write this test suite: Test the Transfer Ledger Read the brief: Test the Transfer Ledger

11 focused reps

Stateful and edge-heavy behavior

  1. Hard catch 7/7 bugs

    Test the Circuit Breaker State Machine

    Drive closed, open, and half-open transitions with a fake clock and prove rejected calls never execute.

    Write this test suite: Test the Circuit Breaker State Machine Read the brief: Test the Circuit Breaker State Machine
  2. Medium catch 6/6 bugs

    Test the Expiring Cache

    Drive a time-to-live cache with a TimeProvider you move by hand and pin every expiry edge.

    Write this test suite: Test the Expiring Cache Read the brief: Test the Expiring Cache
  3. Hard catch 7/7 bugs

    Test Fenced Lease Ownership

    Exercise expiry, renewal, ownership transfer, and stale-token rejection in a lease that must never reuse authority.

    Write this test suite: Test Fenced Lease Ownership Read the brief: Test Fenced Lease Ownership
  4. Hard catch 5/6 bugs

    Test the Interval Merger

    Pin overlap, touching intervals, containment, and input sorting.

    Write this test suite: Test the Interval Merger Read the brief: Test the Interval Merger
  5. Hard catch 5/6 bugs

    Test the LRU Cache

    Build call sequences that prove which entry is truly least recently used.

    Write this test suite: Test the LRU Cache Read the brief: Test the LRU Cache
  6. Hard catch 5/6 bugs

    Test the Next-Day Calculator

    Exercise ordinary days, month ends, year ends, and leap February.

    Write this test suite: Test the Next-Day Calculator Read the brief: Test the Next-Day Calculator
  7. Medium catch 8/8 bugs

    Test the Order Status Workflow

    Cover every state and call of an order workflow and prove each refused move changes nothing.

    Write this test suite: Test the Order Status Workflow Read the brief: Test the Order Status Workflow
  8. Hard catch 5/6 bugs

    Test the Sliding-Window Rate Limiter

    Use timed call sequences to prove the window slides and the limit holds.

    Write this test suite: Test the Sliding-Window Rate Limiter Read the brief: Test the Sliding-Window Rate Limiter
  9. Hard catch 5/6 bugs

    Test the Retry Executor

    Control failures and call counts to prove retries stop, exhaust, and filter exceptions.

    Write this test suite: Test the Retry Executor Read the brief: Test the Retry Executor
  10. Medium catch 6/6 bugs

    Test Stable Priority Ordering

    Write operation sequences that distinguish priority order, FIFO ties, peeking, and queue-instance isolation.

    Write this test suite: Test Stable Priority Ordering Read the brief: Test Stable Priority Ordering
  11. Hard catch 7/7 bugs

    Test the Stock Reservations

    Prove expiring stock holds never sell a unit twice or strand one on an expired hold.

    Write this test suite: Test the Stock Reservations Read the brief: Test the Stock Reservations

The mutation-testing practice loop

Build a suite that earns its green checkmark

1

Read the behavior

Inspect a correct C# implementation and its contract. Your task is not to rewrite the subject; it is to decide which examples would expose a wrong version.

2

Write the tests

Add public test methods with focused inputs and assertions. Every test must agree with the correct implementation before it can judge anything else.

3

Hunt the planted bugs

Submit the suite against several hidden faulty implementations. The result marks each numbered mutant caught or survived. It never says what the bug was, so you still have to find the missing case.

Katabench uses authored faulty implementations rather than mutating your code at runtime, but the principle is the same as mutation testing in .NET: a test proves its value when a meaningful defect makes it fail. For the technique on a real codebase, read mutation testing in C#.

C# unit testing exercise FAQ

Before you write the first assertion

What are C# unit testing exercises?

They are small C# programs where the implementation is already correct and your solution is the test suite. You choose inputs, write assertions, and cover boundaries, invalid data, state changes, and combinations of behavior that a shallow suite would miss.

How does mutation-based grading work?

Katabench runs your suite against the correct implementation first, where every test must pass. It then runs the same suite against several planted faulty versions, called mutants. You pass only after your tests fail against enough of those bugs, proving the assertions can detect regressions rather than merely execute code.

Are all 38 unit testing exercises free?

Yes. The complete Test Writing track is currently available on all plans. Daily graded-submission limits still depend on your plan, but none of these exercises is locked behind a specialized-track entitlement.

Are these xUnit, NUnit, or MSTest exercises?

Katabench uses a small built-in assertion API and treats each public parameterless method as a test, so the exercise stays focused on test design instead of package setup. The boundary analysis, assertions, exception checks, and naming habits transfer directly to xUnit, NUnit, and MSTest.

Do I need Visual Studio or the .NET SDK installed?

No. The editor, compiler, correct subject, planted faulty versions, and result panel run from the browser in disposable server-side sandboxes.

How are these different from ordinary C# coding challenges?

In an ordinary challenge you implement a function and supplied tests judge your code. Here the function is supplied and correct: you write the tests, then faulty implementations judge how strong those tests really are.

Want a different kind of practice? Browse all C# coding challenges across algorithms, data access, refactoring, architecture, security, and test writing, or see every unit testing kata in the catalog.

Write the suite that catches the bug

Start with FizzBuzz: four behavioral branches, five planted faulty versions, and immediate feedback on which bugs your tests caught.

Test FizzBuzz free