Static Testing
Static Testing
SIM3302
objectives
Able to list various type of structured group examinations (manual checking) Able to statically analyse program code using compilers, data flow analysis, and control flow analysis
Static analysis
What is static analysis?
Analysis of software artifacts e.g., requirements or code, carried out without execution of these software artifacts
Objects to be analysed
Formal documents that must follow a certain formal structure
4
Static Analyser
Document Eg. Source code Syntax violation Deviation Data flow info Control flow info
Static analysis
Who and when used static analysis tools?
Developers Before and during component or integration testing
To check if guidelines or programming conventions are adhered to
Static Analysis
If a static analysis is performed before a review, a number of defects can be found and the number of the aspects to be checked in the review clearly decreases
Thus much less effort in a review
How it is performed?
Analysis of data use
The usage of data on paths through the program code is checked
What is an anomaly?
An inconsistency that can lead to failure, but does not necessarily so May be flagged as a risk
9
The usage of every single variable is inspected Three types of usage or states of variables
Defined (d) : the variable is assigned a value Reference (r) : the value of the variable is read and/or used Undefined (u) : the variable has no defined value
10
11
void exchange (int& Min, int& Max) { int Help; if (Min > Max) { Max = Help; Max = Min; Help = Min; } }
12
13
14
void exchange (int& Min, int& Max) { int Help; if (Min > Max) { Max = Help; Max = Min; Help = Min; } }
15
A program structure is represented (modeled) by a control flow graph (CFG) CFG is a directed graph that shows a sequence of events (paths) in the execution through a component or system CFG consists of nodes and edges
Node represents a statement or a sequence of statements Edge represents control flows from one statement to another
16
17
DO
IF C THEN IF D THEN IF E THEN F ELSE G ELSE IF H THEN J ELSE K ELSE L WHILE B M
Modeled as
C D
E
G F J
H K L
B M
18
19
Determining Metrics
Quality characteristics can be measured with metrics The intention is to gain a quantitative measure of software whose nature is abstract Example:
McCabes metric or cyclomatic complexity, V Measures the structural complexity of program code Based on CFG V(G) = e - n + 2 where V(G) is cyclomatic number of graph G e = number of edges in G n = number of nodes in G
20
Determining Metrics
Example: for CFG in previous slide
V(G) = e - n + 2 = 16 12 + 2 = 6 V(G) higher than 10 can not be tolerated and rework of the source code has to take place
V(G) can be used to estimate the testability and maintainability V(G) specifies the number of linearly independent paths in the program
21
Summary
Static testing can be done to find defect and deviation using:
Structured group examinations
Reviews
Inspection, walkthrough, technical review, informal review