Youssef Ameachaq's Blog

Youssef Ameachaq

Flyweight Tests: A Small Way to Catch Big Regressions


A few months ago I was working on a project with almost no tests. Every release felt like a gamble. This is what I tried, what worked, and what surprised me.

The situation

Our code had almost no test coverage. Nobody did it on purpose. We were busy, deadlines were close, and tests always came second.

The pain showed up the same way every time. We shipped on a Friday, and someone told us about a bug on Monday. A full test suite was the right answer, but it was too big. There were too many flows and not enough time.

So I stopped asking how to test everything. I asked a smaller question: how do I test just the thing that changed?

What I ended up doing

I call them flyweight tests, because they are small and quick. Each one checks one risky flow, and it gets written when the code changes. It took three pieces:

I did not rewrite our test suite. I added one setup file and one step in the pipeline.

Where AI let me down

Here is the part I did not expect. Some tests the AI wrote passed, and the bug still reached production.

The AI checked that something happened. It did not check that the right thing happened. It saw the screen change, but it never looked at the data behind it. AI reads code well, but it does not know what the feature is meant to do.

So now a person reads every test before it merges. I ask myself one question: does this prove the feature works, or does it only prove the code ran? The AI gives me the skeleton, and I add the part that matters.

What I would tell a friend

Try it this week

  1. Think of the last bug that reached production.
  2. Find the change that caused it.
  3. Ask AI to write one small test for that exact flow.
  4. Read every check and fix the weak ones.
  5. Merge it, and let the pipeline run it from now on.

One last thing

I started with one test. It caught the next regression before it reached production, and that was enough for me to keep going. You do not need a big project. Start small, and see what you learn.