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 24 focused C# exercises and 134 planted bugs.

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

test-writing exercises
24
planted bugs
134
available free
24/24

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 or six deliberately faulty versions. Your suite must stay green on the first and turn enough of the others red. The feedback names every caught and surviving mutant without revealing its source.

New to the craft? Read the unit testing best-practices guide, 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

CAUGHT

boundary moved

CAUGHT

branch removed

CAUGHT

operator swapped

CAUGHT

case ignored

SURVIVED

edge survives

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.

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

8 exercises

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

Parsing, encoding, and validation

7 exercises

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

Calculators and business rules

5 exercises

Turn prose into an executable contract across thresholds, sequencing rules, rounding, error cases, and combinations of behavior.

Stateful and edge-heavy behavior

4 exercises

Design sequences where earlier calls change later outcomes. Timing, eviction order, sorting, and calendar rollovers make shallow tests survive.

24 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.

8 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 →
  2. Easy catch 4/5 bugs

    Test the Clamp Function

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

    Write this test suite →
  3. Easy catch 4/5 bugs

    Test the FizzBuzz Rule

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

    Write this test suite →
  4. Medium catch 4/5 bugs

    Test the Leap-Year Rule

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

    Write this test suite →
  5. 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 →
  6. Easy catch 4/5 bugs

    Test the Max-of-Three

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

    Write this test suite →
  7. Easy catch 4/5 bugs

    Test the Palindrome Check

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

    Write this test suite →
  8. Medium catch 5/6 bugs

    Test the Triangle Classifier

    Cover each shape, impossible sides, and degenerate boundaries.

    Write this test suite →

7 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 →
  2. Medium catch 5/6 bugs

    Test the Caesar Cipher

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

    Write this test suite →
  3. Easy catch 4/5 bugs

    Test the Vowel Counter

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

    Write this test suite →
  4. Hard catch 5/6 bugs

    Test the Luhn Checksum

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

    Write this test suite →
  5. Medium catch 4/5 bugs

    Test the Roman Numeral Converter

    Exercise each symbol and all six subtractive combinations.

    Write this test suite →
  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 →
  7. Hard catch 5/6 bugs

    Test the Version Comparer

    Prove version segments compare numerically rather than lexically.

    Write this test suite →

5 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 →
  2. Hard catch 5/6 bugs

    Test the Progressive Tax

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

    Write this test suite →
  3. Medium catch 4/5 bugs

    Test the Password Policy

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

    Write this test suite →
  4. Hard catch 5/6 bugs

    Test the RPN Calculator

    Pin operand order, chained operations, and invalid expressions.

    Write this test suite →
  5. Hard catch 5/6 bugs

    Test the Bill Splitter

    Prove every cent is allocated when a total divides unevenly.

    Write this test suite →

4 focused reps

Stateful and edge-heavy behavior

  1. Hard catch 5/6 bugs

    Test the Interval Merger

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

    Write this test suite →
  2. 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 →
  3. Hard catch 5/6 bugs

    Test the Next-Day Calculator

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

    Write this test suite →
  4. 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 →

The mutation-testing practice loop

Build a suite that earns its green checkmark

01

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.

02

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.

03

Hunt the planted bugs

Submit the suite against several hidden faulty implementations. The result names each mutant as caught or survived, so the missing edge case has somewhere to hide.

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.

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 24 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.

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

Get new puzzles and .NET tips in your inbox

A short note when fresh kata land, plus the C# and performance tricks behind the grading. No spam, unsubscribe anytime.