ST Unit I
ST Unit I
INTRODUCTION
What is testing?
Testing consumes at least half of the time and work required to produce a functional program.
O MYTH: Good programmers write code without bugs. (It’s wrong!!!)
O History says that even well written programs still have 1-3 bugs per hundred statements.
O
In production of consumer goods and other products, every manufacturing stage is
subjected to quality control and testing from component to final stage.
O
If flaws are discovered at any stage, the product is either discarded or cycled back for
rework and correction.
O Productivity is measured by the sum of the costs of the material, the rework, and the
discarded components, and the cost of quality assurance and testing.
O
There is a tradeoff between quality assurance costs and manufacturing costs: If
sufficient time is not spent in quality assurance, the reject rate will be high and so will
be the net cost. If inspection is good and all errors are caught as they occur, inspection
costs will dominate, and again the net cost will suffer.
O Testing and Quality assurance costs for 'manufactured' items can be as low as 2% in
consumer products or as high as 80% in products such as space-ships, nuclear reactors,
and aircrafts, where failures threaten life. Whereas the manufacturing cost of software is
trivial.
O The biggest part of software cost is the cost of bugs: the cost of detecting them, the cost
of correcting them, the cost of designing tests that discover them, and the cost of running
those tests.
O For software, quality and productivity are indistinguishable because the cost of a
software copy is trivial.
O Testing and Test Design are parts of quality assurance should also focus on bug
prevention. A prevented bug is better than a detected and corrected bug.
Phases in a tester's mental life:
Phases in a tester's mental life can be categorized into the following 5 phases:
1. Phase 0: (Until 1956: Debugging Oriented) There is no difference between testing and
debugging. Phase 0 thinking was the norm in early days of software development till testing
emerged as a discipline.
2. Phase 1: (1957-1978: Demonstration Oriented) the purpose of testing here is to show that
software works. Highlighted during the late 1970s. This failed because the probability of
showing that software works 'decreases' as testing increases. I.e. the more you test, the more
likely you will find a bug.
3. Phase 2: (1979-1982: Destruction Oriented) the purpose of testing is to show that
software doesn’t work. This also failed because the software will never get released as
you will find one bug or the other. Also, a bug corrected may also lead to another bug.
4. Phase 3: (1983-1987: Evaluation Oriented) the purpose of testing is not to prove anything
but to reduce the perceived risk of not working to an acceptable value (Statistical Quality
Control). Notion is that testing does improve the product to the extent that testing catches
bugs and to the extent that those bugs are fixed. The product is released when the
confidence on that product is high enough. (Note: This is applied to large software products
with millions of code and years of use.)
5. Phase 4: (1988-2000: Prevention Oriented) Testability is the factor considered here. One
reason is to reduce the labor of testing. Other reason is to check the testable and non-testable
code. Testable code has fewer bugs than the code that's hard to test. Identifying the testing
techniques to test the code is the main key here.
Test Design:
We know that the software code must be designed and tested, but many appear to be unaware
that tests themselves must be designed and tested. Tests should be properly designed and tested
before applying it to the actual code.
There are approaches other than testing to create better software. Methods other than testing
include:
1. Inspection Methods: Methods like walkthroughs, desk checking, formal inspections and
code reading appear to be as effective as testing but the bugs caught don’t completely
overlap.
2. Design Style: While designing the software itself, adopting stylistic objectives such as
testability, openness and clarity can do much to prevent bugs.
3. Static Analysis Methods: Includes formal analysis of source code during compilation. In
earlier days, it is a routine job of the programmer to do that. Now, the compilers have
taken over that job.
4. Languages: The source language can help reduce certain kinds of bugs. Programmers
find new bugs while using new languages.
5. Development Methodologies and Development Environment: The development
process and the environment in which that methodology is embedded can prevent many
kinds of bugs.
Dichotomies:
Testing Debugging
Testing starts with known conditions, Debugging starts from possibly unknown
uses predefined procedures and has initial conditions and the end cannot be
predictable outcomes. predicted except statistically.
Testing can and should be planned, Procedure and duration of debugging cannot
designed and scheduled. be so constrained.
Testing is a demonstration of error or
Debugging is a deductive process.
apparent correctness.
Debugging is the programmer's vindication
Testing proves a programmer's failure.
(Justification).
Testing, as executes, should strive to be Debugging demands intuitive leaps,
predictable, dull, constrained, rigid and experimentation and freedom.
inhuman.
Much testing can be done without Debugging is impossible without detailed
design knowledge. design knowledge.
Testing can often be done by an
Debugging must be done by an insider.
outsider.
Much of test execution and design can
Automated debugging is still a dream.
be automated.
o Test designer is the person who designs the tests where as the tester is the one
actually tests the code. During functional testing, the designer and tester are
probably different persons. During unit testing, the tester and the programmer
merge into one person.
o Tests designed and executed by the software designers are by nature biased
towards structural consideration and therefore suffer the limitations of structural
testing.
CONSEQUENCES OF BUGS:
• Dynamic data are transitory. Whatever their purpose their lifetime is relatively short,
typically the processing time of one transaction. A storage object may be used to hold
dynamic data of different types, with different formats, attributes and residues.
• Dynamic data bugs are due to leftover garbage in a shared resource. This can be handled
in one of the three ways: (1) Clean up after the use by the user (2) Common Cleanup by
the resource manager (3) No Clean up
• Static Data are fixed in form and content. They appear in the source code or database
directly or indirectly, for example a number, a string of characters, or a bit pattern.
• Compile time processing will solve the bugs caused by static data.
1. External Interfaces:
• The external interfaces are the means used to communicate with the world.
• These include devices, actuators, sensors, input terminals, printers, and communication
lines.
• The primary design criterion for an interface with outside world should be robustness.
• All external interfaces, human or machine should employ a protocol. The protocol may
be wrong or incorrectly implemented.
• Other external interface bugs are: invalid timing or sequence assumptions related to
external signals
• Misunderstanding external input or output formats.
• Insufficient tolerance to bad input data.
2. Internal Interfaces:
• Internal interfaces are in principle not different from external interfaces but they are more
controlled.
• A best example for internal interfaces is communicating routines.
• The external environment is fixed and the system must adapt to it but the internal
environment, which consists of interfaces with other components, can be negotiated.
• Internal interfaces have the same problem as external interfaces.
3. Hardware Architecture:
• Bugs related to hardware architecture originate mostly from misunderstanding how the
hardware works.
• Examples of hardware architecture bugs: address generation error, i/o device operation /
instruction error, waiting too long for a response, incorrect interrupt handling etc.
• The remedy for hardware architecture and interface problems is twofold: (1) Good
Programming and Testing (2) Centralization of hardware interface software in programs
written by hardware interface specialists.
4. Operating System Bugs:
• Program bugs related to the operating system are a combination of hardware architecture
and interface bugs mostly caused by a misunderstanding of what it is the operating
system does.
• Use operating system interface specialists, and use explicit interface modules or macros
for all operating system calls.
• This approach may not eliminate the bugs but at least will localize them and make testing
easier.
5. Software Architecture:
• Software architecture bugs are the kind that called - interactive.
• Routines can pass unit and integration testing without revealing such bugs.
• Many of them depend on load, and their symptoms emerge only when the system is
stressed.
• Sample for such bugs: Assumption that there will be no interrupts, Failure to block or un
block interrupts, Assumption that memory and registers were initialized or not initialized
etc
• Careful integration of modules and subjecting the final system to a stress test are effective
methods for these bugs.
• Path Testing:
O Path Testing is the name given to a family of test techniques based on
judiciously selecting a set of test paths through the program.
O If the set of paths are properly chosen then we have achieved some measure
of test thoroughness. For example, pick enough paths to assure that every
source statement has been executed at least once.
O Path testing techniques are the oldest of all structural test techniques.
O Path testing is most applicable to new software for unit testing. It is a
structural technique.
O It requires complete knowledge of the program's structure.
O It is most often used by programmers to unit test their own code.
O The effectiveness of path testing rapidly deteriorates as the size of the
software aggregate under test increases.
Flowcharts can be
1. Handwritten by the programmer.
2. Automatically produced by a flowcharting program based on a mechanical analysis
of the source code.
3. Semi automatically produced by a flow charting program based in part on structural
analysis of the source code and in part on directions given by the programmer.
There are relatively few control flow graph generators.
There are many paths between the entry and exit of a typical routine.
Every decision doubles the number of potential paths. And every loop multiplies the number of
potential paths by the number of different iteration values possible for the loop. Defining
complete testing:
1. Exercise every path from entry to exit.
2. Exercise every statement or instruction at least once.
3. Exercise every branch and case statement, in each direction at least once.
If prescription 1 is followed then 2 and 3 are automatically followed. But it is impractical for
most routines. It can be done for the routines that have no loops, in which it is equivalent to
2 and 3 prescriptions.
EXAMPLE: Here is the correct version.
For X negative, the output is X + A, while for X greater than or equal to zero, the output is X
+ 2A. Following prescription 2 and executing every statement, but not every branch, would
not reveal the bug in the following incorrect version:
A negative value produces the correct answer. Every statement can be executed, but if the test
cases do not force each branch to be taken, the bug can remain hidden. The next example uses a
test based on executing each branch but does not force the execution of all statements:
The hidden loop around label 100 is not revealed by tests based on prescription 3 alone because
no test forces the execution of statement 100 and the following GOTO statement. Furthermore,
label 100 is not flagged by the compiler as an unreferenced label and the subsequent GOTO does
not refer to an undefined label.
A Static Analysis (that is, an analysis based on examining the source code or structure) cannot
determine whether a piece of code is or is not reachable. There could be subroutine calls with
parameters that are subroutine labels, or in the above example there could be a GOTO that
targeted label 100 but could never achieve a value that would send the program to that label.
Only a Dynamic Analysis (that is, an analysis based on the code's behavior while running -
which is to say, to all intents and purposes, testing) can determine whether code is reachable or
not and therefore distinguish between the ideal structure we think we have and the actual, buggy
structure.
Any testing strategy based on paths must at least both exercise every instruction and take
branches in all directions.
A set of tests that does this is not complete in an absolute sense, but it is complete in the sense
that anything less must leave something untested.
So we have explored three different testing criteria or strategies out of a potentially infinite
family of strategies.
LOOPS:
Cases for a single loop: A Single loop can be covered with two cases: Looping and Not
looping. But, experience shows that many loop-related bugs are not discovered by C1+C2. Bugs
hide themselves in corners and congregate at boundaries - in the cases of loops, at or around the
minimum or maximum number of times the loop can be iterated. The minimum number of
iterations is often zero, but it need not be.
8. Attempt one more than the maximum number of iterations. What prevents the loop-control
variable from having this value? What will happen with this value if it is forced?
CASE 2: Single loop, Non-zero minimum, No excluded values
1. Try one less than the expected minimum. What happens if the loop control variable's value is
less than the minimum? What prevents the value from being less than the minimum?
2. The minimum number of iterations.
3. One more than the minimum number of iterations.
4. Once, unless covered by a previous test.
5. Twice, unless covered by a previous test.
6. A typical value.
7. One less than the maximum value.
8. The maximum number of iterations.
9. Attempt one more than the maximum number of iterations.
Kinds of Loops: There are only three kinds of loops with respect to path testing:
Nested Loops:
The number of tests to be performed on nested loops will be the exponent of the tests
performed on single loops.As we cannot always afford to test all combinations of nested
loops' iterations values. Here's a tactic used to discard some of these values:
1. Start at the inner most loop. Set all the outer loops to their minimum values.
2. Test the minimum, minimum+1, typical, maximum-1 , and maximum for the innermost
loop, while holding the outer loops at their minimum iteration parameter values. Expand
the tests as required for out of range and excluded values.
3. If you've done the outmost loop, GOTO step 5, else move out one loop and set it up as in
step 2 with all other loops set to typical values.
4. Continue outward in this manner until all loops have been covered.
5. Do all the cases for all loops in the nest simultaneously.
Concatenated Loops:
Concatenated loops fall between single and nested loops with respect to test cases. Two
loops are concatenated if it's possible to reach one after exiting the other while still on a
path from entrance to exit.
If the loops cannot be on the same path, then they are not concatenated and can be treated
as individual loops.
▪ Horrible Loops:
A horrible loop is a combination of nested loops, the use of code that jumps into and out of
loops, intersecting loops, hidden loops, and cross connected loops.
Makes iteration value selection for test cases an awesome and ugly task, which is another
reason such structures should be avoided.
Weak approach doesn’t concentrate on interfaces and paths called components, which are major aspects of
interfacing testing.
Suppose we have a program with multi entry routine with 4 entrances such that all the entrances have certain
restrictions for inputs.
Unit testing alone is not sufficient in this case. Integration testing focuses on interfaces and restrictions on inputs
so we have tests for first entry i.e., one for A and other for B.
Consider one more program which has 3 exits which can be used by outputs A and B such that, exit 1 allows only
output A exit 2 allows only output B and exit 3 allows outputs A & B.
Component testing should assure that exit 1 and exit 3 allows output A, exit 2 and exit 3 allows output B and also
assure that exit1 and exit 2 must not allow output B and A respectively.
3. Theory and Tools Issue:
A well formed software is a software which has single entry and single exit with a rigid structure.
An assumptions that multi entry and multi exit routines cant occur in testing theory has been followed. Such multi
entry and multi exit routines comes under ill formed routines. Before applying the theoretical rules, it is better to
confirm whether the software is well formed or ill formed.
Ill formed software doesn’t have any structure so testing of one component doesn’t guarantee the tests results for
another. Even test generators may not be able to generate test cases for ill formed software.
4. Strategy Summary:
In these routines, there is no direct connection between entry and exit. The control flow is managed by reviewing
parameters values of entry/ exit points. The main draw back of this routine is control flow are not easily
determined which leads to test coverage problem.
1. Avoid multi entry/exit routines as much as possible, because it is difficult to cover all the test cases for these
routines.
2. if it is mandatory for you to use multi entry/exit routines try to achieve maximum control over these routines.
3. supply the imaginary input case statements and exit parameters to control flow graph in order to design test
cases for these routines.
4. each and every entry/exit pair is considered as a separate routine, which is tested individually using powerful
unit testing mechanism.
5. you have to assure yourself, that test cases designed based on your assumption are suitable for multi entry/exit
routine.
Effectiveness and limitations: Unit testing is comparatively stronger than path testing which inturn is stronger than
statement and branch testing. Path testing captures about 50% of bugs which the unit testing captures. Unit testing
can catch up to 65% of bugs of overall structures, this implies that path testing captures approximately 35% bugs
in the overall structure as per statistical reports.
1. path testing has to be combined with other methods to improve the over all performance in terms of percentage.
2. all the paths may not be covered if there is a bug.
3. it is very difficult to catch all the bugs that are covered during the process of initialization.
4. path testing doesn’t deal with specification errors.
5. unit level path testing doesn’t concentrate on integration issues which may result in interface errors.
6. missed functions cannot be identified during path testing.
7. even if all the tests during unit level are cleared by routine, path testing cannot assure of its reliability because
one routine may intervene the other routines.
PREDICATES, PATH PREDICATES AND ACHIEVABLE PATHS:
PREDICATE: The logical function evaluated at a decision is called Predicate. The direction
taken at a decision depends on the value of decision variable. Some examples are: A>0,
x+y>=90.......
PATH PREDICATE: A predicate associated with a path is called a Path Predicate. For
example, "x is greater than zero", "x+y>=90", "w is either negative or equal to 10 is true" is a
sequence of predicates whose truth values will cause the routine to take a specific path.
MULTIWAY BRANCHES:
The path taken through a multiway branch such as a computed GOTO's, case statement, or
jump tables cannot be directly expressed in TRUE/FALSE terms.
Although, it is possible to describe such alternatives by using multi valued logic, an
expedient (practical approach) is to express multiway branches as an equivalent set of
if..then..else statements.
For example a three way case statement can be written as: If case=1 DO A1 ELSE (IF
Case=2 DO A2 ELSE DO A3 ENDIF)ENDIF.
INPUTS:
In testing, the word input is not restricted to direct inputs, such as variables in a subroutine
call, but includes all data objects referenced by the routine whose values are fixed prior to
entering it.
For example, inputs in a calling sequence, objects in a data structure, values left in registers,
or any combination of object types.
The input for a particular test is mapped as a one dimensional array called as an Input
Vector.
PREDICATE INTERPRETATION:
The simplest predicate depends only on input variables.
For example if x1,x2 are inputs, the predicate might be x1+x2>=7, given the values of x1
and x2 the direction taken through the decision is based on the predicate is determined at
input time and does not depend on processing.
Another example, assume a predicate x1+y>=0 that along a path prior to reaching this
predicate we had the assignment statement y=x2+7. although our predicate depends on
processing, we can substitute the symbolic expression for y to obtain an equivalent predicate
x1+x2+7>=0.
The act of symbolic substitution of operations along the path in order to express the
predicate solely in terms of the input vector is called predicate interpretation.
Sometimes the interpretation may depend on the path; for
example, INPUT X
ON X GOTO A, B, C, ...
A: Z := 7 @ GOTO HEM
B: Z := -7 @ GOTO HEM
C: Z := 0 @ GOTO HEM
.........
HEM: DO SOMETHING
.........
HEN: IF Y + Z > 0 GOTO ELL ELSE GOTO EMM
The predicate interpretation at HEN depends on the path we took through the first multiway
branch. It yields for the three cases respectively, if Y+7>0, Y-7>0, Y>0.
The path predicates are the specific form of the predicates of the decisions along the
selected path after interpretation.
INDEPENDENCE OF VARIABLES AND PREDICATES:
The path predicates take on truth values based on the values of input variables, either
directly or indirectly.
If a variable's value does not change as a result of processing, that variable is independent
of the processing.
If the variable's value can change as a result of the processing, the variable is process
dependent.
A predicate whose truth value can change as a result of the processing is said to be process
dependent and one whose truth value does not change as a result of the processing is
process independent.
Process dependence of a predicate does not always follow from dependence of the input
variables on which that predicate is based.
Any set of input values that satisfy all of the conditions of the path predicate expression will
force the routine to the path.
Sometimes a predicate can have an OR in it.
Example:
A: X5 > 0 E: X6 < 0
B: X1 + 3X2 + 17 B: X1 + 3X2 + 17
>= 0 >= 0
C: X3 = 17 C: X3 = 17
D: X4 - X1 >= D: X4 - X1 >=
14X2 14X2
Boolean algebra notation to denote the boolean expression:
ABCD+EBCD=(A+E)BCD
PREDICATE COVERAGE:
Compound Predicate: Predicates of the form A OR B, A AND B and more complicated
Boolean expressions are called as compound predicates.
Sometimes even a simple predicate becomes compound after interpretation. Example: the
predicate if (x=17) whose opposite branch is if x.NE.17 which is equivalent to x>17. Or.
X<17.
Predicate coverage is being the achieving of all possible combinations of truth values
corresponding to the selected path have been explored under some test.
As achieving the desired direction at a given decision could still hide bugs in the
associated predicates
TESTING BLINDNESS:
Testing Blindness is a pathological (harmful) situation in which the desired path is
achieved for the wrong reason.
There are three types of Testing Blindness:
• Assignment Blindness:
O Assignment blindness occurs when the buggy predicate appears to work correctly
because the specific value chosen for an assignment statement works with both the
correct and incorrect predicate.
O For Example:
Correct Buggy
X = 7 X = 7
........ ........
if Y > 0 if X+Y > 0
then ... then ...
O If the test case sets Y=1 the desired path is taken in either case, but there is still a bug.
Equality Blindness:
O Equality blindness occurs when the path selected by a prior predicate results in a value
that works both for the correct and buggy predicate.
O For Example:
Correct Buggy
if Y = 2 then if Y = 2 then
........ ........
if X+Y > 3 if X > 1
then ... then ...
O The first predicate if y=2 forces the rest of the path, so that for any positive value of x.
the path taken at the second predicate will be the same for the correct and buggy version.
Self Blindness:
O Self blindness occurs when the buggy predicate is a multiple of the correct predicate and
as a result is indistinguishable along that path.
O For Example:
Correct Buggy
X=A X=A
........ ........
if X-1 > 0 if X+A-2 > 0
then ... then ...
1. The assignment (x=a) makes the predicates multiples of each other, so the direction taken is
the same for the correct and buggy version.
PATH SENSITIZING:
1. This is a workable approach, instead of selecting the paths without considering how to
sensitize, attempt to choose a covering path set that is easy to sensitize and pick hard to
sensitize paths only as you must to achieve coverage.
2. Identify all variables that affect the decision.
3. Classify the predicates as dependent or independent.
4. Start the path selection with un correlated, independent predicates.
5. If coverage has not been achieved using independent uncorrelated predicates, extend
the path set using correlated predicates.
6. If coverage has not been achieved extend the cases to those that involve dependent
predicates.
7. Last, use correlated, dependent predicates.
PATH INSTRUMENTATION:
1. Path instrumentation is what we have to do to confirm that the outcome was achieved by
the intended path.
2. Co-incidental Correctness: The coincidental correctness stands for achieving the
desired outcome for wrong reason.
Path Instrumentation is what we have to do to confirm that the outcome was achieved by
the intended path.
The types of instrumentation methods include:
1. Interpretive Trace Program:
O An interpretive trace program is one that executes every statement in order and records the
intermediate values of all calculations, the statement labels traversed etc.
O If we run the tested routine under a trace, then we have all the information we need to
confirm the outcome and, furthermore, to confirm that it was achieved by the intended
path.
O The trouble with traces is that they give us far more information than we need. In fact,
the typical trace program provides so much information that confirming the path from
its massive output dump is more work than simulating the computer by hand to confirm
the path.
2. Traversal Marker or Link Marker:
O A simple and effective form of instrumentation is called a traversal marker or link marker.
O Name every link by a lower case letter.
O Instrument the links so that the link's name is recorded when the link is executed.
O The succession of letters produced in going from the routine's entry to its exit should,
if there are no bugs, exactly correspond to the path name.
O Why Single Link Markers aren't enough: Unfortunately, a single link marker may not
do the trick because links can be chewed by open bugs.
We intended to traverse the ikm path, but because of a rampaging GOTO in the middle of
the m link, we go to process B. If coincidental correctness is against us, the outcomes will
be the same and we won't know about the bug.
Two Link Marker Method:
The solution to the problem of single link marker method is to implement two markers
per link: one at the beginning of each link and on at the end.
The two link markers now specify the path name and confirm both the beginning and end
of the link.
Link Counter: A less disruptive (and less informative) instrumentation method is based on
counters. Instead of a unique link name to be pushed into a string when the link is
traversed, we simply incremnt a link counter. We now confirm that the path length is as
expected. The same problem that led us to double link markers also leads us to double link
counters.