Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Python Fundamentals

Lesson 33 of 55 · Python

Unit Testing with unittest

Duration: 20 minutes

Unit Testing with unittest\n\nPython’s standard library includes unittest, a framework for writing repeatable tests. Test cases are classes that inherit from unittest.TestCase.\n\npython\nimport unittest\n\ndef add(a, b):\n return a + b\n\nclass TestMath(unittest.TestCase):\n def test_add(self):\n self.assertEqual(add(2, 3), 5)\n self.assertEqual(add(-1, 1), 0)\n\nif __name__ == '__main__':\n unittest.main()\n\n\nRun the script (python test_math.py) and unittest will report any failures.\n

Previous: Context ManagersNext: Logging