Learn unit testing in Python! 🧪
In this lesson, you will learn:
✅ Why automated testing beats manual testing
✅ unittest.TestCase to organize tests into classes
✅ assertEqual to verify return values
✅ assertRaises to test error handling
✅ assertIn to check membership
✅ setUp to create fresh test fixtures before each test
✅ tearDown to clean up after each test
✅ python3 -m unittest -v for verbose test output
✅ Testing classes with state and validation
✅ Mini Project: Gradebook with complete test coverage
🕐 Timestamps:
0:00 - Introduction
0:22 - Test Basics Explained
0:49 - Test Basics Demo
3:17 - setUp & tearDown Explained
3:44 - setUp & tearDown Demo
6:42 - Gradebook Explained
7:09 - Gradebook Demo
10:53 - Recap
11:28 - End
💻 Source Code: https://github.com/GoCelesteAI/python...
📚 Code from this lesson:
Create a test class
class TestMathTools(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
def test_divide_by_zero(self):
with self.assertRaises(ValueError):
divide(10, 0)
Run tests with verbose output
python3 -m unittest test_math_tools -v
🔗 Previous: Lesson 27 - Virtual Environments
🔗 Next: Lesson 29 - File I/O
#Python #PythonTutorial #LearnPython #Programming #UnitTesting #unittest #Testing #PythonBasics
Tags: Python, Python tutorial, Python for beginners, learn Python, unit testing, unittest, assertEqual, assertRaises, setUp, tearDown, TestCase, testing, TDD,
Python basics, CelesteAI
Category: Education