Skip to content

Testing Overview

Introduction to testing frameworks and strategies for writing reliable tests.

Why Test?

Benefits of automated testing.

# Testing benefits:
# - Catch bugs early
# - Document expected behavior
# - Enable refactoring safely
# - Improve code quality
# - Reduce manual testing

def add(a, b):
    return a + b

# Simple test
assert add(2, 3) == 5, "Addition failed"
assert add(-1, 1) == 0, "Zero test failed"
print("All tests passed!")
All tests passed!

Testing Frameworks

Popular testing frameworks in Python.

# unittest - built-in testing framework
import unittest

class TestMath(unittest.TestCase):
    def test_addition(self):
        self.assertEqual(2 + 3, 5)

# pytest - simpler, more powerful
# pip install pytest
# def test_addition():
#     assert 2 + 3 == 5

# Running tests:
# unittest: python -m unittest test_module
# pytest: pytest test_file.py

print("Testing frameworks overview")
Testing frameworks overview