Skip to content

Testing in practice

Integration tests, unit tests and test strategies that keep large APIs safe to change — for humans and AI agents.

Quality
11 posts1 h 22 min reading time
Start with part 1 →
  1. One job only — a base class for API integration testsMost integration test base classes start as "host the API" and end as a 2,000-line junk drawer of test data helpers. A WebApplicationFactory-based base class that starts the API once, hands out clients and does nothing else.8 min read
  2. Test patterns for GET, POST and DELETEMost API test suites test the happy path of GET and call it a day. A repeatable checklist per HTTP verb, from the 401 to the "deleted means gone" check, plus the setup and cleanup rules that keep those tests independent of each other and of the system state.8 min read
  3. Test-first for APIs — start with the 401Test-first for APIs isn't about red-green ceremony. It forces you to be the first consumer of your own endpoint, to think about security before data, and to build the endpoints your tests need. A step-by-step walk-through with a minimal API.7 min read
  4. From Postman to C# and backA bug report arrives as a Postman request, a consuming team asks how to call your API, and your tests are written in object initializers nobody else can use. How to keep test data in the format that travels, turn every test call into a curl command, and turn real requests into tests.7 min read
  5. One test suite, many environmentsThe production pipeline that runs its tests against staging, the tenant-specific tests that are commented out before every commit, and three developers deleting each other's test data on QA. How to run the same integration tests against several environments without copying them.7 min read
  6. Testing as a specific user — without pasting tokens into codeA bug only happens for one kind of user, so someone pastes a bearer token into a test and swaps the header on the shared client. How to run API tests as specific users, in-process and against deployed environments, without leaking tokens or breaking unrelated tests.7 min read
  7. Unit tests that explain themselves — structure and namingA test called CalculateSomething with five asserts tells you one thing when it fails, and you have to run it five times to learn the rest. Naming conventions, test class structure and assertion habits that make a failing unit test explain itself.7 min read
  8. Snapshot testing for graph logicWhen deleting one entity cascades through a graph of relations, classic assertions miss exactly the bugs that hurt most — the relation that wasn't deleted and the neighbour that was. Why snapshotting the whole graph, plus a generated visual diff, works better.8 min read
  9. AI-friendly tests — failures built for humans and agentsA bare Assert.IsTrue failure was always a bad failure message. Now that AI agents read test output and try to fix what broke, it's an expensive one. How to design failures that say what broke, why, where and how to fix it, and why one diagnostic model should render for both humans and machines.8 min read
  10. Real dependencies in tests with TestcontainersThe in-memory database that happily accepts what PostgreSQL would reject, and the shared dev database that three test runs fight over. How Testcontainers gives every test run its own real database and cache, wired into a WebApplicationFactory, and what it costs.7 min read
  11. Integration tests for things that happen in the backgroundThe API answers 202 Accepted and the real work happens later in a background worker. Task.Delay makes those tests slow and flaky, test-only events pollute production code. Polling through the public API and listening to the telemetry the app already emits are the two patterns that work.8 min read