Lesson 30 of 30
Debugging and Testing
Visual Studio debugger, breakpoints, unittest, and writing test cases.
Debugging in Visual Studio 2026
Visual Studio 2026 has a world-class Python debugger. Key techniques:
- Click the grey margin to the left of a line number to set a breakpoint (red dot).
- Press F5 to run. Execution pauses at breakpoints.
- F10 — Step Over (execute current line, don't enter function).
- F11 — Step Into (enter the function call).
- Shift+F11 — Step Out.
- Hover over any variable to see its current value in a tooltip.
- The Locals and Watch windows show all variables in scope.
Writing Tests with unittest
# calculator.py
def add(a, b): return a + b
def divide(a, b):
if b == 0: raise ValueError("Cannot divide by zero")
return a / b
# test_calculator.py
import unittest
from calculator import add, divide
class TestCalculator(unittest.TestCase):
def test_add(self):
self.assertEqual(add(3, 4), 7)
self.assertEqual(add(-1, 1), 0)
def test_divide(self):
self.assertAlmostEqual(divide(10, 3), 3.333, places=2)
def test_divide_by_zero(self):
with self.assertRaises(ValueError):
divide(5, 0)
if __name__ == "__main__":
unittest.main()
Running Tests
In Visual Studio 2026, open the Test Explorer (Test → Test Explorer). It auto-discovers test files matching test_*.py and shows pass/fail for every test method.
✅ What's Next?
You've completed the Python in Visual Studio 2026 tutorial! Continue your journey with web frameworks (Flask, FastAPI), machine learning (scikit-learn, TensorFlow), or cloud deployment (Azure, AWS).
🎓 Congratulations!
You have now covered Python fundamentals through intermediate-level topics including OOP, file I/O, APIs, databases, and professional project management. You're ready to build real-world applications!