Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 60 ยท Static Testing and Reviews

Static vs Dynamic Testing

Learn the difference between static testing (reading and analysing work products) and dynamic testing (running the software), what each finds, and when to use them.

Most people picture testing as "run the program and see what happens". That is only half the story. You can find a surprising number of problems without running anything at all, by reading a requirement, studying a design, or scanning source code with a tool. Finding a problem before the code exists, or before it runs, is usually much cheaper than finding it in a test environment or in production.

This lesson separates the two families of testing: static testing, which examines work products without executing code, and dynamic testing, which executes the software and observes its behavior. Good teams use both, because each one finds problems the other misses.

Real versus stand-in. Linters, static analyzers and review tools are real products that parse code into syntax trees. The TryIt blocks here use tiny stand-ins built from regular expressions and plain functions. They show the idea of a static rule and of a dynamic check, but a real analyzer is far more accurate than a text scan.

What static testing is

Static testing evaluates a work product by looking at it, not by running it. A work product is anything produced during the project: a requirements document, a user story, a design diagram, a test plan, a database schema, or source code.

There are two main ways to do it:

  • Reviews are done by people. Someone reads the work product and looks for mistakes, gaps and misunderstandings. You will meet the formal variants in Reviews, Walkthroughs and Inspections.
  • Static analysis is done by tools. A tool reads source code (or a model, or a configuration file) and applies rules. Compilers, linters, type checkers, security scanners and complexity analyzers all belong here.

Because nothing runs, static testing can start the moment the first document exists. That is its biggest advantage. A wrong sentence in a requirement costs minutes to fix. The same mistake, built into the product, can cost days.

What static testing finds well

Static testing is good at problems that are visible in the text of the work product:

  • Ambiguous, contradictory or missing requirements.
  • Design flaws, such as a service that depends on itself.
  • Coding standard violations and inconsistent naming.
  • Syntax errors and type mismatches.
  • Unused variables, unreachable code and dead branches.
  • Security smells, such as building SQL by joining strings.
  • Gaps in test coverage in a test plan, such as a requirement with no test.

It is weak at problems that only appear at runtime: a slow query under real load, a race condition between two threads, or a calculation that is syntactically perfect but uses the wrong formula.

What dynamic testing is

Dynamic testing executes the software with chosen inputs and compares the observed behavior with the expected behavior. Unit tests, integration tests, exploratory sessions, load tests and acceptance tests are all dynamic. Everything in the later chapters on test design, execution and defect reporting is built on it.

Dynamic testing finds:

  • Failures, meaning wrong behavior you can observe. See What Is Software Testing? for the failure, defect and error vocabulary.
  • Wrong results from correct-looking code, such as a discount applied twice.
  • Performance, memory and concurrency problems.
  • Problems in how components behave together.
  • Usability problems that appear only when a person uses the product.

Its cost is that it needs something to run: a working build, an environment, and test data. That means it happens later.

Two ways to find problems

Static Examine work products without running code.
Dynamic Run the software and observe its behavior.

Both are testing. They find different kinds of defects.

1 / 3

A tiny static checker

Real linters build a syntax tree. This stand-in is much cruder: it checks each line of a source string against a few text rules, then looks for variables that are declared but never used again. It never runs the code it scans, which is exactly what makes it static.

JS A tiny static checker

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice what the checker could and could not say. It flagged style and risk. It had no idea whether addTax is right, and it never will: a tax rate of 1.2 is a business fact, not something you can see in the syntax.

Where static and dynamic testing differ

Here is the comparison in one table.

Static testing Dynamic testing
Needs running code No Yes
Earliest start As soon as a work product exists After code is built
Finds Defects in documents and code text Failures in behavior
Typical tools Linters, type checkers, review checklists Test frameworks, test runners, load tools
Cost to fix what it finds Lowest Higher, because more work is built on top
Blind spot Runtime behavior Code paths and documents nobody exercised

Static testing finds defects directly: the reviewer points at the line or sentence that is wrong. Dynamic testing finds failures, and then someone must debug to locate the defect behind each one. That is one reason fixing a statically found defect is quick.

The same bug seen two ways

The next stand-in has two small functions. average has a defect you could spot by reading it. applyDiscount looks perfectly tidy to a linter, and only running it with a real example, and comparing with what the requirement says, shows that it is wrong.

JS One bug found by reading, one by running

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The empty-list failure was predictable from reading. The discount failure needed the requirement and a concrete example: 200 - 200 * 10 is -1800. The 0 percent check passes, which is a good reminder that a passing test proves very little by itself. Choosing inputs that expose problems is the subject of the test design chapter, starting with Equivalence Partitioning.

Using both in a project

Place the two families along the timeline of a feature:

flowchart LR
    A["Requirement<br/>written"] --> B["Review<br/>(static)"]
    B --> C["Code<br/>written"]
    C --> D["Linter and<br/>type check (static)"]
    D --> E["Unit and<br/>integration tests (dynamic)"]
    E --> F["System and<br/>acceptance tests (dynamic)"]

Static checks guard the early steps and the code text, dynamic tests guard behavior later on.

A practical rule of thumb:

  • Review requirements and designs before anyone builds them.
  • Run linters and type checks on every change, automatically.
  • Run dynamic tests at every level, from small unit tests to full system runs.
  • When a dynamic test finds a defect, ask whether a review or a rule could have caught it earlier, and add that check.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which activity is static testing?

    Static testing examines work products without executing code. Reading a requirements document is a review. The other three all run the software.
  2. 2. What is the main advantage of static testing?

    Static testing can begin as soon as a work product exists. It does not replace dynamic testing, and it cannot show runtime behavior.
  3. 3. A function compiles, passes the linter, but returns a price of -1800 for a 10 percent discount on 200. Which kind of testing is most likely to reveal this?

    The code is syntactically fine. Only running it and comparing the result with the requirement exposes the wrong formula.
  4. 4. Which defect is a static analyzer best placed to find?

    Unused variables are visible in the source text. The other problems appear only when the software runs or is used.

Summary

  • Static testing examines work products (documents, designs, code) without running the code, through reviews and static analysis tools.
  • Dynamic testing runs the software and compares actual behavior with expected behavior.
  • Static testing starts earlier and finds defects directly; dynamic testing finds failures that must then be traced to a defect.
  • Each has blind spots: static misses runtime behavior, dynamic misses what nobody executes.
  • Combine them: review early, analyze automatically on every change, and test dynamically at every level.

Next: Reviews, Walkthroughs and Inspections.