Automated tests
Beginner
12 min read
Code that checks your code: unit and integration tests, and what to test first.
Why it matters
Tests let you change code without fear. They catch a broken feature minutes after the change instead of days later from a user, and they are what CI runs on every pull request.
Where it fits
What you will learn
- Write a unit test with an arrange–act–assert structure.
- Tell unit, integration and end-to-end tests apart.
- Add a regression test when you fix a bug.
Before you start
- Git basics✓ Learned
A unit test
test_prices.py
from prices import total
def test_total_applies_discount():
# arrange
items = [100, 50]
# act
result = total(items, discount=0.1)
# assert
assert result == 135
Kinds of tests
- Unit — one function or class, fast, no network or database. Most of your tests.
- Integration — several parts together: code plus a real database or HTTP layer.
- End-to-end — the whole app through a browser. Valuable but slow; keep a few for the key journeys.
Tip: When you fix a bug, first write a test that fails because of it. The fix makes it pass, and the bug cannot quietly come back.
Linters and static analysis are checks too: they catch unused variables, type errors and risky patterns without running the code. Run them alongside the tests.
Official documentation and references
Documentation
- pytest documentation ↗ Official · pytest
- Jest — Getting started ↗ Official · Jest
- PHPUnit documentation ↗ Official · PHPUnit
Guides
- The Practical Test Pyramid ↗ martinfowler.com — A widely read article on how many tests of each kind to write.
Practise in Zerethon IDE
- Algorithm sample: Binary Search · read the code, then use Open in IDE on its page Includes a test file: open it in the IDE and set the test file as the entry to run the checks.
Learn next
- CI/CD pipelines ›✓ Learned
Related topics
- Linters and static analysis✓ Learned
- CI/CD pipelines✓ Learned
- Branches and pull requests✓ Learned
Done with this topic?
Reviewed 2026-10-23. Links go to the official documentation unless marked otherwise.