St-Module 2-Note1
St-Module 2-Note1
1|Page
Module2 white box testing
Advantages
• Testing can be commenced at an earlier stage. One need not wait for the
GUI to be available.
• Testing is more thorough, with the possibility of covering most paths.
• Reveals errors in "hidden" code.
• Spots the Dead Code or other issues with respect to best programming
practices.
• Disadvantages of White Box Testing:
Disadvantages
• Expensive as one has to spend both time and money to perform white box
testing.
• Every possibility that few lines of code are missed accidentally.
• In-depth knowledge about the programming language is necessary to
perform white box testing.
What do you verify in White Box Testing?
• White box testing involves the testing of the software code for the
following:
• Internal security holes
• Broken or poorly structured paths in the coding processes
• The flow of specific inputs through the code
• Expected output
• The functionality of conditional loops
• Testing of each statement, object, and function on an individual basis
• The testing can be done at system, integration and unit levels of software
development.
• One of the basic goals of white box testing is to verify a working flow for
an application.
2|Page
Module2 white box testing
3|Page
Module2 white box testing
• The goal of White Box testing in software engineering is to verify all the
decision branches, loops, statements in the code.
• To exercise the statements in the above code, White Box test cases would
be
A = 1, B = 1
A = -1, B = -3
4|Page
Module2 white box testing
STATIC TESTING
• Static testing is a type of testing which requires only the source code of the
product, not the binaries or executables.
• Static testing does not involve white box testing executing the programs on
computers but involves select people going through the code to find out
whether:
o The code works according to the functional requirement;
o The code has been written in accordance with the design developed
earlier in the project life cycle;
o The code for any functionality has been missed out;
o the code handles errors properly.
• Static testing can be done by humans or with the help of specialized tools.
Static Testing by Humans
• These methods rely on the principle of humans reading the program code
to detect errors rather than computers executing the code to find errors.
5|Page
Module2 white box testing
6|Page
Module2 white box testing
7|Page
Module2 white box testing
Code Walkthrough
• This method is a group-oriented methods.
• Walkthroughs are less formal than inspections.
• The line drawn in formalism between walkthroughs and inspections is very
thin and varies from organization to organization.
• The advantage that walkthrough has over desk checking is that it brings
multiple perspectives.
• In walkthroughs, a set of people look at the program code and raise
questions for the author.
• The author explains the logic of the code, and answers the questions.
• If the author is unable to answer some questions, he or she then takes those
questions and finds their answers.
8|Page
Module2 white box testing
• Completeness is limited to the area where questions are raised by the team.
Formal Inspection
• Code inspection-also called Fagan Inspection is a method, normally with a
high degree of formalism.
• The focus of this method is to detect all faults, violations, and other side-
effects.
• This method increases the number of defects detected by
o 1. demanding thorough preparation before an inspection/review;
o 2. enlisting multiple diverse views;
o 3. assigning specific roles to the multiple participants;
o 4. going sequentially through the code in a structured manner.
• A formal inspection should take place only when the author has made sure
the code is ready for inspection by performing some basic desk checking
and walkthroughs.
• When the code is in such a reasonable state of readiness, Software Testing
an inspection meeting is arranged.
There are four roles in inspection
1. First is the author of the code.
2. Second is a moderator who is expected to formally run the inspection
according to the process.
3. Third are the inspectors.
• These are the people who actually provides, review comments for the code.
• There are typically multiple inspectors. Finally, there is a scribe, who takes
detailed notes during the inspection meeting and circulates them to the
inspection team after the meeting.
Working of Formal Inspection
The author or the moderator selects the review team. The chosen members
have the skill sets to uncover as many defects as possible. In an
introductory meeting, the inspectors get copies (These can be hard copies
or soft copies) of the code to be inspected along with other supporting
9|Page
Module2 white box testing
10 | P a g e
Module2 white box testing
11 | P a g e
Module2 white box testing
12 | P a g e
Module2 white box testing
13 | P a g e
Module2 white box testing
14 | P a g e
Module2 white box testing
STRUCTURAL TESTING
■ Structural testing takes into account the code, code structure, internal
design, and how they are coded.
■ The fundamental difference between structural testing and static testing is
that :
■ In structural testing tests are actually run by the computer on the built
product,
■ Whereas in static testing, the product is tested by humans using just the
source code and not the executables or binaries.
■ Structural testing entails running the actual product against some
predesigned test cases to exercise as much of the code as possible or
necessary.
15 | P a g e
Module2 white box testing
■ A given portion of the code is exercised if a test case causes the program
to execute that portion of the code when running the test
Classification Of Structural Testing
Structural testing can be further classified into :
1. Unit/code functional testing.
2. Code coverage.
3. Code complexity testing.
Unit/Code Functional Testing
■ This initial part of structural testing corresponds to some quick checks that
a developer performs before subjecting the code to more extensive code
coverage testing or code complexity testing.
This can happen by several methods:
■ 1. Initially, the developer can perform certain obvious tests, knowing the
input variables and the corresponding expected output variables. This can
be a quick test that checks out any obvious mistakes. By repeating these
tests for multiple values of input variables, the confidence level of the
developer to go to the next level increases. This can even be done prior to
formal reviews of static testing so that the review mechanism does not
waste time catching obvious errors.
■ 2. For modules with complex logic or conditions, the developer can build
a “ debug version" of the product by putting intermediate print statements
and making sure the program is passing through the right loops and
iterations the right number of times. It is important to remove the
intermediate print statements after the defects are fixed.
■ 3. Another approach to do the initial test is to run the product under a
debugger or an integrated development environment (ide).These tools
allow single stepping of instructions (allowing the developer to stop at the
end of each instruction, view or modify the contents of variables, and so
on), Setting break points at any function or instruction, and viewing the
various system parameters or program variable values.
16 | P a g e
Module2 white box testing
All the above fall more under the "debugging" category of activities than
under the "testing" category of activities. All the same, these are intimately
related to the knowledge of code structure and hence we have included
these under the "white box testing" head. This is consistent with our view
that testing encompasses whatever it takes to detect and correct defects in
a product.
17 | P a g e
Module2 white box testing
Statement coverage
■ Statement coverage Program constructs in most conventional
programming languages can be classified as :
1. Sequential control flow
2. Two-way decision statements like IF then ELSE
3. Multi-way decision statements like Switch
4. Loops like while do, repeat ,until and for
■ Statement coverage refers to writing test cases that execute each of the
program statements.
■ One can start with the assumption that more the code covered, the better
is the testing of the functionality, as the code realizes the functionality.
■ Based on this assumption, code coverage can be achieved by providing
coverage to each of the above types of statements.
Sequential Control Flow
■ For a section of code that consists of statements that are sequentially
executed
■ (that is, with no conditional branches), test cases can be designed to run
through from top to bottom.
■ A test case that starts at the top would generally have to go through the
full section till the bottom of the section.
■ However, this may not always be true.
■ First, if there are asynchronous exceptions that the code encounters (for
example, a divide by zero),
■ then, even if we start a test case at the beginning of a section, the test case
may not cover all the statements in that section.
■ Thus, even in the case of sequential statements, coverage for all statements
may not be achieved.
■ Second, a section of code may be entered from multiple points.
18 | P a g e
Module2 white box testing
19 | P a g e
Module2 white box testing
3. Try covering the loop, around the "boundary" of n-that is, just
below n, n, and just above n.
■ The statement coverage for a program, which is an indication of the
percentage of statements actually executed in a set of tests, can be
calculated by the formula :
Statement coverages=(𝑇𝑜𝑡𝑎𝑙 𝑠𝑡𝑎𝑡𝑒𝑚𝑒𝑛𝑡 𝐸𝑥𝑒𝑟𝑐𝑖𝑠𝑒𝑑/𝑇𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓
𝑒𝑥𝑒𝑐𝑢𝑡𝑎𝑏𝑙𝑒 𝑠𝑡𝑎𝑡𝑒𝑚𝑒𝑛𝑡𝑠 𝑖𝑛 𝑝𝑟𝑜𝑔𝑟𝑎𝑚)∗100
Path coverage
■ In path coverage, we split a program into a number of Distinct paths.
■ A program (or a part of a program) can start from the beginning and take
any of the paths to its completion.
Path coverage =(Total paths Exercised/Total number of path in
program)*100
20 | P a g e
Module2 white box testing
Let us take an example of a date validation routine. The date is accepted as three
fields mm, dd and yyyy. We have assumed that prior to entering this routine, the
values are checked to be numeric. To simplify the discussion, we have assumed
the existence of a function called le a pye a r which will return TRUE if the given
year is a leap year. There is an array called Dayo (Month which contains the
number of days in each month. A simplified flow chart for this is given in Figure
3.2 below.
As can be seen from the figure, there are different paths that can be taken through
the program. Each part of the path is shown in red. The coloured representation
of Figure 3.2 is available on page 459. Some of the paths are
21 | P a g e
Module2 white box testing
Condition coverage
■ Condition coverage is also known as Predicate Coverage in which each one
of the Boolean expression have been evaluated to both TRUE and FALSE.
Result
■ In order to ensure complete Condition coverage criteria for the above
example, A, B and C should be evaluated at least once against "true" and
"false".
■ So, in our example, the 3 following tests would be sufficient for 100%
Condition coverage testing.
22 | P a g e
Module2 white box testing
Functional Testing
■ This is a new addiction in structure testing to identify how many program
functions are covered by test cases.
■ The requirements of a products are mapped into functions during the
design phase and each of the functions form a logical unit.
■ Functional testing ensures that the requirements or specifications are
properly satisfied by the application.
■ This type of testing is particularly concerned with the result of processing.
■ It focuses on simulation of actual system usage but does not develop any
system structure assumptions.
■ While providing function coverage test cases can be written so as to
exercise each of the different functions of the code.
Advantages of functional testing
■ Functions are easy to identify in a program hence it is easier to write test
cases to provide function coverage.
■ Since functions are at a much higher level of abstraction than code ,it is
easier to achieve 100 percent function coverage than 100 percent coverage
in any of the easier methods.
■ Functions have a more logical mapping to requirements and hence can
provide a more direct correlation to the test coverage of the product.
■ Function coverage provide a natural transition to black box testing.
■ We can also measure how many times a given function is called, This will
indicate which functions are used most often and hence these function
become the target of any performance testing and optimization.
■ The function coverage can help in improving the performance as well as
quality of the product.
■ Function coverage =(Total functions Exercised/Total number of
functions in program)*100
23 | P a g e
Module2 white box testing
Cyclomatic Complexity
■ Cyclomatic complexity is a software metric used to measure the
complexity of a program. Thomas J. McCabe developed this metric in
1976.
■ McCabe interprets a computer program as a set of a strongly connected
directed graph.
■ Nodes represent parts of the source code having no branches and arcs
represent possible control flow transfers during program execution.
■ The notion of program graph has been used for this measure, and it is used
to measure and control the number of paths through a program. The
complexity of a computer program can be correlated with the topological
complexity of a graph.
How to Calculate Cyclomatic Complexity ?
■ McCabe proposed the cyclomatic number, V (G) of graph theory as an
indicator of software complexity.
■ The cyclomatic number is equal to the number of linearly independent
paths through a program in its graphs representation.
■ For a program control graph G, cyclomatic number, V (G), is given as:
V (G) = E - N + 2 * P
E = The number of edges in graphs G
N = The number of nodes in graphs G
P = The number of connected components in graph G.
24 | P a g e
Module2 white box testing
25 | P a g e
Module2 white box testing
26 | P a g e