Boundary and classification rules
10 exercisesChoose 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.
Free C# test-writing practice in the browser
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.
Green is the start, not the proof
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
The implementation is supplied. Your inputs and assertions are the solution.
Correct implementation
Every test must 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
A C# unit test example
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.
// 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
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.
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.
Partition strings into meaningful input classes, then target ordering, normalization, invalid data, encoding, and representation edge cases.
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.
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
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
Choose inputs that expose each mistake in the conversion formula.
Write this test suite: Test the Temperature Converter Read the brief: Test the Temperature ConverterCover values below, above, inside, and exactly on both boundaries.
Write this test suite: Test the Clamp Function Read the brief: Test the Clamp FunctionIsolate plain, Fizz, Buzz, and combined FizzBuzz branches.
Write this test suite: Test the FizzBuzz Rule Read the brief: Test the FizzBuzz RuleWrite 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 BucketsSeparate 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 RuleTest 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 BoundariesProve 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-ThreeCover case, punctuation, empty text, and asymmetric strings.
Write this test suite: Test the Palindrome Check Read the brief: Test the Palindrome CheckPin 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 WindowCover each shape, impossible sides, and degenerate boundaries.
Write this test suite: Test the Triangle Classifier Read the brief: Test the Triangle Classifier9 focused reps
Pin bracket type, nesting order, and every unbalanced case.
Write this test suite: Test the Bracket Matcher Read the brief: Test the Bracket MatcherCover wraparound, letter case, punctuation, and normalized shifts.
Write this test suite: Test the Caesar Cipher Read the brief: Test the Caesar CipherDistinguish every vowel, case, empty input, and tempting non-vowels.
Write this test suite: Test the Vowel Counter Read the brief: Test the Vowel CounterPin digit doubling, reduction, checksum validity, and rejected inputs.
Write this test suite: Test the Luhn Checksum Read the brief: Test the Luhn ChecksumExercise each symbol and all six subtractive combinations.
Write this test suite: Test the Roman Numeral Converter Read the brief: Test the Roman Numeral ConverterCover 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 EncoderDistinguish 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 CountingProve version segments compare numerically rather than lexically.
Write this test suite: Test the Version Comparer Read the brief: Test the Version ComparerPin 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 Parser8 focused reps
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 ScorerBuild 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 RulesWrite 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 ServiceProve each band is taxed marginally and every threshold is correct.
Write this test suite: Test the Progressive Tax Read the brief: Test the Progressive TaxIsolate each policy rule so dropping any one rule is detected.
Write this test suite: Test the Password Policy Read the brief: Test the Password PolicyPin operand order, chained operations, and invalid expressions.
Write this test suite: Test the RPN Calculator Read the brief: Test the RPN CalculatorProve every cent is allocated when a total divides unevenly.
Write this test suite: Test the Bill Splitter Read the brief: Test the Bill SplitterTrack both balances across applied, rejected, duplicate, and conflicting transfers.
Write this test suite: Test the Transfer Ledger Read the brief: Test the Transfer Ledger11 focused reps
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 MachineDrive 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 CacheExercise 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 OwnershipPin overlap, touching intervals, containment, and input sorting.
Write this test suite: Test the Interval Merger Read the brief: Test the Interval MergerBuild 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 CacheExercise 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 CalculatorCover 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 WorkflowUse 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 LimiterControl 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 ExecutorWrite 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 OrderingProve 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 ReservationsThe mutation-testing practice loop
1
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
Add public test methods with focused inputs and assertions. Every test must agree with the correct implementation before it can judge anything else.
3
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
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.
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.
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.
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.
No. The editor, compiler, correct subject, planted faulty versions, and result panel run from the browser in disposable server-side sandboxes.
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.
Start with FizzBuzz: four behavioral branches, five planted faulty versions, and immediate feedback on which bugs your tests caught.
Test FizzBuzz free