← Back to libraryQuestion 317 of 468

Static vs Dynamic Testing

📌 Definition:

Static testing examines work products WITHOUT executing code (reviews, walkthroughs, inspections, static analysis); dynamic testing executes the software to observe its behavior against expected results (functional, non-functional testing).

📖 Detailed Explanation:

STATIC testing includes requirement/design/code reviews, walkthroughs, formal inspections, and static analysis tools (linters, SAST) — it finds defects early and cheaply (before code runs) and improves quality of documents/code. DYNAMIC testing runs the application (unit, integration, system, acceptance; functional and non-functional) to find defects in behavior. They're complementary: static catches issues (ambiguous requirements, code smells, security flaws) that dynamic can't easily, while dynamic catches runtime behavior static can't. Early static testing shifts defect detection left, reducing cost. Distinguishing them (and giving examples) is a common foundational question.

🔑 Key Points:
  • Static = no execution: reviews, walkthroughs, inspections, static analysis
  • Dynamic = execute the software: functional + non-functional testing
  • Static finds defects early/cheaply (shift-left); dynamic finds runtime behavior
  • Complementary — use both
🌍 Real-World Example:

A code review (static) catches a SQL-injection risk and an ambiguous requirement before any code runs, while executing the feature (dynamic) reveals it crashes on an empty cart — two defect types, two techniques.

🎯 Scenario-Based Interview Question:

What's the difference between static and dynamic testing, and give an example of each?