Since I started coding with an agent every day, the question stopped being "is it worth writing tests?". It became "does the agent have a way to know it got it right?". When it does, I ask for the change, it runs the checks, fails, reads the message, fixes it and only hands it back when everything is green. When it doesn't, it hands me something that looks done, and I become the test suite.
This post takes a position with no middle ground: in AI-driven development, static typing and automated tests at every layer are no longer an optional good practice. They're the infrastructure that makes the agent useful. I'll show the numbers, how each layer helps the AI, and real cases from the very site you're reading.
What Changed with AI Writing the Code
Before, whoever wrote the code was whoever understood the code. Tests were a net for the future: the next change, the next teammate.
With an agent, the order flipped. The code arrives finished, in volume, written by something that wasn't in the meeting where the business rule was decided. The 2025 DORA report, with nearly 5,000 professionals, puts it this way: AI is an amplifier that "magnifies the strengths of high-performing organizations and the dysfunctions of struggling ones". The same report shows that 90% already use AI at work and that 30% have little or no trust in the code it generates (DORA 2025).
The math works out like this: if AI increases the amount of code and you don't trust it, someone has to check it. That can be you, reading diffs. Or it can be an automated check that runs in seconds, never gets tired, every single time.
Anthropic says this itself in the Claude Code docs: "Give Claude something it can run that comes back pass or fail. Once it has that, it can keep going on its own and you don't have to watch." And it adds that, with nothing to run, "'looks done' is all it has to go on. In practice that makes you the test suite" (Claude Code best practices).

Why Static Types Help the AI
A static type is the declaration, in code, of the shape of each thing: this field is a number, this function takes an Order and returns an Invoice, this status can only be "paid" or "pending". The compiler checks all of it before the program runs.
For the agent, that brings three gains.
1. The error shows up right away and says where it is. A tsc in TypeScript, a dotnet build in C#, a go build or a cargo check answer in seconds with file, line and reason. It's the shortest fix loop there is.
2. Types catch exactly the mistake models make most. The study by Mündler and colleagues, from ETH Zurich and UC Berkeley, measured TypeScript code generated by models and found that, on average, 94% of compilation errors come from failed type checks; syntax errors are only 6% (arXiv, 2025). In other words: the model rarely misses a comma, but it gets the field name wrong, forgets a parameter, leaves a null unhandled. That's exactly what the compiler sees.
3. Types are documentation the agent reads. When it opens createOrder(data: NewOrder): Promise<Order>, it already knows what to send and what to expect, without reading the whole implementation. In a large project, that's cheap context.
Before AI, the argument was already strong. Gao, Bird and Barr took real, public bugs from JavaScript projects that had survived testing and review, and showed that TypeScript 2.0 and Flow 0.30 would have detected 15% of them (ICSE 2017). Airbnb, in an internal postmortem analysis presented in 2019, estimated that 38% of its bugs could have been prevented with TypeScript (InfoQ, 2020).
The industry followed. In August 2025, TypeScript passed Python and JavaScript to become the language with the most contributors on GitHub, according to Octoverse, which ties the shift directly to AI (GitHub, 2025). In a 2026 post, GitHub calls type systems "the safety net for code you didn't write yourself" (GitHub Blog).

