Skip to content
Katabench
Try free

Topic

Testing & Refactoring

Techniques for changing C# safely, writing tests that catch real regressions, and measuring maintainability instead of debating it.

Practice this topic: C# refactoring exercises →

Try Flatten the Null Checks → Free, no account needed

Latest articles

RSS feed →

13 articles

Guard clauses in C#: flatten nesting, keep the behavior

Testing & Refactoring 8 min read

Guard clauses turn nested conditionals into a flat list of early exits. One refactor took nesting from 5 to 1 while cyclomatic complexity stayed at 6.

Read article →

Boundary value analysis: choosing tests at the edges

Testing & Refactoring 8 min read

Boundary value analysis picks test inputs on both sides of every partition edge. See it catch off-by-one mutants that full branch coverage lets through.

Read article →

TimeProvider testing in C#: stop waiting for the clock

Testing & Refactoring 8 min read

Make TimeProvider testing in C# deterministic. Check expiry and delays with FakeTimeProvider, distinguish elapsed time, and avoid asynchronous clock races.

Read article →

Property-based testing in C#: invariants that find bugs

Testing & Refactoring 8 min read

Use property-based testing in C# to check invariants with FsCheck, generate valid inputs, shrink failing cases, and turn discoveries into regression tests.

Read article →

Mocks vs stubs vs fakes: choosing a test double in C#

Testing & Refactoring 8 min read

Mocks vs stubs vs fakes in C#: what each test double can detect, why interaction-heavy mocks go red on every refactor, and when a hand-written fake wins.

Read article →

Integration testing in .NET with Testcontainers and WebApplicationFactory

Testing & Refactoring 8 min read

Integration testing in .NET with Testcontainers and WebApplicationFactory runs your API against real PostgreSQL, so constraints and query counts get tested.

Read article →

Mutation Testing in C# with Stryker.NET

Testing & Refactoring 8 min read

Mutation testing in C# plants controlled bugs and asks whether your tests notice. Learn Stryker.NET, triage survivors, and set useful CI gates.

Read article →

Code smells: a working catalog of six, with C# examples

Testing & Refactoring 8 min read

Code smells are symptoms, not verdicts. Six worth knowing, with C# examples: the tell for each, why it hurts, and the refactoring move that clears it.

Read article →

Cyclomatic complexity: what the number actually tells you

Testing & Refactoring 9 min read

Cyclomatic complexity counts the independent paths through a method. How to compute it by eye, what a score of 10 predicts, and how to reduce it for real.

Read article →

Unit testing best practices: test behavior, not implementation

Testing & Refactoring 8 min read

Unit testing best practices in C# with xUnit examples. Assert behavior instead of implementation, and remove what makes tests flaky so red means broken.

Read article →

Primitive obsession: the bug the compiler was begging to catch

Testing & Refactoring 7 min read

When everything is a string, a decimal, or a Guid, the type system cannot tell arguments apart. Value objects in modern C#, the bugs they delete, their limits.

Read article →

Refactoring legacy C# code safely: a test-first playbook

Testing & Refactoring 5 min read

How to refactor legacy C# without breaking it: write characterization tests first, then take small behavior-preserving steps like extract method and seams.

Read article →

Clean code is a vibe until you measure it

Testing & Refactoring 6 min read

Four code quality metrics you can automate in C#: cyclomatic complexity, nesting depth, method length, and duplication, with thresholds and a passing refactor.

Read article →

Get new katas 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.