Department of Computing Adama Science and Technology University
Department of Computing Adama Science and Technology University
Department of Computing Adama Science and Technology University
3
Specification Based Testing
Input
determined Result
by... Actual output
compared
… requirements* Black box with
required
* from previous phase
Black, Gray and White-box Testing
Result
Input determined by... Actual output
compared
… requirements Black box or with
Glass-box required output
White box
Confirmation
…design of expected
elements behavior
Characteristics of Testable Software
Operable
– The better it works (i.e., better quality), the easier it is to test
Observable
– Incorrect output is easily identified; internal errors are automatically detected
Controllable
– The states and variables of the software can be controlled directly by the tester
Decomposable
The software is built from independent modules that can be tested independently
Simple
– The program should exhibit functional, structural, and code simplicity
Stable
– Changes to the software during testing are infrequent and do not invalidate
existing tests
Understandable
– The architectural design is well understood; documentation is available and
organized
6
Test Characteristics
7
Black box Testing
In a black box, the test item is
treated as "black" whose logic
is Unknown.
All that's known is what goes in
and what comes out, the input
and output
Focuses on the functional
requirements specifications of
the software.
Ex:
Unit,integration,system,acceptanc
e testing etc…
Also called behavioral testing
Black-box Testing
Test cases are designed using only functional specification of the
software:
– without any knowledge of the internal structure of the software.
Unlike white-box testing, here we don’t use any knowledge about the internals of
the code
Used during the later stages of testing after white box testing has been performed
The tester identifies a set of input conditions that will fully exercise all functional
requirements for a program
10
Questions answered by Black-box Testing
How is functional validity tested?
What data rates and data volume can the system tolerate?
11
Black box Testing Techniques
Boundary Value Testing
Equivalence class Testing
Error Guessing
Decision Table based Testing
Combinatorial Testing
Grammar Based Testing
Module Base Testing
Orthogonal matrix
Equivalence Partitioning
A black-box testing method that divides the input domain of a
program into classes of data from which test cases are derived.
From each equivalence class, test cases are selected so that the
largest number of attributes of an equivalence class are exercise at
once
13
Equivalence Partitioning
Equivalence testing is a black-box testing method that divides the space of all possible
inputs into equivalence groups such that the program “behaves the same” on each
group
Two steps:
1. Partitioning the values of input parameters into equivalence groups
If an input condition requires a specific value, one valid and two invalid
equivalence classes are defined
– Input value: 250 Eq classes: {250}, {x < 250}, {x > 250}
If an input condition is a Boolean value, one valid and one invalid class
are define
– Input: {true condition} Eq classes: {true condition}, {false
condition}
15
Equivalence Partitioning
Basic idea: consider input/output domains and partition them into equiv. classes
– For different values from the same class, the software should behave
equivalently
Input x in a certain range [a..b]: this defines three classes “x<a”, “a<=x<=b”,
“b<x”
16
Example: Searching
Search for a value in an array
– Return value is the index of some occurrence of the
value, or -1 if the value does not occur in the array
17
Example: Searching
Another partition: location of the value
– Four classes: “first element”, “last element”, “middle element”, “not
found”
Array Value Output
Empty 5 -1
[7] 7 0
[7] 2 -1
[1,6,4,7,2] 1 0
[1,6,4,7,2] 4 2
[1,6,4,7,2] 2 4
[1,6,4,7,2] 3 -1
18
Boundary Value Analysis
19
Boundary Value Analysis
Boundary Value Analysis (BVA) technique is a test case design technique that
system.
Human brain is evolved in emotional side and less evolved in logical side.
domain.
BVA based test case design helps to write test cases that exercise
Boundary Value Analysis
boundaries...”
---
The test cases developed based on equivalence class partitioning can be strengthened
Boris Beizer
by use of a technique called boundary value analysis.
Many defects occur directly on, and above and below, the edges of
equivalence classes.
cases for possibilities just above and below the ends of the range.
For example if a specification states that an input value for a module must lie
Valid tests that include values -1.0, +1.0 for ends of the range, as well as
Invalid test cases for values just above and below the ends -1.1, +1.1, should
be included.
Boundary Value Analysis
If an input condition for the software-under-test is specified as a
number of values, develop valid test cases for the minimum and
maximum numbers as well as invalid test cases that include one lesser
For example, for the real-estate module, a house can have four owners,
Valid Tests that includes tests for minimum and maximum values 1, 4
owners
Boundary Value Analysis
If the input or output of the software-under-test is an ordered set, such as a
table or a linear list, develop tests that focus on the first and last elements of
the set
Boundary Value Analysis
Using BVA- Range
Value - precision)
Minimum Value
“In the examination grading system, if the student scores 0 to less than 40 then
the student scores between 50 to 69 then assign C Grade, if the student scores
between 70 to 84 then assign B Grade, and if the student scores 85 to 100 then
assign A Grade.”
Values:
0 to 39 -E
40 to 49-D
BVA-An Illustration
Based on BVA, we identify following input values to test each boundary: For
Precision is 1.
Thus, input values for testing for this boundary values are: (Minimum Value-
Thus, input values for Boundary Values 0 and 39 are: -1, 0, 1, 38, 39, 40.
On the similar lines of analysis, we arrive at following input values for other
Boundary values:
Guidelines for Boundary Value Analysis
If an input condition specifies a range bounded by values a and b,
test cases should be designed with values a and b as well as values
just above and just below a and b
Example : When the bike stops, first thing you do is — check the
petrol.
30
Decision Tables - Usage
Decision tables make it easy to observe that all possible
conditions are accounted for.
31
Decision Tables - Structure
Conditions - (Condition stub) Condition Alternatives –
(Condition Entry)
Actions – (Action Stub) Action Entries
Condition2 X Yes X No
Condition3 Yes X No No
Condition4 No No Yes X
34
Black box testing
Advantages:
Large numbers of moderately skilled testers can test the application with no
performed.
Inefficient testing, due to the fact that the tester only has limited knowledge about
an application.
Blind coverage, since the tester cannot target specific code segments or error-
Black Box Testing
White-Box Testing
White-box testing: uses knowledge of the internal
structure of the software
E.g: write tests to “cover” internal paths
Note: white-box testing is also called structural testing/Glass
box/open box testing.
White-box testing Techniques:
Control-flow-based testing
Loop testing
Data-flow-based testing
Statement coverage
Path coverage
Branch testing
Unit Testing Tools/Frameworks:
Junit
TestNG
Control-flow-based Testing
38
Example of a Control Flow Graph (CFG)
1
s:=0;
d:=0; 2
while (x<y) {
x:=x+3; 3
y:=y+2;
if (x+y < 100) 4
s:=s+x+y; 5 6
else 7
d:=d+x-y;
} 8
39
Elements of a CFG
40
IF-THEN, IF-THEN-ELSE, SWITCH
…
… … …..
Example
switch (position)
case CASHIER
if (empl_yrs > 5)
bonus := 1; .
else .
bonus := 0.7; .
case MANAGER .
bonus := 1.5;
if (retiring_soon)
bonus := 1.2 * bonus
case …
end switch
42
Mapping for Loops
while (c) {
} …
43
Statement Coverage
Basic idea: given the control flow graph define a
“coverage target” and write test cases to achieve it.
44
Example
Suppose that we write and
execute two test cases 1
Test case #1: follows path 1-
2-exit (e.g., we never take the 2
loop)
Test case #2: 1-2-3-4-5-7-8- 3
2-3-4-5-7-8-2-exit (loop T 4 F
twice, and both times take the
true branch) 5 6
Do we have 100% statement 7
coverage?
8
45
Branch Coverage
46
Branch Coverage
Statement coverage does not imply branch
coverage
– Can you think of an example?
Motivation for branch coverage: experience
shows that many errors occur in “decision
making” (i.e., branching)
– Plus, it subsumes statement coverage.
47
Example
Same example as before
1
Test case #1: follows path 1-
2
2-exit
Test case #2: 1-2-3-4-5-7-8- 3
2-3-4-5-7-8-2-exit T 4 F
What is the branch 5 6
coverage? 7
48
Achieving Branch Coverage
For decades, branch coverage has been
considered a necessary testing minimum
To achieve it: pick a set of start-to-end paths
(in the CFG) that cover all branches, and then
write test cases to execute these paths
It can be proven that branch coverage can be
achieved with at most E-N+2 paths
49
White-Box Testing
Advantages:
As the tester has knowledge of the source code, it becomes very easy to find out
which type of data can help in testing the application effectively.
It helps in optimizing the code.
Extra lines of code can be removed which can bring in hidden defects.
Due to the tester's knowledge about the code, maximum coverage is attained
during test scenario writing.
Disadvantages:
Due to the fact that a skilled tester is needed to perform white box testing, the
costs are increased.
Sometimes it is impossible to look into every nook and corner to find out hidden
errors that may create problems as many paths will go untested.
It is difficult to maintain white box testing as the use of specialized tools like code
analyzers and debugging tools are required.
White Box Testing
Grey Box Testing
In software testing, the term “the more you know the better”
carries a lot of weight when testing an application.
Unlike black box testing, where the tester only tests the
application’s user interface, in grey box testing, the tester has
access to design documents and the database. Having this
knowledge, the tester is able to better prepare test data and test
scenarios when making the test plan.
Grey Box Testing
Advantages:
Offers combined benefits of black box and white box testing wherever possible.
Grey box testers don’t rely on the source code; instead they rely on interface
definition and functional specifications.
Based on the limited information available, a grey box tester can design
excellent test scenarios especially around communication protocols and data
type handling.
The test is done from the point of view of the user and not the designer.
Disadvantages:
Since the access to source code is not available, the ability to go over the code
and test coverage is limited.
The tests can be redundant if the software designer has already run a test case.
Testing every possible input stream is unrealistic because it would take an
unreasonable amount of time; therefore, many program paths will go untested.
Gray Box Testing
Black Box Testing Grey Box Testing White Box Testing
The Internal Workings of an Somewhat knowledge of the Tester has full knowledge of the
application are not required to internal workings are known. Internal workings of the application .
be known .
Also known as closed box Another term for grey box Also known as clear box testing,
testing, data driven testing testing is translucent testing as structural testing or code based
and functional testing . the tester has limited testing .
knowledge of the insides of the
application .
Performed by end users and Performed by end users and Normally done by testers and
also by testers and also by testers and developers . developers .
developers .
Testing is based on external Testing is done on the basis of Internal workings are fully known
expectations -Internal high level database diagrams and the tester can design test data
behavior of the application is and data flow diagrams . accordingly .
unknown.
This is the least time Partly time consuming and The most exhaustive and time
consuming and exhaustive . exhaustive . consuming type of testing .
Not suited to algorithm Partially suited to algorithm Suited for algorithm testing.
testing, but suitable for End- testing.
to-End testing.
This can only be done by trial Data domains and Internal Data domains and Internal
and error method . boundaries can be tested, if boundaries can be better tested .
known.
Questions Please!!!!