# Unit Test (unittest)

say it: **“YOO-nit-test”** **/ˈjunɪtˌtɛst/** or **“YOO-nit TEST”** **/ˈjuːnɪt tɛst/**

Code that checks one function gives the right answer.

## What is a **unit test**?

A **unit test** is a small piece of code that checks one function gives the right answer. Python's built-in tool for them is `unittest`.

```python
import unittest

def add_tax(price):
    return round(price * 1.07, 2)

class TestTax(unittest.TestCase):
    def test_adds_seven_percent(self):
        self.assertEqual(add_tax(100), 107.0)
```

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 17, 2026

Source: https://www.ask-codey.com/glossary/unit-test-unittest
