---
title: "Unit Tests: Deciding What Is Worth Testing"
description: "Writing small automated checks that call a function with chosen inputs and compare its behaviour with a specified contract. Choose ordinary cases, relevant boundaries and specified errors; empty input"
canonical: https://lightmysky.com/learn/computing/unit-tests-deciding-what-is-worth-testing-mt_tuIQecq5Le
source: https://lightmysky.com/learn/computing/unit-tests-deciding-what-is-worth-testing-mt_tuIQecq5Le.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Unit Tests: Deciding What Is Worth Testing

Writing small automated checks that call a function with chosen inputs and compare its behaviour with a specified contract. Choose ordinary cases, relevant boundaries and specified errors; empty input matters when the contract makes it relevant.

Subject: Computing · Area: Programming · Ages 17 to 18
Page: https://lightmysky.com/learn/computing/unit-tests-deciding-what-is-worth-testing-mt_tuIQecq5Le

## Ready when they can

- Write tests for one function covering a normal case, a boundary and an error case
- Change the function so a test fails, and read what the failure tells you
- Explain how copying implementation logic into an expected result can hide a shared mistake

## Lesson: Tests that check a promise

A unit test automatically checks a specified behaviour. Assume split_bill(total, people) accepts a nonnegative total and a positive integer people, returns total / people, and raises ValueError otherwise. Plan ordinary cases, relevant boundaries and specified errors for this contract, not a fixed test quota.
```python
assert split_bill(16, 4) == 4
```
The assertion fails if this call's result is not 4.

A boundary depends on the allowed domain. For a function accepting integers from 1 through 6, the endpoints 1 and 6 are boundaries; 3 is an interior value. Empty input and zero matter only when the function's contract makes them relevant. State the expected behaviour before choosing a test.

*(drawing: A useful failure identifies the call, its expected result and what actually happened.)*

Check a test by changing the specific behaviour it should detect. If division is replaced by multiplication, a test of split_bill(12, 3) expecting 4 should reject the new result 36. An unrelated change may leave this test passing. A surviving relevant change suggests inspecting the call, expected value and assertion.

An expected result should come from the contract or an independent calculation. If the test repeats the implementation's calculation, both may share the same mistake and agree on an incorrect answer. Such a test is not automatically worthless, but agreement alone does not establish correctness.

A passing suite establishes only its checks. Inspect inputs and assertions: positive-only tests do not cover negative inputs. A tested case can still be missed by weak assertions or different execution conditions. Plan early; add missing tests later.

**Example.** An expected-error test passes when a matching exception is raised:
```python
import unittest
check = unittest.TestCase()
with check.assertRaises(ValueError):
    split_bill(12, 0)
```
If the call returns normally, this check fails. An unexpected exception does not make it pass. The function raising the expected error is different from the test failing.

**Recap.** Choose cases from the contract. Compare observed behaviour with independent expectations. Check specified exceptions and inspect what the suite actually covers.

*Unit-test teaching, examples and assessment repairs independently written for this dataset.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Exceptions: Raising, Catching and Recovering](https://lightmysky.com/learn/computing/exceptions-raising-catching-and-recovering-mt_hEVa1JRrGu)

## Opens up

- [Debugging as a Method: Reproduce, Isolate, Fix](https://lightmysky.com/learn/computing/debugging-as-a-method-reproduce-isolate-fix-mt_2JGE4ICRf6)
- [Refactoring: Changing Structure Without Changing Behaviour](https://lightmysky.com/learn/computing/refactoring-changing-structure-without-changing-behaviour-mt_HHZufOyTg4)
