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.
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
Updated