# Test harness

> Test Harness: What It Is and What It Contains. Canonical page: <https://zapple.tech/glossary/test-harness/>

A test harness is everything around the code under test that lets you run it and judge the result: the driver that calls it, stand-ins for its dependencies, the test data, the runner and the reporting. You pay for one whenever tests need more than the product itself. An AI agent needs one that also contains its side effects.

## What does a test harness contain?

In everyday use, a harness answers the same questions. This is the working definition from practice, not a quote from a standard. How do you call the code? What stands in for the things it depends on? Where does the data come from? Who runs the cases and writes the report?

| Part | What it does in an ordinary suite | What it becomes around an AI agent |
|:--|:--|:--|
| Driver | Calls the code under test, such as a function, an API or a browser | Sends a task to the agent and collects its answer |
| Stub or fake | Replaces a slow or unavailable dependency | A sandboxed copy of each tool the agent may call |
| Fixture and test data | Sets up the state a test starts from | The task set, plus the files and accounts the agent starts with |
| Runner | Executes cases and isolates them | Executes tasks, often several times each |
| Assertion | Decides pass or fail from a known answer | A scorer: a rule, a check on the end state or a judge model |
| Reporting | Shows what failed and why | A trace of every step the agent took |

The word is used for two things. Some teams mean a runnable setup for one product. Others mean a library, such as testharness.js, which the [web-platform-tests documentation](https://web-platform-tests.org/writing-tests/testharness.html) describes as the framework its JavaScript tests are written in. Harness, the CI/CD company, is a third meaning and has nothing to do with either.

## Do you need to build a harness, or does your framework already give you one?

Usually your framework gives you most of it. The [Playwright documentation](https://playwright.dev/docs/test-fixtures) says fixtures "are used to establish the environment for each test, giving the test everything it needs and nothing else." The [pytest documentation](https://docs.pytest.org/en/stable/explanation/fixtures.html) says fixtures define "the steps and data that constitute the arrange phase of a test." On the Java side, the [JUnit User Guide](https://docs.junit.org/6.1.3/overview.html) describes the JUnit Platform as "a foundation for launching testing frameworks on the JVM." So the runner, setup and isolation come ready-made.

Build something extra only when the product needs it. That is a judgement call, and it usually comes down to three cases:

- A dependency is paid per call, slow or not built yet, so you need a fake.
- Tests need data that no framework creates, such as accounts in a state that takes days to reach.
- Several teams run the same checks and each has copied the setup.

If none of these applies, adding a harness layer is cost without a return. Ask your lead which of the three they have, and ask who maintains the answer. For the framework side of this decision, see our comparison of [unit test tools](/blog/types-of-automation-testing/list-of-the-best-unit-automation-testing-tools/). If the harness has to run in CI, see our guide to building a [QA automation pipeline](/blog/types-of-automation-testing/guide-to-creating-qa-automation-pipeline/).

## What does a harness for an AI agent need that an ordinary one does not?

An agent acts. It calls tools, changes files and sends messages. A harness that lets it do that on live systems is a risk, so the first need is containment: each tool runs against a sandbox or a fake, and nothing leaves it. [Inspect](https://inspect.aisi.org.uk/), an evaluation framework from the UK AI Security Institute and Meridian Labs, lists "a sandboxing system that supports running untrusted model code in Docker, Kubernetes, Modal, Proxmox, Vagrant, and other systems" among its core features.

The second need is repeat runs. The same task can succeed on one run and fail on the next, so one pass proves little. The third is a trace of every step, because a wrong final answer is hard to fix without seeing the path to it. Inspect describes its building blocks as "datasets, agents, tools, and scorers", which maps onto the table above.

Our guides to [testing AI agents](/blog/types-of-automation-testing/how-to-test-ai-agents/) and [testing an MCP server](/blog/types-of-automation-testing/how-to-test-mcp-server/) go through the cases, and Zapple.Tech builds harnesses as part of the [AI agent testing](/services/ai-agent-testing/) work.

## What does a harness not solve?

A harness runs and records. It does not decide what a correct result is. That comes from your success criteria and a labelled set of examples, and someone has to write and keep them. A harness with weak scorers produces tidy reports about the wrong things. It also does not cover what the sandbox leaves out: a fake that drifts from the real service passes tests the real one would fail.

## What does Zapple.Tech do about it?

If you are not sure whether your tests need a harness of their own, start with the evidence. Zapple.Tech starts with a one-week QA audit of one product area. It looks at its tests, pipeline and release process, and ends in a written report on what is at risk and what to fix first, plus a pilot plan you can run with Zapple.Tech or without it. Read more on the [QA audit and assessment](/services/audit-and-assessment/) page.

Tell us about your setup in the form below.

## FAQ

### What is a test harness?

A test harness is the set of tools and code around the software under test that runs it and records the outcome. It usually holds a driver that calls the code, stubs or fakes for its dependencies, test data, a runner and a report. It runs the tests. It does not decide what a correct result is.

### What is the difference between a test harness and a test framework?

A framework gives you the rules for writing and running tests, such as fixtures, assertions and discovery. A harness is the working setup for one product, built on a framework plus your own drivers, fakes, data and environment. Many teams never build a harness separately, because the framework and their fixtures already do the job.

### What are the components of a test harness?

The usual parts are a driver that calls the code under test, stubs or fakes for what it depends on, fixtures and test data, a runner that executes the cases, assertions that decide pass or fail, and reporting. For an AI agent, add a sandbox for its tools and a record of each run.

### What is an evaluation harness for AI agents?

It is the setup that runs an agent against a set of tasks and scores the results. It supplies the tasks, the tools the agent may call in a sandbox, repeat runs and a record of each step. Open-source tools such as Inspect package datasets, sandboxed tools, scorers and run logs. The scoring rules still come from your own success criteria.

## Sources

- [Playwright documentation, Fixtures (current docs)](https://playwright.dev/docs/test-fixtures)
- [pytest documentation, About fixtures (current docs)](https://docs.pytest.org/en/stable/explanation/fixtures.html)
- [web-platform-tests documentation, JavaScript tests (testharness.js)](https://web-platform-tests.org/writing-tests/testharness.html)
- [JUnit User Guide, Overview (6.1.3)](https://docs.junit.org/6.1.3/overview.html)
- [Inspect, UK AI Security Institute and Meridian Labs (current docs)](https://inspect.aisi.org.uk/)
