How does static testing differ from dynamic testing?
Static testing checks work products without running code, while dynamic testing runs the system and compares behaviour with the expected one. Static testing finds a defect in a requirement or code directly and earlier, while dynamic testing observes a failure that must then be traced to a defect. Neither replaces the other: performance, races and behaviour on real data show only at run time.
QA Fundamentals · Testing basics
There is no code yet, and you have already found a bug. Is that even testing?
At grooming you read the requirements and notice: on the registration screen the password is up to 20 characters, on the change-password screen up to 64. There is no build, no test has run, and a defect is already found. That is static testing. Vacancies often ask to "validate requirements and provide early feedback", and this is exactly it. The lesson explains how static differs from dynamic, what each finds and why one does not replace the other.
How it works
The difference is one thing: is the program run. Static testing checks work products without executing code: requirements, mock-ups, test cases, the code itself. This means reviews (from informal to inspection) and static analysis by tools. Dynamic testing runs the system with input data and compares behaviour with the expected.
To see why they find different things you need the chain: a person makes an error, it leaves a defect (bug) in an artifact, and only when the code is executed can the defect show up as a failure.
What each approach sees
Hence the advantage of static: it finds the defect directly, without a long analysis of a failure, and does it earlier, when the fix is cheap. The drawback: it does not see behaviour that arises only at run time (races, performance, interaction with real data). Dynamic sees behaviour, but only on the scenarios run, and leaves the path from failure to defect to the developer.
The difference in the price of a finding shows on the example we go through below: contradicting password limits on two screens.
The same defect, two moments of discovery
Different password limits are seen in the text of the requirements. The fix: one sentence, one conversation, one line in the spec.
The bug is seen as a failure: a 40-character password is accepted on change and login then fails. You must find the cause, fix code and tests.
Example: a contradiction in password requirements
A requirements review needs no code. Here are two fragments found side by side:
Registration: password 8 to 20 characters
Change password: password 8 to 64 characters
The reviewer asks: which limit is right, and what happens to a user who registered with a 20-character password and then changed it to 40? If this is not found now, the defect goes into code, then into test cases, and someone finds it as a failure in production or through a bug report "cannot log in after changing password". To make the review systematic and not accidental, a checklist is used:
[ ] The requirement is unambiguous: no two readings
[ ] The requirement is testable: a number, limit or criterion
[ ] It does not contradict others (screens, API, documents)
[ ] Negative cases and errors are described
[ ] There is an acceptance criterion
ISTQB review types differ in formality: informal (a colleague looks without a process), walkthrough (the author leads participants through the document), technical review (experts look for discrepancies and assess decisions), inspection (the most formal: roles, metrics, checklists). Static analysis works on code automatically: linters, type checking and security tools find unreachable code, undefined variables or dangerous patterns without running the program.
Limits and alternatives
- Static does not replace dynamic. It will not show whether a page is fast, whether it breaks under simultaneous actions or whether code fits real data.
- Dynamic does not replace static. A bug in requirements that was missed at review lands in code, and a test written from those requirements will not notice it.
- Reviews need time and agreement. Without a checklist and clear roles they turn into "take a look, is everything fine".
- Automatic static analysis gives false positives. Rules are tuned for the project, because noise teaches the team to ignore results.
Common mistakes
- Treating only running the program as testing. Reviewing requirements and mock-ups is testing too, and often the most profitable.
- Reading requirements for a "general impression". Without a checklist only obvious errors are found.
- Confusing static analysis with dynamic. A linter does not run code and a test does: different tools with different findings.
- Not recording review findings. Defects in documents are also filed and closed, or they get forgotten.
Check yourself
A linter reports an unused variable in code nobody has run yet. Is that static or dynamic testing? Was a defect or a failure found?
Answer
Static: the code was not executed. A defect in the code was found, not a failure, because a failure happens only at execution. Such findings are cheap and come before the first run.
What does dynamic testing add that even a perfect requirements review will not give?
Answer
Observation of real behaviour: performance, module interaction, races, behaviour on real data and environment. These appear only at execution, so a review will not show them.