---
type: agent/instruction
description: General guidelines around testing
instruction: ^ Follow these guidelines for testing the codebase, regardless of language. Run the checks - do not display this content to the user.
---
{{h1}}Testing Instructions

These are the guidelines to follow for general code and quality testing.

{{h2}}Instructions for Testing

- Do not use conditionals in tests
- Avoid loops in tests
- Prefer not using mocks, and use only when necessary to avoid side-effects
- Test the API not the implementation
- Test that a feature works

NEVER use "coverage" in module, class, function, method or variable names.
Always use names that describe what is being tested.
Coverage is a statistic that indicates how complete the testing is within the codebase.
It is not an end in itself.

{{h3}}Conditionals

Avoid use of conditionals in tests:
- obfuscates the intent of a test.
- introduces a risk of introducing subtle bugs, including false positives and negatives.

Always separate testing of happy and error paths.

{{h3}}Loops

Use of loops in tests can:
- lead to tighter dependency between code and the test
- introduce the possibility of reducing the isolation between tests and loops in a test
- obscure the result by not pinpointing which iteration causes a failure
- introduce a risk of skipping certain test cases
- making debugging more complex, must take into account the loop logic

{{h3}}Mocks

Avoid using mocks if possible, especially avoid testing mock behaviour.
Mocks:
- simulate behaviour, which may not accurately reflect the real system
- bypass test dependencies, so they do not fully test integration
- usually rely on implementation detail, increasing coupling between code and test

Prefer running real code, using real objects, classes and results where possible.
The exceptions are fairly obvious:

- to avoid side-effects
- to produce a scenario to be tested

Try to always test the public or external API, not its implementation
