Your Cart
Loading

Why a Green Test Suite Can Be the Most Dangerous State of Your Codebase

On one project, I set up contract tests between services that published Kafka events and exposed REST endpoints. The thing that convinced the team we needed them wasn’t a red build. It was a green one.

Most integration tests run against mocks. A mock is a snapshot of what someone believed another service did, on the day they wrote it. Services keep changing after that day. Mocks usually don’t.

How mocks go stale

Here’s a typical way it happens. The orders service calls the customer service and expects a response like this:


{ "id": "c-102", "email": "ana@example.com", "phone": "+57 300 000 0000" }


Someone writes a mock with exactly that shape, the tests pass, and everyone moves on.

Three months later, the customer team makes phone optional because new sign-ups no longer require it. They update their own tests, and those pass. Our mock still returns a phone number every time, so our tests pass too.

Then the first customer without a phone number reaches checkout, and code that assumed the field would always be there throws a null error in production.

Nobody did anything wrong in isolation. Both teams had green suites. The bug lived between them, in an assumption that was never written down.

That’s why stale mocks are so dangerous. A red test tells you something is broken. A green test built on an outdated mock tells you everything is fine, and you believe it.

The contract should be the source of truth

The fix is to stop treating the mock as the truth and treat the contract as the truth instead. A contract states what the provider promises and what the consumer needs. Each side tests against it independently, so when the provider changes something a consumer depends on, a test fails on the provider side before the change ships.

Tools like Pact help, but tooling was never the hard part. Contracts are tedious to write, and if nobody maintains them they drift just like mocks do.

Where AI actually helps

In the middle of the testing pyramid, I’ve found AI more useful for reading both sides of a boundary than for writing new tests. These are the four things I’d ask a model to do:

  1. Compare the mock to reality. Give it the mock and the current API schema, or a recent real response, and ask which fields differ in name, type, or whether they’re optional.
  2. List the unwritten assumptions. Give it the consumer code and ask what it assumes about the response that the provider never guarantees: missing fields, empty lists, ordering, nulls.
  3. Review provider changes from the consumer’s side. When a pull request changes a response, ask which consumers could break and how.
  4. Ask the uncomfortable questions. What if this list comes back empty? What if this ID is missing? The answers usually point to tests nobody wrote.

A prompt like this works well for the second one:


Here is a client function that consumes the /customers/{id} endpoint, and here is the OpenAPI spec for that endpoint. List every assumption the client makes about the response that the spec does not guarantee. For each one, describe the failure it would cause in production.


The answer won’t always be right. Sometimes it flags things that don’t matter, and sometimes it misses context only your team has. But it gives you a list of candidates fast, and reviewing a list is much easier than imagining every edge case from scratch.


What I’d do on Monday

If your integration suite leans heavily on mocks, start small:

  • Pick the three integrations that would hurt the most if they broke.
  • Compare each mock against a real, recent response. You’ll probably find at least one difference.
  • Capture that difference as a contract or a test, not as a comment.
  • Ask a model to list the assumptions in the consumer code, and turn the real ones into tests.

None of this needs a new framework. It mostly takes the habit of asking whether your mocks still describe reality.

In my experience, most production failures don’t happen inside a component. They happen between components, in agreements nobody wrote down.


This article is adapted from one of the ideas in my short field guide, AI Across the Testing Pyramid*, which walks through what AI really changes at each level of the testing pyramid. Chapter 2 is free to preview at payhip.com/SantiagoRodriguez.*