Courses/Testing & Debugging

🧪 Testing & Debugging

unittest Basics

Group tests into a TestCase and run them.

unittest ships with Python. Subclass TestCase and use assertEqual, assertTrue, assertRaises to express expectations.

import unittest

class MathTests(unittest.TestCase):
    def test_add(self):
        self.assertEqual(1 + 1, 2)
main.py
Output
Press Run to execute.
Expected output
ok

Sign in to track your progress across lessons.