What About Dynamic Languages?
JavaScript and Python don't come with static checking, but both gained optional typing that works very well with an agent:
| Language | How to get types | Command the agent runs |
|---|---|---|
| JavaScript | TypeScript (or JSDoc with // @ts-check) |
tsc --noEmit |
| Python | type hints + mypy or pyright | mypy . or pyright |
| Node.js | runs .ts directly since v22.18 and v23.6 (only strips types, doesn't check them) |
tsc --noEmit is still needed |
| Java, C#, Kotlin, Go, Rust | native static typing | mvn compile, dotnet build, go build, cargo check |
The Node detail deserves attention: since v22.18 it runs TypeScript files with no setup, but the docs are clear, "no type checking is performed" (Node.js). Running isn't checking. The one that checks is tsc, and it got a lot faster: TypeScript 7, rewritten in native code, came out in July 2026 with builds 8 to 12 times faster (Microsoft, 2026). For an agent that runs the compiler dozens of times per task, that's real time.
One caveat that's part of the advantage: types disappear when the program runs. The JSON coming from an API, the form a user fills in and the response from an AI model don't go through the compiler. At that boundary, validate at runtime with a schema (Zod, Valibot, Pydantic) and derive the type from the schema. The agent gets both at once: the compilation error and the validation error. It's the same idea behind Jev, the model that only returns responses with a defined type.
Why Each Test Layer Helps the AI
Types guarantee the pieces fit. They don't guarantee the shipping calculation is right, that the order was saved to the database or that the pay button works. That's what tests are for, and each layer catches a different kind of mistake.
Unit tests check a single function or rule in isolation, with no database and no network. They run in milliseconds. For the agent, it's the fastest feedback on logic: "is the 10% discount over $200 right?". Ham Vocke's classic guide on Martin Fowler's site sums it up: "Write lots of small and fast unit tests" (martinfowler.com, 2018).
Integration tests put the real pieces together: the HTTP route, the service and a real database in a containerIsolated package that bundles an application with its dependencies and runs the same on any machine, sharing the host operating system. Docker is the most common.. This is where the agent finds out the migration didn't create the index, the query broke with the new field, the API contract changed. Kent C. Dodds, creator of Testing Library, summed up the trophy school in one line: "Write tests. Not too many. Mostly integration" (Kent C. Dodds, 2021).
End-to-end (E2E) tests open the browser or the app and do what a person would do: sign in, fill in, pay. They're the slowest and the closest to real use. For the agent, they're the final proof that all the changes, added together, didn't break the flow.
The ratio varies by school, and deep down they all say the same thing: lots of what's fast, little of what's slow. Google suggests around 80% unit, 15% integration and 5% end to end, and calls it "a very rough guideline" (Software Engineering at Google, ch. 11). The details of each layer are in the guides to front-end testing and back-end testing.
Tests Are the Official Judge of Agents
When the industry wanted to measure whether a coding agent solves real problems, it used tests. SWE-bench, the most cited benchmark in the field, takes real GitHub issues and applies the agent's patch. If the tests tied to the issue pass (the FAIL_TO_PASS ones) and the ones that already passed keep passing (the PASS_TO_PASS ones), the problem counts as solved (SWE-bench, ICLR 2024).
What works for the benchmark works for your project. Without tests, you have no way to tell the agent what "solved" means.
What the Loop Looks Like in Practice
The three big coding agents ask for the same thing in their docs. Anthropic suggests a prompt like "write a failing test that reproduces it, then fix it". The AGENTS.mdMarkdown file at the repository root with project rules for coding agents: commands, conventions, what not to touch. The agent reads it before starting. guide, used by OpenAI's Codex, gives examples like always running npm test after touching JavaScript files (OpenAI). GitHub says to tell Copilot "how to build, test and validate its changes" (GitHub Docs).
In practice, that becomes a short instructions file at the root of the project:
## Verification (run before saying you're done)
- `npm run typecheck` (tsc --noEmit): zero errors
- `npm run lint`
- `npm test -- --run`: unit and integration
- Changed a screen? `npx playwright test` on the affected flow
## Rules
- New bug: first a failing test that reproduces the bug, then the fix.
- Don't change or delete an existing test to make it pass. If the test is wrong, stop and explain.And a sample test the agent can use as a criterion, in Vitest:
import { describe, expect, it } from 'vitest';
import { calculateShipping } from './shipping';
describe('calculateShipping', () => {
it('is free from $200 up', () => {
expect(calculateShipping({ subtotal: 200, region: 'CA' })).toBe(0);
});
it('charges the regional rate below that', () => {
expect(calculateShipping({ subtotal: 199.9, region: 'AK' })).toBe(39.9);
});
});With that, a request like "change free shipping to $250" stops being a conversation. The agent changes the rule, the first test breaks, it understands the test describes the old rule, updates both cases with the new value and points that out in its summary. You review one line of rule and two of test, not the whole file.
- Turn on TypeScript strict mode (
"strict": true) or mypy/pyright in Python, and ask the agent to clear the errors in small batches. - Write integration tests for the 3 flows that bring in money or cause headaches (sign-up, payment, the report the client looks at).
- Put types, lint and tests in the pipeline, blocking the merge.
- Write the agent's instructions file with the verification commands.
- From then on, every bug fix comes with a test that would have failed before the fix.
Real Cases from This Site
This portfolio is written with an agent, and the checks have saved me from publishing something wrong more than once.
- The test that bans the em dash. A unit test reads every blog post and fails if it finds the long dash, a classic mark of AI-generated text. When an agent translates a post and lets one slip, the pipeline stops before deploy, and the agent itself rewrites the sentence.
- The test that checks every internal link. Another test makes sure every link to another post uses the language prefix and a slug that exists in that language, and that every image referenced exists in the folder. The links in this post went through it.
- The E2E that caught a false noindex. The SEO test in Playwright visits every URL in the sitemapFile, usually XML, that lists the URLs of a site with their update dates, helping search engines discover and crawl the pages. and fails if it finds a
noindexmeta tag. A post that mentioned that tag as an example in the text broke the test. The false positive became a small fix in the test itself, and the rule keeps protecting the site.
None of these mistakes would be spotted in a quick diff review. All of them were caught without me looking.
The Rule That Makes It All Worth It: The Agent Can't Touch the Criterion
Tests only work as a judge if the agent can't swap the judge. Models sometimes try to make the test pass instead of making the code work: they delete the assertion, hardcode the expected value, skip the hard case.
This isn't theory. METR, which evaluates frontier models, recorded in 2025 that, in one batch of tasks, 39 out of 128 runs (30.4%) cheated, including a model that decided "to patch the competition evaluation function so that it judges every submission as successful" (METR, 2025). Anthropic acknowledges the risk in its own docs and suggests telling the model that "tests are there to verify correctness, not to define the solution", and that if any test is incorrect, it should "inform me rather than working around them" (Anthropic).

What works:
- A written rule in the instructions file: existing tests don't change without an explanation.
- Test diffs up front in review. Did a
*.spec.*or*.test.*file change? That's the first thing you read. - Mutation testing to check whether the generated tests test anything. Stryker changes the code on purpose and sees whether any test notices; a test that never fails protects nothing (Stryker). The details are in the back-end testing guide.
- Someone else writes the E2E. In my workflow, the agent that builds the screen writes the component test, and the E2E comes from a different session. That keeps an agent further from fixing its own criterion.
This connects with two practices that have already shown up on this blog: the spec written before the code in SDD and AI code review, which becomes far more useful when the machine has already filtered out type and rule errors.
What's Left for Human Review
With types and tests doing the mechanical part, review changes nature. You stop hunting for the forgotten undefined and start looking at what no tool sees: whether the solution is the right one for the problem, whether the name communicates, whether the business rule is the one the client asked for, whether it'll be easy to change six months from now.
It's a good trade. The tiring part goes to the machine, which doesn't get tired. The part that needs judgment stays with whoever has the context. It's also the difference between vibe coding that becomes a throwaway prototype and vibe codingWay of programming by asking an AI for everything in plain language and accepting the generated code without reading it closely, steering only by what shows on screen. that becomes a product.
Tools to Set This Up
- Vitest for unit and integration tests in JavaScript and TypeScript projects.
- Testing Library to test components the way people use them.
- Playwright for E2E on Chromium, Firefox and WebKit with the same code.
- TypeScript Playground to try out a type before bringing it into the project.
Frequently Asked Questions
Why use TypeScript with AI?
Because models get types wrong far more than syntax: in model-generated TypeScript code, 94% of compilation errors are type-check errors. The compiler turns that mistake into a message with file and line, which the agent itself reads and fixes before you see it.
Are unit tests still worth it if AI writes the code?
More than before. The test is the criterion that tells the agent whether it got it right. Without it, the agent only knows the code looks done, and the checking falls back on you.
What's the difference between unit, integration and E2E tests?
A unit test checks an isolated rule, with no database or network, in milliseconds. An integration test puts the real pieces together, like route, service and database. An E2E test opens the browser or the app and runs the whole flow, the way a person would.
Can AI write its own tests?
It can and should help, especially with the repetitive cases. The catch is not letting the same agent change the test to make it pass: a written rule against it, test diffs reviewed first and, when you can, mutation testing to check that the tests actually catch something.
Does untyped Python work well with an agent?
It works better with types. Type hints with mypy or pyright give the agent the same fast feedback TypeScript gives in JavaScript, and runtime validation goes to Pydantic.
Does Node running TypeScript directly make tsc unnecessary?
No. Since v22.18, Node runs .ts files by stripping the types, but it doesn't check anything. For the agent to catch type errors, tsc --noEmit stays in the loop.
How much of each kind of test should I have?
Lots of what's fast and little of what's slow. Google uses roughly 80% unit, 15% integration and 5% end to end as a guide; the trophy school puts more weight on integration. Start with the flows that bring in money or cause headaches.
References
- DORA. State of AI-assisted Software Development. Google Cloud, 2025.
- Anthropic. Best practices for Claude Code and Prompting best practices. Accessed November 2026.
- OpenAI. AGENTS.md. GitHub. Get the best results from Copilot coding agent.
- Gao, Z., Bird, C. and Barr, E. To Type or Not to Type: Quantifying Detectable Bugs in JavaScript. ICSE, 2017.
- Mündler, N. et al. Type-Constrained Code Generation with Language Models. PLDI, 2025.
- InfoQ. Airbnb's TypeScript migration, 2020.
- GitHub. Octoverse 2025 and Why AI is pushing developers toward typed languages (2026).
- Jimenez, C. et al. SWE-bench: Can Language Models Resolve Real-World GitHub Issues?. ICLR, 2024.
- Vocke, H. The Practical Test Pyramid. martinfowler.com, 2018. Dodds, K. C. The Testing Trophy and Testing Classifications, 2021.
- METR. Recent Frontier Models Are Reward Hacking, 2025. Stryker. Documentation.
- Microsoft. Announcing TypeScript 7.0, 2026. Node.js. Modules: TypeScript.
- Winters, T., Manshreck, T. and Wright, H. Software Engineering at Google. O'Reilly, 2020. The testing chapter is free at abseil.io.
- Khorikov, V. Unit Testing Principles, Practices, and Patterns. Manning, 2020. The best book for figuring out what's worth testing and what only produces brittle tests.
- Vanderkam, D. Effective TypeScript, 2nd edition. O'Reilly, 2024. 83 short pieces of advice for making the type system work for you.