Skip to content
Heads up: this guide was last verified on Oct 8, 2026. Free-tier limits change often — re-check the provider's current pricing page before relying on it. Report an outdated limit.
Everyday AI, Done Right
Learning

Write Unit Tests for a Small Script with Aider

Learn testing by having an open-source coding agent draft tests for your script, then reading every one to understand what it checks.

ToolAider (open-source coding agent, Apache-2.0)
Cost$0 — open-source licence (Apache-2.0)
LimitsYour hardware is the limit when run with a local model
Verified8 October 2026

Why this works

Testing is easiest to learn from examples. Aider can draft tests for a small Python script; your job is to read them, run them, and make them fail on purpose once to prove they work.

Step by step

  1. Start with a tiny scriptPick a script under 100 lines, such as a unit converter or a budget calculator, and commit it.
  2. Ask for testsUse the prompt below in Aider with the script added to the chat.
  3. Run the testsRun pytest (install it first). Read the output even when everything passes.
  4. Break the code on purposeChange one line of the script to produce a wrong answer and confirm a test fails.
  5. Explain each test to yourselfFor each test, write one sentence saying what behaviour it protects.

Copy-paste prompt

Write pytest unit tests for the functions in this file. Cover normal inputs, edge cases such as zero and negative values, and one error case. Do not change the script. Keep each test short with a descriptive name.

SCRIPT:
<paste>

Check your result

  • Tests run and pass on the correct code
  • At least one test fails when you break the code on purpose
  • You can explain each test

Pitfalls to avoid

  • A passing test is not proof of correct behaviour if the test asserts the wrong thing.
  • Do not accept generated tests that only call the function without checking the result.

What we checked: Licence and project status were read from the project's GitHub repository on 8 Oct 2026. Install commands and flags change between releases, so follow the project README for the current version. Source: https://github.com/Aider-AI/aider.