Static testing is a testing technique that examines software work products without executing the code. This is achieved through manual reviews or static analysis tools.
The primary goals of static testing are:
| Aspect | Static Testing | Dynamic Testing |
|---|---|---|
| Execution | No execution of code or system. | Code is executed to verify behavior. |
| Purpose | Identify errors in documents, designs, or code before execution. | Detect defects during execution. |
| Techniques Used | Reviews, static analysis. | Functional, non-functional testing. |
| Performed On | Requirements, design documents, code. | Running software or system. |
| Cost of Defect Fixing | Cheaper, as defects are caught early. | More expensive, as defects appear late. |
Static testing uses two main techniques:
Think of static testing like reviewing a blueprint of a house before construction begins:
Static testing applies to a variety of software work products. Let’s look at these work products in detail:
Requirements Specifications:
These documents describe what the system should do.
Static testing ensures the requirements are clear, complete, and consistent.
Common Defects:
Ambiguous statements (e.g., “The system should work fast”).
Missing requirements (e.g., no specification for error handling).
Example:
Requirement: “The website must handle 500 users simultaneously.”
Ambiguity: What happens if there are 501 users? Static testing helps clarify such ambiguities.
Functional and Technical Designs:
Source Code:
User Documentation:
Test Plans and Test Cases:
A review is a systematic examination of a software work product to find defects and improve quality. Reviews are often manual processes where team members analyze documents, code, or designs.
| Review Type | Key Features | Outcome |
|---|---|---|
| Informal Review | - No formal process or roles.- Casual discussion and feedback.- Low-cost and lightweight. | Understanding and advice. |
| Walkthrough | - The author leads the session.- Team members ask questions and give suggestions.- Typically educational. | Improved understanding. |
| Technical Review | - Involves technical experts.- Identifies deviations from specifications.- Structured but less formal than inspections. | Identification of issues. |
| Inspection | - A formal, structured process.- Roles include moderator, author, reviewers, and recorder.- Uses checklists for defect detection. | Detailed defect detection. |
In formal reviews like inspections, specific roles are assigned to ensure the review is efficient and thorough:
Author:
Moderator:
Reviewers:
Recorder (Scribe):
Imagine a developer writes the following code:
def calculate_area(radius):
return 3.14 * radius * radius
The team conducts a walkthrough with the following feedback:
3.14 should be replaced with math.pi for precision.”radius is negative? Add input validation.”Outcome:
Revised Code:
import math
def calculate_area(radius):
if radius < 0:
raise ValueError("Radius cannot be negative")
return math.pi * radius * radius
Reviews are one of the most effective static testing techniques. Conducting reviews early in the Software Development Lifecycle (SDLC) can bring numerous benefits:
Example:
A requirement states, “The system should allow quick login for all users.”
- Without clarification, developers may not understand what “quick” means.
- In a review, testers clarify that “quick” means login within 3 seconds.
| Phase of Detection | Cost of Fixing Defects |
|---|---|
| Requirements/Design | Low |
| Coding | Moderate |
| Testing | High |
| Production | Very High |
Example:
A review of a user manual ensures the documentation is clear and complete, reducing confusion for end-users.
Example:
In a design review, developers may clarify system architecture choices, while testers provide input on potential edge cases.
Static analysis is an automated technique used to analyze the source code or software artifacts without executing them. Tools are used to identify potential issues like syntax errors, logical flaws, or coding standard violations.
Static analysis tools serve various purposes depending on the type of analysis performed. Let’s break them down:
| Tool Function | Description | Examples | Benefits |
|---|---|---|---|
| Coding Standards | Ensures code complies with style and format guidelines. | Checkstyle, SonarQube | Maintain consistent, clean, and readable code. |
| Code Metrics | Measures code complexity, size, and maintainability. | SonarQube, PMD | Identify overly complex code that is hard to test and maintain. |
| Syntax Checking | Checks for syntax errors in the code. | Compilers, Lint | Prevent compilation errors early. |
| Data Flow Analysis | Identifies incorrect variable usage and data flow issues. | Coverity, Fortify | Avoid logical errors like unused or uninitialized variables. |
| Code Coverage Analysis | Measures how much code is covered by test cases. | JaCoCo, Clover | Ensure all parts of the code are tested. |
Coding standards ensure consistency in the codebase. Tools like Checkstyle or SonarQube analyze code to identify violations.
Example:
Rule: All class names must start with an uppercase letter.
Code:class testclass: # Incorrect pass class TestClass: # Correct pass
Static analysis flags testclass as a violation of the coding standard.
Code metrics measure properties like cyclomatic complexity, which determines how complex the code logic is.
Example:
A function with multiple nested “if” statements may have high cyclomatic complexity:def calculate_discount(price, membership, holiday): if price > 100: if membership == "Gold": if holiday: return price * 0.5 else: return price * 0.7 return price
Static analysis calculates cyclomatic complexity and suggests refactoring if the value is too high.
Tools like Lint check for syntax errors and ensure the code adheres to programming language rules.
Example:
def my_function(): print("Hello World" # Missing closing parenthesisError: Static analysis detects the missing parenthesis and flags it before execution.
Data flow analysis identifies unused or uninitialized variables.
Example:
def add_numbers(a, b): result = a + b unused_variable = 10 # This variable is never used return result
Static analysis detects that unused_variable is declared but not used, helping clean up the code.
Code coverage tools analyze how much of the code is tested. They identify untested parts of the program.
Example:
Suppose a function has three branches:def check_even(num): if num % 2 == 0: return "Even" else: return "Odd"
Static analysis ensures all branches (both "Even" and "Odd") are covered by test cases.
| Tool Function | Key Purpose | Example Tools |
|---|---|---|
| Coding Standards | Ensure consistent coding practices. | Checkstyle, SonarQube |
| Code Metrics | Measure code complexity and size. | SonarQube, PMD |
| Syntax Checking | Identify syntax errors early. | Lint, Compilers |
| Data Flow Analysis | Detect incorrect or unused variables. | Coverity, Fortify |
| Code Coverage Analysis | Measure test coverage of code paths. | JaCoCo, Clover |
Truth: Static testing applies to any work product, including:
ISTQB Concept: Static testing = any technique that evaluates work products without executing the software.
Truth: Static testing can detect:
Many students confuse static analysis with dynamic white-box testing (like statement or branch coverage).
Static analysis is considered a white-box testing technique because it requires knowledge of the internal code structure.
However, it differs from dynamic white-box testing because the code is never executed.
| Technique | White-box? | Requires Code Execution? |
|---|---|---|
| Static Analysis | Yes | No |
| Statement/Branch Testing | Yes | Yes |
Static Analysis Examples:
This table helps you quickly distinguish between the four review types—an ISTQB exam favorite.
| Review Type | Formality | Led By | Participants | Outcome Type |
|---|---|---|---|---|
| Informal Review | Low | No one | Peers (colleagues) | Suggestions, informal notes |
| Walkthrough | Medium | Author | Team (cross-functional) | Clarifications, Q&A |
| Technical Review | Medium | Facilitator | Technical experts | Defect identification |
| Inspection | High | Moderator | Assigned roles (Author, Reviewers, Recorder, Moderator) | Formal defect log |
At the end of the “Reviews” section, include a bullet-point “You Should Know” box:
What is static testing in software testing?
Static testing is the process of evaluating software artifacts without executing the code.
Static testing examines work products such as requirements, design documents, and source code to identify defects early in the development lifecycle. Techniques include reviews, walkthroughs, inspections, and static code analysis. Because the software is not executed, the focus is on detecting issues like incorrect requirements, inconsistent design decisions, or coding standard violations. Identifying defects early through static testing can significantly reduce the cost of fixing them compared to finding them during later dynamic testing phases.
Demand Score: 60
Exam Relevance Score: 88
How do static testing and dynamic testing differ?
Static testing evaluates artifacts without executing the program, whereas dynamic testing involves executing the software to observe its behavior.
Static testing focuses on reviewing documentation, requirements, design models, and source code to detect issues early. Examples include inspections and automated static code analysis. Dynamic testing requires running the software with selected inputs and verifying outputs against expected results. Both approaches complement each other: static testing identifies defects earlier and prevents them from propagating, while dynamic testing validates the software’s runtime behavior and functional correctness.
Demand Score: 57
Exam Relevance Score: 83
What is the primary purpose of reviews in static testing?
The primary purpose of reviews is to detect defects in work products early and improve their quality before implementation progresses.
Reviews involve systematically examining documents or code with the participation of multiple stakeholders. Different review types exist, including informal reviews, walkthroughs, technical reviews, and inspections. Besides defect detection, reviews also promote shared understanding of requirements, improve communication among team members, and ensure adherence to standards and guidelines. Early feedback from reviews helps prevent defects from propagating into later development stages.
Demand Score: 58
Exam Relevance Score: 82