Nikita Chursin, a team lead at Ozon Bank, explains how test-driven development helps teams work with uncertain requirements and maintain code quality. He covers four common misconceptions about TDD, demonstrates the red-green-refactor cycle with a bank account example, and explains how the approach can be used with legacy systems, acceptance tests, and LLM agents.
How TDD changes software development
The author’s first experience with TDD did not go well: he decided to write all the tests up front, then tried to make the implementation fit them. After two days, he had to abandon both the tests and the code. Later, Chursin realized he had confused development in small iterations with designing an entire system around a prewritten set of checks.
Over time, he began using tests in almost all his work and came to see TDD as a way to manage uncertainty: choose the next testable example, get feedback, improve the solution, and repeat the cycle.
The author identifies four myths about the approach: that it requires perfect requirements, always takes longer, calls for writing all tests in advance, and applies only to unit tests or simple functions. In his view, these misconceptions arise when tests are seen as a way to check finished code rather than as part of the development process.
Start by asking what to check
Requirements are often vague, so before implementation it is important to define observable behavior: what data goes in, what result is expected, and where the scenario’s boundaries lie. TDD turns these questions into concrete examples.
For example, an investment portfolio report should calculate the value of each holding and the total. An example with five shares at two dollars each checks multiplication. Adding holdings in different currencies immediately raises new questions: where should the exchange rate come from, and what point in time should it apply to?
A list of examples can reveal gaps before the team invests in implementation. It is not a complete system plan: the list evolves as work progresses, and newly discovered scenarios and unresolved questions can be added along the way.
The red-green-refactor cycle
TDD revolves around three phases. First, the developer writes a test that fails; then they make it pass with the smallest change possible; finally, they improve the code’s structure while preserving its behavior.
- Red. Write one test that fails for the expected reason—for example, because the required behavior does not yet exist. If the test does not compile, fix that issue and then check that it really detects the intended mismatch.
- Green. Make the smallest change needed to pass the test. There is no need to build a generalized solution right away: the next example may reveal what needs to be extended.
- Refactor. While the tests pass, remove duplication, clarify names, distribute responsibilities, and improve the design without changing behavior.
Then repeat the cycle. For a straightforward task, the steps can be larger; when uncertainty is high, it can help to narrow them down to a single API element or a small piece of behavior.
Why the test should fail first
A passing test does not, by itself, guarantee that the check is useful: it may not exercise the right part of the code or may lack a meaningful assertion. That is why the author recommends making sure the test has failed at least once because the behavior was missing or incorrect—not, for example, because of an import error.
Example: depositing money into a bank account
For an account with a zero opening balance, the first example describes a five-dollar deposit and expects the balance to be five dollars. At first, the test may not compile because the necessary types and methods do not exist. Once minimal definitions are in place, it fails because the behavior is unsupported; a simple implementation then makes it pass.
Next comes a second example: the account already has five dollars, and after another five-dollar deposit, the balance should be ten. A hard-coded value is no longer enough, so the example points toward adding the deposit amount to the current balance.
Once the tests pass, the design can be improved: consider where responsibility for monetary values should sit, how amounts are compared, and whether the names are clear. This approach does not guarantee a successful first architecture, but it lets you change it gradually and get feedback as you go.
- The interface takes shape around how the code will be used.
- The system remains runnable after each small cycle.
- Generalizations are introduced when new examples call for them.
- Refactoring has its own place in the process.
Myths about requirements and timelines
Myth 1: Requirements must be completely clear
In fact, working through examples can reveal ambiguities and hidden dependencies. Tests do not automatically fix poor requirements, but they can bring questions to light earlier—before a large amount of code has been written.
The scenario list remains a working guide: new business examples and edge cases, such as a null check, can be added, and completed items can be marked off. It helps keep attention on the next outcome without turning into a detailed blueprint for the entire implementation.
Myth 2: Testing always takes longer
It is not enough to compare TDD with development that has no checks at all: after the first version, there is still debugging, regression testing, and preparation for future changes. If automation is postponed until a large amount of code is complete, the architecture may be hard to test and feedback will be slow.
In the author’s experience, TDD is a little slower than writing code with no tests at all, but faster than building the entire implementation first and adding checks afterward. Time spent testing is made up through shorter debugging sessions, safer changes, and a lower risk of major rework. When tests are part of the definition of done from the start, they do not become unplanned work at the end of a task.
Myth 3: All tests must be written in advance
A list of examples is enough to get started, and it can change as the team understands the task better. The author recommends working through it with the red-green-refactor cycle, updating the list, keeping changes limited during the red and green phases, and setting aside time to improve the design.
If refactoring is skipped, tests may keep the system working even as its structure continues to deteriorate. The point of a minimal change is not to accumulate poor code, but to keep the iteration short; once the test passes, the developer should assess the design.
Myth 4: TDD is only suitable for unit tests
The cycle can be used at different levels, from a small piece of code to an integration, service contract, or acceptance scenario. In the platform team’s work described by the author, acceptance tests check the inputs, expected result, and boundaries of the team’s area of responsibility.
A broader end-to-end business scenario can remain with the testing team. This division helps the platform team focus on its own component and reduces the impact of failures in systems it does not own.
How developers and testers can work together
In a cross-functional team, a developer and tester can choose an example together, define the interface, and go through the full cycle until it is implemented. When they are in separate teams, they can agree on a public contract: the person writing the acceptance test describes behavior through available inputs and outputs without knowing how the code is built internally.
TDD also works with pair programming. One person writes a failing test, then the pair switches roles: the new driver—the person at the keyboard—gets it passing, refactors, and adds the next check. Switching roles frequently helps both people stay involved in the process.
Legacy systems, migrations, and the limits of the approach
With an older system, it may be necessary to create a safe point for checking behavior first. When migrating a library, you can use a golden master or approval test: provide known data, save the observed result, and compare subsequent runs against it.
It is then useful to separate business logic from the external dependency. If interaction with the library is isolated in a separate layer, that implementation can be replaced and the system’s core behavior checked to make sure it has not changed.
The author rarely uses TDD for a one-off prototype that is only needed for a demonstration and will be discarded. When exploring an unfamiliar technology, he experiments first to understand how it behaves, then applies the testing cycle to production code. If full checks run slowly, it is important to look for a faster feedback loop and reserve heavier tests for less frequent runs.
Coverage and test quality
With TDD practiced consistently, new production code is written in response to a failing test, so high coverage usually follows from the process. However, the percentage of lines covered does not show how useful the checks are: a test can execute code without confirming anything meaningful.
The author suggests paying attention to whether a test failed for the expected reason, whether it describes important behavior, and whether it catches an implementation change. It also matters whether the design can be changed safely and how quickly the test suite runs for the current cycle.
How to use TDD with LLM agents
Asking an LLM to implement a feature can result in a large amount of code appearing before the first check. The result may look complete, but an unusual scenario can expose behavior that was never tested. Asking the model to write tests for an implementation that is already in place is not always helpful either: the model may simply confirm the existing code.
Instead, the author suggests describing the expected behavior first and using tests as an executable specification for the agent:
- Ask it to create a plan in the form of test examples.
- Review the list and clarify what each scenario means.
- Set TDD as the working principle and let it proceed one failing test at a time.
- Review after every passing test, or less often depending on the level of trust.
You can split the work between two agents: one writes tests, while the other changes the production code. Their collaboration is then guided by the behavior described in the tests. With ATDD, the agent receives an acceptance scenario and repeats the internal steps until it passes; the author compares this process to what is known as the Ralph Loop.
TDD does not guarantee that an agent’s result is correct: a person is still responsible for the examples, architecture, and meaning of the checks. But instead of reviewing one large change, you can review a series of small steps.
TDD as a way to manage uncertainty
Tests help reveal sooner what is still unknown about a task and reduce the cost of mistakes. In Agile, feedback comes frequently; Scrum and XP organize it through iterations, CI provides it after a commit, and TDD provides it after a small code change.
The shorter the cycle between intention and verification, the less work can build up before a wrong direction is spotted. You can start with a few observable examples: choose the simplest one, see the test fail, make it pass, assess the design, and move on to the next scenario.
The approach does not replace engineering judgment, fix requirements on its own, or promise a perfect architecture. Its value depends on the quality of the examples and attention to refactoring; its main benefit is regular feedback and the ability to improve code safely.