Daniel
Menu
19

How AI Agents Write Tests — Not Just Code

October 2026 · Daniel Audu, Founder

The dirty secret of most AI coding tools is that they write code and stop. They generate a function, maybe a component, and hand it back. What they don't do is write the tests that tell you whether the code works. That gap is larger than it sounds.

Automated test output on a developer screen
Writing and running tests is the part of software engineering AI does consistently well. · Unsplash

A pull request without tests is not a complete pull request. It is a proposal with an unknown probability of correctness. In a professional codebase, a PR without adequate test coverage gets sent back. An AI that can write code but not tests is useful in the same way that a contractor who can frame a wall but not pass inspection is useful: partially.

Why testing is hard to automate well

Writing good tests requires understanding not just what code does, but what could go wrong. A test for an authentication function needs to cover the success case, the wrong-password case, the expired-token case, the user-not-found case, the rate-limit case, and edge cases like empty strings and SQL injection attempts. Writing those cases requires understanding the attack surface, not just the happy path.

This is why naive test generation — tools that take a function and generate tests by permuting its inputs mechanically — produces tests with high line coverage and low semantic value. They tell you the code runs. They don't tell you the code is correct under pressure.

How Daniel approaches test writing

Daniel reads the codebase before writing tests. It looks at existing test patterns, naming conventions, the test framework in use, and what kinds of cases existing tests cover. It reads the function being tested alongside its dependencies. It reasons about the inputs that are most likely to cause failures — boundary values, null inputs, malformed data, adversarial inputs for security-sensitive paths — and writes cases for those.

For security-sensitive code, Daniel adds adversarial cases. For database-touching code, it checks transaction handling and rollback behavior. For API endpoints, it tests both valid and invalid authentication, rate limiting behavior, and error response formats. The resulting test suite looks like work from a senior engineer who has read the codebase carefully and cares about what could break.

The run-read-revise loop

The other difference is that Daniel doesn't just write tests and stop. It runs them. If a test fails because the code is wrong, it fixes the code. If a test fails because the test itself has a wrong assumption about behavior, it revises the test. This loop — write, run, read output, revise — is what distinguishes an agent from a code generator.

In practice, this means every pull request Daniel opens includes a green CI run. Not "I wrote tests." Green tests. That distinction is what makes the output usable without an additional round of debugging. A human reviewer picking up a Daniel PR can focus on whether the code does the right thing, not whether it runs at all.

Characterization tests for existing code

One of the most valuable things an AI agent can do for a mature codebase is write characterization tests — tests that document what code currently does, rather than what it should do. These tests become the safety net for every subsequent change. If a refactor breaks something, a test fails. You know immediately and can fix it before merging.

Characterization test generation at scale — reading each untested function, inferring its behavior from its code and the surrounding test infrastructure, writing tests that lock in that behavior — is a process that would take months for a large codebase if done by hand. Done by an AI agent working in parallel, it can be completed in days. This coverage expansion is often the single most valuable thing Cognitive Daniel does in the first sprint with a new codebase.

Coverage as a byproduct, not a goal

Teams sometimes specify coverage targets: 80%, 90%, 100% of lines. These targets are useful signals but imperfect goals. 100% line coverage with tests that don't cover meaningful inputs is theater. Daniel's approach is to cover the behaviors that matter — edge cases, security paths, error states, integration boundaries — rather than optimize for a percentage. Coverage naturally goes up as a result of covering meaningful cases, but the goal is semantic correctness, not the metric.

When your existing codebase has gaps, Daniel can audit and fill them systematically. This coverage expansion creates the safety net that makes future changes less risky, which in turn makes the entire team faster. The investment in tests compounds over time in a way that raw feature output does not.

Code with test results in an IDE
· Unsplash

Further reading

Frequently asked questions

Does Cognitive Daniel write tests for the code it produces?

Yes. Daniel writes tests as part of every pull request, runs them, and only considers the task complete when the full test suite is green. It reads existing test patterns in your codebase to match your conventions and framework choices.

What kinds of tests does an AI agent write?

Daniel writes unit tests, integration tests, and edge case coverage including adversarial inputs, boundary values, null handling, and security-sensitive cases. For web applications, it also covers authentication edge cases, error states, and rate limiting behavior.

How does Daniel handle test failures?

Daniel runs the test suite after writing code. If tests fail, it reads the output, identifies whether the code or the test is wrong, fixes the appropriate one, and reruns. It iterates until green — not until it runs out of ideas.