Search articles

TestForge: AI-Written Tests That Stop When They Can't Read the Results

TestForge is an Agent Skill for Claude Code and Cursor. It plans, writes and runs tests, and stops when it can't read the results.

Case studies

by Leonidas Michalopoulos 7 min read

TestForge Agent Skill for Claude Code and Cursor — cover

When you ask an AI model to write tests for a project, you usually get something that looks like a correct result. Files inside tests/, names that read well, and a closing paragraph saying coverage went up. None of that proves the tests are right. The model may edit the application code to make a test pass. It may run commands against a database that isn't a test database. And if the log is empty or confusing, it may fill in the numbers itself.

That is what I wanted to avoid. Not with a bigger prompt, which gets lost in the next conversation, but with a skill: a folder of instructions and scripts that Claude Code and Cursor can load.

What TestForge is

TestForge is an Agent Skill. The folder goes into the skills directory of Claude Code or Cursor, and from there a conversation can invoke it. It is not a test runner and it doesn't replace pytest, Jest or Maven. It uses them.

The work is split into three modes.

In plan mode it reads the code and writes a plan, TESTFORGE_PLAN.md. It creates no tests and runs none. This is the right mode when the environment isn't known to be safe, or when you want to see what it would cover first.

In generate mode it writes tests into directories that already belong to tests, such as tests/, __tests__/ and spec/, or the temporary .testforge/ folder. It doesn't execute them.

In audit mode, the default, it runs the full cycle. It detects the language and framework, plans, writes, runs, classifies failures, and leaves two reports: a Markdown one for people and a JSON one for anything that wants to read them programmatically.

Today it recognises Python, JavaScript or TypeScript, and Java. For Python it distinguishes pytest and unittest. For JavaScript it looks for Jest, Vitest and Playwright. For Java it reads pom.xml, build.gradle or build.gradle.kts and reports JUnit 5, JUnit 4 or TestNG depending on the dependencies. If it finds none of them, it writes java-unknown with a note and doesn't guess. When a wrapper exists, it prefers ./mvnw or ./gradlew.

Why a skill and not one big prompt

Skills load instructions in stages. The model first sees a short name and description, enough to decide whether the skill is relevant to the conversation. If it invokes the skill, it reads SKILL.md, which holds the flow and the rules. It opens the details only at the step that needs them: the test pyramid, Arrange-Act-Assert, Playwright locators, failure classification. That is what the files in references/ are for.

The parts that must stay stable I don't leave to the model's judgement. Four small Python scripts, standard library only, do that work.

The first looks at the project's files, package.json, pyproject.toml, pom.xml, and suggests a command. The second runs a check before anything is executed. The third reads JUnit XML, or the text produced by pytest, unittest, Jest, Vitest, Playwright, Maven and Gradle. The fourth writes testforge-results.json.

If the log doesn't look like any of these, the parser stops with an error. It doesn't write a report with zero tests and a green result. An empty success is worse than a failed read, because it looks like a measurement.

Judgement stays with the model: which paths deserve a test, what is a defect in the code and what is a brittle test, how to fix a broken import. For a syntax or import error it may retry up to twice, using notes I keep in references/test-validation.md. There is no script that repairs tests on its own.

What it leaves behind

At the end of an audit there are two files: TESTFORGE_REPORT.md, which a person reads, and testforge-results.json, which is checked against a schema and can be read by another tool or a CI pipeline. The first says what was planned, what was written, what ran and how the failures were classified. The second keeps the numbers in a form you don't have to guess at.

The report doesn't prove the tests are good. It proves what ran and what was read. That difference is the whole point.

What I mean by safe

Before an audit, a small check runs. It looks at whether the folder is writable. It looks at environment variable names that resemble an environment, stage or database, and whether the value looks like production. In its output it prints only the variable's name. If it finds something like that, it recommends plan mode and execution stops.

The check is heuristic. The network stays open. Commands run inside the project. A database isn't proven disposable just because the script didn't see the word production. The .testforge/ folder holds logs and intermediate JSON. It is not an isolated environment.

The rule "don't touch the application's source code" started as an instruction to the model, and that wasn't enough. Now a Claude Code hook enforces it: hooks/enforce_write_boundary.py. It runs before every Write, Edit, MultiEdit and NotebookEdit and rejects any write that falls outside tests/, test/, __tests__/, spec/, src/test/, .testforge/, files with test names (such as foo.test.ts or FooTest.java) and the report files. Before judging the path, it resolves .. and symlinks, so a tests/../src/app.py doesn't get through.

Here is the limit. Bash is checked only approximately. The hook recognises redirections, tee, sed -i, rm, mv and cp, but a shell can write files in ways a regex doesn't see. It is not a lock on the file system. The hook is declared in the frontmatter of SKILL.md and is active only while the skill is running. If your version of Claude Code doesn't honour hooks inside skills, you copy it into settings.json. The hook is written for Claude Code.

The tests it produces still need a human read before they are committed. A skill that promises a guarantee it can't enforce becomes dangerous the day someone trusts it, which is why I state explicitly where the protection is reliable (Write and Edit) and where it isn't (Bash).

How to try it

It needs Python 3.10 or newer. The scripts have no dependencies. For JavaScript and Java you need the runner the project already has.

In Claude Code the folder goes in ~/.claude/skills/testforge for all projects, or inside the project at .claude/skills/testforge. In Cursor the location is ~/.cursor/skills/testforge or .cursor/skills/testforge. After a restart, one sentence is enough:

"Run a TestForge test audit on this project."

For a plan only: "Use TestForge in plan mode."

For files without execution: "Use TestForge in generate mode and don't run the tests."

If it's your first time, start with plan mode on a small project. You'll see what it would do before you let it run anything.

The code is on GitHub under the MIT licence: github.com/leonidasmich/testforge.

What it doesn't do

It doesn't cover every language. evals/evals.json describes two behaviour scenarios. Nothing inside the repo executes them. The repo has unit tests for the hook and for the framework detector, but those are not the evals. And it doesn't replace someone who knows which bug deserves a test.

It sets an order, keeps the measurable steps in scripts, and leaves a written trace of what ran. I built it because I was tired of test reports I couldn't verify. If you use it, read the tests it wrote. The report is the trace. The judgement stays yours.

  • testforge
  • agent-skill
  • claude-code
  • cursor
  • testing
  • ai
  • case-study