Unit 4 - Code Construction and Testing Strategies.pptx
Unit 4 - Code Construction and Testing Strategies.pptx
Software
Construction
Disclaimer:
The lecture notes have been prepared by referring to many books and notes prepared by the teachers. This
document does not claim any originality and cannot be used as a substitute for prescribed textbooks.
Topics
■ Software Construction
■ Coding Standards
■ Coding Framework
■ Reviews – Desk Checks (Peer Reviews)
■ Walkthroughs
■ Code Reviews, Inspections
■ Coding Methods
■ Structured Programming
■ Object-Oriented Programming
■ Automatic Code Generation
■ Software Code Reuse
■ Pair Programming
■ Test-Driven Development
■ Configuration Management
■ Software Construction Artefacts
2
Software Construction
Introduction
■ A layman believes that software construction is the entire software
development process.
■ But, in fact, it is just one of the crucial tasks in software development;
software requirement management, software design, software testing and
software deployment are all equally crucial tasks.
■ Furthermore, the process of software construction itself consists of many
tasks; it not only includes software coding but also unit testing, integration
testing, reviews and analysis.
■ Construction is one of the most labor intensive phases in the software
development life cycle.
■ It comprises 30% or more of the total effort in software development.
■ What a user sees as the product at the end of the software development
life cycle is merely the result of the software code that was written during
software construction.
■ Due to the labor intensive nature of the software construction phase, the
work is divided not only among developers, but also small teams are
formed to work on parts of the software build.
Software Construction
Introduction
■ In fact, to shrink the construction time, many distributed teams, either
internal or through contractors are deployed.
■ The advantage to this is that these project teams do the software coding
and other construction work in parallel with each other and thus the
construction phase can be collapsed.
■ This parallel development is known as concurrent engineering.
■ Constructing an industry strength software product of a large size
requires stringent coding standards.
■ The whole process of construction should follow a proven process so that
the produced code is maintainable, testable and reliable.
■ The process itself should be efficient so that resource utilization can be
optimized and thus cost of construction can be kept at a minimum.
Software Construction
Coding Standards
■ Developers are given software design specifications in the form of use cases, flow
diagrams, UI mock ups, etc., and they are supposed to write a code so that the
built software matches these specifications.
■ Converting the specifications into software code is totally dependent on the
construction team.
■ How well they do it depends on their experience, skills and the process they follow
to do their job.
■ Apart from these facilities, they also need some standards in their coding so that
the work is fast as well as has other benefits like maintainability, readability and
reusability (Figure-Source Code Production (Conversion) from Software Design).
Software Construction
Coding Standards
■ At any time, a code written by a developer will always be different from
that written by any other developer.
■ This poses a challenge in terms of comprehending the code while reusing
the code, maintaining it, or simply reviewing it.
■ A uniform coding standard across all construction teams working on the
same project will make sure that these issues can be minimized if not
eliminated (Figure below - Software Construction Characteristics).
■ Some of the coding standards include standards for code modularity,
clarity, simplicity, reliability, safety and maintainability.
Software Construction
Coding Standards – Modularity
■ The produced software code should be modular in nature.
■ Each major function should be contained inside a software code module.
■ The module should contain not only structure, but it should also process data.
■ Each time a particular functionality is needed in the software construction, it can
be implemented using that particular module of software code.
■ This increases software code reuse and thus enhances productivity of
developers and code readability.
Coding Standards – Clarity
■ The produced code should be clear for any person who would read the
source code.
■ Standard naming conventions should be used so that the code has ample
clarity.
■ There should be sufficient documentation inside the code block, so that
anybody reading the code could understand what a piece of code is supposed to
do.
■ There should also be ample white spaces in the code blocks, so that no piece
of code should look crammed. White spaces enhance readability of written code.
Software Construction
Coding Standards – Simplicity
■ The source code should have simplicity and no unnecessary complex logic;
improvisation should be involved, if the same functionality can be achieved by a
simpler piece of source code.
■ Simplicity makes the code readable and will help in removing any defects found in
the source code.
■ Simplicity of written code can be enhanced by adopting best practices for many
programming paradigms.
■ For instance, in the case of object-oriented programming, abstraction and
information hiding add a great degree of simplicity.
■ Similarly, breaking the product to be developed into meaningful pieces that mimic
real life parts makes the software product simple.
Reviews – Inspections
■ Code inspections are final reviews of software code in which it is decided
whether to pass a piece of code for inclusion into the main software build.
Software Construction
Coding Methods
■ Converting design into optimal software construction is a very serious topic that
has generated tremendous interest over the years.
■ Many programming and coding methods were devised and evolved as a result.
■ As it is well known in the industry, the early software products were of small size
due to limited hardware capacity.
■ With increasing hardware capacity, the size of software products has been
increasing.
■ Software product size affects the methods that can be used to construct specific
sized software products.
■ Advancement in the field of computer science also allows discovery of better
construction methods.
■ To address needs of different sized software products in tandem with
advancement in computer science, different programming techniques evolved.
■ These include structured programming, object-oriented programming,
automatic code generation, test-driven development, pair programming, etc.
Software Construction
27
Verification and Validation
Validation is the process of evaluating a software system or component
during, or at the end of, the development cycle in order to determine
whether it satisfies specified requirements
Does the product perform as desired?
Are we building the right product
Methods of Validation : Dynamic Testing
Testing
28
29
Example for Verification and Validation
30
Difference between Verification and Validation
31
Difference between Verification and Validation
32
Software Testing Strategy for
conventional software architecture
■ A Software process & strategy for software testing may
also be viewed in the context of the spiral.
■ Unit testing begins at the vortex of the spiral and
concentrates on each unit (i.e., component) of the
software.
■ Testing progresses by moving outward along the spiral to
integration testing, where the focus is on design and the
construction.
■ Another turn outward on the spiral, we encounter
validation testing, where requirements established as
part of software requirements analysis are validated
against the software.
■ Finally, we arrive at system testing, where the software
and other system elements are tested as a whole.
■ Software process from a procedural point
of view; a series of four steps that are
implemented sequentially.
■ Initially, tests focus on each component individually, ensuring
that it functions properly as a unit.
■ Unit testing makes heavy use of white-box testing techniques,
exercising specific paths in a module's control structure.
■ Integration testing addresses the issues associated with the
dual problems of verification and program construction.
■ Black-box test case design techniques are the most prevalent
during integration.
■ Now, validation testing provides final assurance that software
meets all functional, behavioral, and performance
requirements.
■ Black-box testing techniques are used exclusively during
validation.
■ once validated, must be combined with other system elements
(e.g., hardware, people, databases). System testing verifies
that all elements mesh properly and that overall system
function / performance is achieved.
Criteria for Completion of Testing
■ There is no definitive answer to state that “we have done
with testing”.
■ One response to the question is: "You're never done
testing, the burden simply shifts from you (the software
engineer) to your customer." Every time the customer/
user executes a computer program, the program is being
tested.
■ Another response is: "You're done testing when you run
out of time (deadline to deliver product to customer) or
you run out of money (spend so much money on testing).
■ But few practitioners would argue with these responses,
a software engineer needs more rigorous criteria for
determining when sufficient testing has been conducted.
■ Response that is based on statistical criteria: "No, we
cannot be absolutely predict that the software will never
fail, but relative to a theoretically sound and
experimentally validated statistical model, we have done
sufficient testing to say with 95 percent confidence that
program will not fail.
Unit testing strategies for conventional
software
■ Focuses verification effort on the smallest unit of
software design – component or module.
■ Using the component-level design description as a guide
◻ important control paths are tested to uncover errors
within the boundary of the module.
■ Unit test is white-box oriented, and the step can be
conducted in parallel for multiple components.
■ Unit test consists of
◻ Unit Test Considerations
◻ Unit Test Procedures
Unit Test Considerations
Contd.
■ Module interface - information properly flows into
and out of the program unit under test.
■ local data structure - data stored temporarily
maintains its integrity.
■ Boundary conditions -module operates properly
at boundaries established to limit or restrict
processing
■ Independent paths - all statements in a module
have been executed at least once.
■ And finally, all error handling paths are tested.
■ Module interface are required before any other
test is initiated because If data do not enter and
exit properly, all other tests are debatable.
■ In addition, local data structures should be
exercised and the local impact on global data
should be discover during unit testing.
■ Selective testing of execution paths is an
essential task during the unit test. Test cases
should be designed to uncover errors due to
◻ Computations,
◻ Incorrect comparisons, or
◻ Improper control flow
■ Basis path and loop testing are effective
techniques for uncovering a broad array of path
errors.
Errors are commonly found during unit testing
The process continues from step 2 until the entire program structure is
built.
Problem occur in top-down integration
■ Logistic problems can arise
■ most common problems occurs when processing at low levels
in the hierarchy is required to adequately test upper levels.
■ No significant data can flow upward in the program structure
due to stubs replace low level modules at the beginning of
top-down testing. In this case, Tester will have 3 choice
◻ Delay many tests until stubs are replaced with actual
modules
◻ develop stubs that perform limited functions that simulate
the actual module
◻ integrate the software from the bottom of the hierarchy
upward
Bottom-up Integration
■ Bottom-up integration testing, as its name
implies, begins construction and testing with
atomic modules (i.e., components at the lowest
levels in the program structure)
■ Because components are integrated from the
bottom up, processing required for components
subordinate to a given level is always available
and the need for stubs is eliminated.
Bottom up integration process steps
Method
s
Strategies
87
White-Box
Testing
88
Why
Cover?
logic errors and incorrect assumptions
are inversely proportional to a path's
execution probability
or
number of enclosed areas +
1
In this case, V(G) = 4
93
Cyclomatic
Complexity
A number of industry studies have indicated
that the higher V(G), the higher the probability
or errors.
modules
V(G)
95
Importance of Cyclomatic Complexity
96
Properties of Cyclomatic Complexity
97
Calculating Cyclomatic Complexity
98
Calculating Cyclomatic Complexity
Method-01:
Method-02:
Cyclomatic Complexity = E – N + 2
Here-
•E = Total number of edges in the control flow
graph
•N = Total number of nodes in the control flow
graph
99
Calculating Cyclomatic Complexity
Method-03:
Cyclomatic Complexity = P + 1
Here,
P = Total number of predicate nodes contained in
the control flow graph
Note-
100
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Problem-01
Calculate cyclomatic
complexity for the given
code-
Method-01:
Cyclomatic Complexity
= Total number of closed
regions in the control flow
graph + 1
= 1+ 1
=2
101
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Method-02:
Cyclomatic Complexity
=4–4+2
=4–4+2
=2
102
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Method-03:
Cyclomatic Complexity
=P+1
=1+1
=2
103
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Problem-02
Calculate cyclomatic
complexity for the given
code-
1. IF A = 354
2. THEN IF B > C
3. THEN A = B
4. ELSE A = C
5. END IF
6. END IF
7. PRINT A
104
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Method-01:
Cyclomatic Complexity
= Total number of closed regions in the
control flow graph + 1
=2+1
=3
105
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Method-02:
Cyclomatic Complexity
=E–N+2
=8–7+2
=3
106
PRACTICE PROBLEMS BASED ON CYCLOMATIC COMPLEXITY
Method-03:
Cyclomatic Complexity
=P+1
=2+1
=3
107
Problem 4
Paths
• path 1: 1-11
• path 2: 1-2-3-4-5-10-1-11
• path 3: 1-2-3-6-8-9-10-1-11
• path 4: 1-2-3-6-7-9-10-1-11
108
Basis Path
Testing1
Next, we derive the
independent paths:
2 Since V(G) = 4,
there are four
paths
3 Path 1: 1,2,3,6,7,8
4
5 6
Path 2: 1,2,3,5,7,8
Path 3: 1,2,4,7,8
Path 4: 1,2,4,7,2,4,...7,8
Finally, we derive test
7 cases to exercise these
paths.
109
Basis Path Testing
Notes you don't need a flow chart,
but the picture will help when
you trace program paths
110
Deriving Test Cases
■ Summarizing:
◻ Using the design or code as a foundation,
draw a corresponding flow graph.
◻ Determine the cyclomatic complexity of the
resultant flow graph.
◻ Determine a basis set of linearly independent
paths.
◻ Prepare test cases that will force execution of
each path in the basis set.
111
Graph Matrices
■ A graph matrix is a square matrix whose size (i.e.,
number of rows and columns) is equal to the number of
nodes on a flow graph
■ Each row and column corresponds to an identified
node, and matrix entries correspond to connections (an
edge) between nodes.
■ By adding a link weight to each matrix entry, the graph
matrix can become a powerful tool for evaluating
program control structure during testing
112
Graph Matrix
113
Connection Matrix
114
Control Structure Testing
■ Condition testing — a test case design
method that exercises the logical
conditions contained in a program module
■ Data flow testing — selects test paths of a
program according to the locations of
definitions and uses of variables in the
program
115
Data Flow Testing
■ The data flow testing method [Fra93] selects test paths of a program
according to the locations of definitions and uses of variables in the
program.
◻ Assume that each statement in a program is assigned a unique
statement number and that each function does not modify its
parameters or global variables. For a statement with S as its statement
number
■ DEF(S) = {X | statement S contains a definition of X}
■ USE(S) = {X | statement S contains a use of X}
◻ A definition-use (DU) chain of variable X is of the form [X, S, S'], where S
and S' are statement numbers, X is in DEF(S) and USE(S'), and the
definition of X in statement S is live at statement S'
116
Loop Testing
Simple
loop
Nested
Loops
Concatenated
Loops Unstructured
Loops
117
Loop Testing: Simple
Loops
Minimum conditions—Simple Loops
118
Loop Testing: Nested Loops
Nested Loops
Start at the innermost loop. Set all outer loops to their
minimum iteration parameter values.
Test the min+1, typical, max-1 and max for the
innermost loop, while holding the outer loops at their
minimum values.
Move out one loop and set it up as in step 2, holding all
other loops at typical values. Continue this step until
the outermost loop has been
tested.
Concatenated
Loops
If the loops are independent of one another
then treat each as a simple
else* treat as nested
loop
endif*
loops
for example, the final loop counter value of loop 1 is
used to initialize loop 2.
119
Black-Box Testing
requirements
output
input events
120
Black-Box Testing
■ How is functional validity tested?
■ How is system behavior and performance tested?
■ What classes of input will make good test cases?
■ Is the system particularly sensitive to certain input
values?
■ How are the boundaries of a data class isolated?
■ What data rates and data volume can the system
tolerate?
■ What effect will specific combinations of data have on
system operation?
121
Graph-Based Methods
To understand the
objects that are
modeled in
software and the
relationships that
connect these
objects
In this context, we
consider the term
“objects” in the broadest
possible context. It
encompasses data
objects, traditional
components (modules),
and object-oriented
elements of computer
software.
122
Equivalence Partitioning
user output FK
queries formats input
mouse
picks dat
prompts a
123
Sample Equivalence
ClassesValid data
user supplied commands
responses to system prompts
file names
computational
data
physical parameters
bounding values
initiation values
output data
responses to error messages
formatting
graphical data (e.g., mouse picks)
Invalid
datadata outside bounds of the program
physically impossible data
proper value supplied in wrong place
124
Boundary Value Analysis
user output FK
queries formats input
mouse
picks dat
prompts a
output
input domain domain
125
Model-Based Testing
■ Analyze an existing behavioral model for the software or create one.
◻ Recall that a behavioral model indicates how software will respond to
external events or stimuli.
■ Traverse the behavioral model and specify the inputs that will force
the software to make the transition from state to state.
◻ The inputs will trigger events that will cause the transition to occur.
■ Review the behavioral model and note the expected outputs as the
software makes the transition from state to state.
■ Execute the test cases.
■ Compare actual and expected results and take corrective action as
required.
126
THANK YOU