SWT3 Static Techniques
SWT3 Static Techniques
2 / 25
Static Testing
People Techniques
• individual:
– desk-checking, data-stepping, proof-reading
• group:
– Reviews (informal & formal): for consensus
– Walkthrough: for education
– Inspection (most formal): to find faults
3 / 25
Static Testing
Benefits of reviews
• Development productivity improvement
• Reduced development timescales
• Reduced testing time and cost
• Lifetime cost reductions
• Reduced fault levels
• Improved customer relations
• etc.
4 / 25
Static Testing
What can be inspected?
• policy, strategy, business plans, marketing or
advertising material, contracts
• system requirements, feasibility studies,
acceptance test plans
• test plans, test designs, test cases, test results
• system designs, logical & physical
• software code
• user manuals, procedures, training material
5 / 25
Static Testing
What can be inspected?
Tests
Tests
Tests
Tests
6 / 25
Static Testing
The types of defects found by reviews
• Deviations from standards.
• Requirements defects – for example, the
requirements are ambiguous, or there are
missing elements.
• Design defects – for example, the design
does not match the requirements.
• Insufficient maintainability – for example, the
code is too complex to maintain.
• Incorrect interface specifications – for
example, the interface specification does not
match the design or the receiving or sending
interface.
7 / 25
Review Process 1/6
8 / 25
Review Process 2/6
Basic review process
• The document under review is studied by the
reviewers.
• Reviewers identify issues or problems and
inform the author either verbally or in a
documented form, which might be as formal as
raising a defect report or as informal as
annotating the document under review.
• The author decides on any action to take in
response to the comments and updates the
document accordingly.
9 / 25
Review Process 3/6
Formal Review
Process
• Planning
• Initiate Review
• Individual
Review/Preparation
• Issue
Communication &
Analysis
• Fixing & Reporting
10 / 25
Review Process 4/6
Roles in Formal
Review
• The Author
• Management
• Facilitator/Moderator
• Review Leader
• Reviewers
• Scribe (Recorder)
11 / 25
Review Process 5/6
Types of Review
• Informal Review
• Walkthrough
• Technical review
• Inspection
12 / 25
Review Process 6/6
Review Techniques
• Ad hoc reviewing: carried out by independent
reviewers informally, without a structured
process
• Checklist-based reviewing: guided by a list of
questions or required attributes
• Scenario-based reviewing: guided by
determining the ability of the work product to
address specific scenario
• Role-based reviewing: reviewers evaluate a work
product from the perspective of different
stakeholder roles
• Perspective-based reading/reviewing: reviewers
evaluate the work product from the different
viewpoints
13 / 25
Success factors for reviews
Organizational People-related success factors for
success factors for reviews
reviews • Pick the right reviewers
• Have clear • Involve testers: to learn & to design
objectives test
• Pick the right review • Each participant does their review
type & technique work well
• Review materials • Limit the scope of the review & pick
need to be kept up things that really count
to date • Defects fond should be welcomed
• Limit the scope of • Review meetings are well managed
the review
• Trust is critical
• It takes time
• How you communicated is
• Management important
support is critical
14 / 25
• Follow the rules by keep it simple
Static Analysis By Tools
• Static techniques do not execute the code
• A form of automated testing
– check for violations of standards
– check for things which may be a fault
• Descended from compiler technology
– a compiler statically analyses code, and “knows” a
lot about it, e.g. variable usage; finds syntax faults
– static analysis tools extend this knowledge
– can find unreachable code, undeclared variables,
parameter type mis-matches, uncalled functions &
procedures, array bound violations, etc.
15 / 25
Static Analysis By Tools
Data flow analysis
• This is the study of program variables
– variable defined* where a value is stored into it
– variable used where the stored value is accessed
– variable is undefined before it is defined or when it
goes out of scope
x is defined, y and z are used
x=y+z
IF a > b THEN read(S)
16 / 25
Static Analysis By Tools
Data flow analysis faults
n := 0
read (x) Data flow anomaly: n is
re-defined without being used
n := 1
while x > y do Data flow fault: y is used
before it has been defined
begin (first time around the loop)
read (y)
write( n*y)
x := x - n
end
17 / 25
Static Analysis By Tools
Control flow analysis
• Highlights:
– nodes not accessible from start node
– infinite loops
– multiple entry to loops
– whether code is well structured, i.e. reducible
– whether code conforms to a flowchart
grammar
– any jumps to undefined labels
– any labels not jumped to
– cyclomatic complexity and other metrics
18 / 25
Static Analysis By Tools
Control flow analysis
Unreachable code example
• Macro definitions
(different for different platforms the code runs
on)
Buffsize: 1000
Mailboxmax: 1000
IF Buffsize < Mailboxmax THEN
Error-Exit
ENDIF
• Static Analysis finds the THEN clause
unreachable, so will flag a fault
19 / 25
Static Analysis By Tools
Control flow analysis
Cyclomatic complexity
• cyclomatic complexity is a measure of the
complexity of a flow graph
(and therefore the code that the flow graph represents)
• the more complex the flow graph, the greater the
measure
• it can most easily be calculated as:
complexity = number of decisions + 1
20 / 25
Static Analysis By Tools
Control flow analysis
What is the cyclomatic
complexity?
2 3 5
21 / 25
Static Analysis By Tools
Control flow analysis
Example control flow graph init
Pseudo-code:
Result = 0 do
Right = 0
DO WHILE more Questions if r=r+1
IF Answer = Correct THEN
Right = Right + 1
ENDIF end
END DO
Result = (Right / Questions) res
IF Result > 60% THEN
Print "pass" if pass
ELSE
Print "fail” fail
ENDIF
end
22 / 25
Static Analysis By Tools
Static metrics
• lines of code (LOC)
• operands & operators (Halstead’s metrics)
• fan-in & fan-out
• nesting levels
• function calls
• OO metrics:
– inheritance tree depth,
– number of methods,
– coupling & cohesion
23 / 25
Static Analysis By Tools
Limitations and advantages
• Limitations:
– cannot distinguish "fail-safe" code from
programming faults or anomalies (often
creates overload of spurious error messages)
– does not execute the code, so not related to
operating conditions
• Advantages:
– can find faults difficult to "see"
– gives objective quality assessment of code
24 / 25