haechandev
AI & work

AI can write tests. It does not automatically design them.

A deployment test file grew beyond 10,000 lines despite careful development rules. That made me rethink how verification itself is designed.

August 17, 2026

When developing with AI, I pay attention to keeping files small, finding existing code first, and resolving ambiguities one at a time. I can usually keep feature code within those boundaries.

Revisiting a current project taught me something else: adding “write tests too” does not mean the tests will be designed alongside the feature.

AI diligently implements features and adds tests. Those tests often accumulate at the end of an existing large file. Regressions are prevented and CI passes, but after more changes and exceptions, the tests become a huge block with a very different structure from the feature code.

Tests can grow even when development rules are followed

One operations and deployment verification file in my current project, deploy-seed.test.mjs, had reached 10,686 lines at the time of writing.

It did not grow simply because the tests were careless. Deployment has many conditions that must hold: permissions, remote execution, environment checks, rollback, retries, and recovery. Every change naturally prompted another question: should we also cover this case?

Over time, the boundaries between those questions blurred:

  • Does this test check deployment policy or remote command formatting?
  • Does it verify recovery after failure or ensure nothing happens without permission?
  • Do scenarios need the same setup, or have unrelated scenarios ended up together?

Once a file exceeds eight or ten thousand lines, a failure first requires finding which situation broke. Interpreting the test takes longer than changing the feature. A safety net becomes a second legacy system that is hard to modify.

AI tracks test coverage more readily than test boundaries

Consider this request:

We changed the deployment policy. Update the existing tests and add missing cases.

AI will find tests, add conditions, and cover more failures. That is useful. But identifying the responsibility of each test, whether a smaller check would prove the same thing, and whether the shared setup will remain understandable are separate questions.

I now try to ask this before implementation:

List at most three contracts this change must preserve. Suggest whether each belongs in a unit test, an integration test, or a real workflow check, and explain why. If you need to extend a large test file, first describe its responsibility and possible boundaries to extract.

The point is to decide which failure to prevent, at which layer, and why.

Give tests responsibilities, just like product code

1. Write down what must never break

For risky changes such as deployment, write the contracts before test names.

  • Incorrect permissions must prevent remote execution and file changes from starting.
  • An intermediate failure must restore the previous state or clearly record that recovery is impossible.
  • A response that looks successful must not count as success without matching verification evidence.

These statements reduce ambiguous duplication and help place new exceptions.

2. Separate small rules from long scenarios

Input validation, state transitions, and permission decisions belong in small independent tests. Deployment flows, rollback, and remote command ordering need scenario tests where several steps work together.

Making everything an end-to-end test is slow and obscures failure causes. Using only unit tests can miss broken connections. The task is to choose the cheapest and clearest place to prove each fact.

3. Manage scenario setup separately

Setup often makes long tests harder than the assertions do. Slightly different environments, permissions, remote responses, and prior states hide which values matter.

I keep shared fixtures and builders together, without forcing semantically different scenarios to share setup. Builders such as “unauthorized request,” “recoverable intermediate failure,” and “interrupted remote response” should make their meaning clear from their names.

const request = unauthorizedDeployRequest();

const result = await startDeployment(request);

expect(result).toEqual({ status: "denied" });
expect(remoteCommand).not.toHaveBeenCalled();

This makes the contract visible. If large configuration objects and file-writing code dominate the body, the essential assertion is getting buried.

Include test design in the definition of done

I used to stop when the feature worked and the tests passed. Now I also include these questions in the task list.

## Deployment policy change

- [ ] Define the policy change and failure conditions in words
- [ ] Identify reusable contracts in existing verification
- [ ] Add the new rule at the smallest suitable test layer
- [ ] Add only the scenario needed for the real workflow
- [ ] Record responsibilities to extract from the large test file

I ask AI to handle the first unfinished item in this list. Before writing tests, it reads what existing verification means and helps decide where new cases belong.

This is still a work in progress

I have not completely solved the large test file. I am still reading operations and deployment verification, identifying the contracts it protects and scenarios that can be separated.

What is clear now is that requesting well-structured feature code is insufficient. Tests also need responsibilities, boundaries, fixtures, and failure conditions.

More important than the number of tests is whether the next person can immediately see what must never break. That is the standard I am working toward.