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

  1. Plan & Design
  2. Develop
  3. Version control
  4. ● Verify
  5. Build & Package
  6. CI/CD
  7. Deploy
  8. Operate

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

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

Guides

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

Done with this topic?

Reviewed 2026-10-23. Links go to the official documentation unless marked otherwise.