Chương 5
Chương 5
TEST TECHIQUES
BỘ MÔN CÔNG NGHỆ PHẦN MỀM
KHOA CNTT-ĐH NGOẠI NGỮ TIN HỌC TPHCM
OBJECTIVES
White box testing (also known as Clear Box Testing, Open Box Testing, Glass Box Testing, Transparent
Box Testing, Code-Based Testing or Structural Testing) is a software testing method in which the internal
structure/design/implementation of the item being tested is known to the tester. The tester chooses inputs
to exercise paths through the code and determines the appropriate outputs. Programming know-how and
the implementation knowledge is essential. White box testing is testing beyond the user interface and into
the nitty-gritty of a system.
Definition by ISTQB
• white-box testing: Testing based on an analysis of the internal structure of the component or system.
• white-box test design technique: Procedure to derive and/or select test cases based on an analysis
of the internal structure of a component or system.
WHITEBOX TESTING
White Box Testing level is applicable to the following levels of software testing:
Advantages
• Testing can be commenced at an earlier stage. One need not wait for the GUI to be available.
Disadvantages
• Since tests can be very complex, highly skilled resources are required, with a thorough knowledge of programming and implementation.
• Test script maintenance can be a burden if the implementation changes too frequently.
• Since this method of testing is closely tied to the application being tested, tools to cater to every kind of implementation/platform may
not be readily available.
WHITE BOX TESTING
Code coverage
• Code coverage is a measure which describes the degree of which the source code of the
program has been tested. It is one form of white box testing which finds the areas of the
program not exercised by a set of test cases. It also creates some test cases to increase
coverage and determining a quantitative measure of code coverage.
• In most cases, code coverage system gathers information about the running program. It
also combines that with source code information to generate a report about the test
suite's code coverage.
WHITE BOX TESTING
Basic coverage criteria
• Function coverage – has each function (or subroutine) in the program been called?
• Statement coverage – has each statement in the program been executed?
• Edge coverage – has every edge in the Control flow graph been executed?
• Branch coverage – has each branch (also called DD-path) of each control structure
(such as in if and case statements) been executed? For example, given an if statement,
have both the true and false branches been executed? This is a subset of edge
coverage.
• Condition coverage (or predicate coverage) – has each Boolean sub-expression
evaluated both to true and false?
WHITE BOX TESTING
Code coverage Methods
1. Statement Coverage
2. Decision Coverage
3. Branch Coverage
4. Toggle Coverage & FSM Coverage
WHITE BOX TESTING
1. Statement Coverage
Statement coverage is a white box test design technique which involves execution of all the
executable statements in the source code at least once. It is used to calculate and measure
the number of statements in the source code which can be executed given the
requirements.
• Statement coverage is used to derive scenario based upon the structure of the code
under test.
WHITE BOX TESTING
1. Statement Coverage
Ex
Scenerio 1:
If a= 3, b = 9
WHITE BOX TESTING
1. Statement Coverage
• The statements marked in yellow color are those which are executed as per the scenario
• Number of executed statements = 5, Total number of statements = 7
• Statement Coverage: 5/7 = 71%
Scenario 2:
• If a = -3, b = -9
WHITE BOX TESTING
1. Statement Coverage
• The statements marked in yellow color are those which are executed as per the
scenario.
• Number of executed statements = 6
• Total number of statements = 7
/* ABS
This program function returns the absolute value of the integer
passed to the function as a parameter. The Flowgraph for ABS
INPUT: An integer.
OUTPUT: The absolute value if the input integer.
*/
1 int ABS(int x)
2 {
3 if (x < 0)
4 x = -x;
5 return x;
6 }
WHITE BOX TESTING
CONTROL FLOW TESTING
Test Cases to Satisfy Path Coverage for ABS
ABS takes as its input any integer. There are many integers (depending on the maximum size
of an integer for the language) that could be input to ABS making it impractical to test all
possible inputs to ABS.
• Black box testing, also known as Behavioral Testing, is a software testing method in
which the internal structure/design/implementation of the item being tested
is not known to the tester. These tests can be functional or non-functional, though
usually functional.
• Black box testing: Testing, either functional or non-functional, without reference to the
internal structure of the component or system.
• Black box test design technique: Procedure to derive and/or select test cases based
on an analysis of the specification, either functional or non-functional, of a component or
system without reference to its internal structure.
BLACKBOX TESTING
Black Box Testing method is applicable to the following levels of software testing:
• Integration Testing
• System Testing
• Acceptance Testing
The higher the level, and hence the bigger and more complex the box, the more black-box
testing method comes into use.
BLACKBOX TESTING
Techniques
• Equivalence Partitioning: It is a software test design technique that involves dividing input values
into valid and invalid partitions and selecting representative values from each partition as test
data.
• Boundary Value Analysis: It is a software test design technique that involves the determination of
boundaries for input values and selecting values that are at the boundaries and just inside/
outside of the boundaries as test data.
• Cause-Effect Graphing: (decision table) It is a software test design technique that involves
identifying the cases (input conditions) and effects (output conditions), producing a Cause-
Effect Graph, and generating test cases accordingly.
• State Transition Testing
BLACK BOX TESTING
Advantages
• Tests are done from a user’s point of view and will help in exposing discrepancies in the
specifications.
• Tester need not know programming languages or how the software has been
implemented.
• Tests can be conducted by a body independent from the developers, allowing for an
objective perspective and the avoidance of developer-bias.
• Test cases can be designed as soon as the specifications are complete.
BLACKBOX TESTING
Disadvantages
• Only a small number of possible inputs can be tested and many program paths will be left
untested.
• Without clear specifications, which is the situation in many projects, test cases will be
difficult to design.
• Tests can be redundant if the software designer/developer has already run a test case.
• Ever wondered why a soothsayer closes the eyes when foretelling events? So is almost
the case in Black Box Testing.
BLACK BOX TESTING
EQUIVALENCE PARTITIONING:
• It is also known as Equivalence Class Partitioning (ECP).
• Using equivalence partitioning test design technique, we divide the test conditions into class
(group). From each group we do test only one condition. Assumption is that all the conditions
in one group works in the same manner. If a condition from a group works then all of the
conditions from that group work and vice versa. It reduces lots of rework and also gives the
good test coverage. We could save lots of time by reducing total number of test cases that
must be developed.
• For example: A field should accept numeric value. In this case, we split the test conditions as
Enter numeric value, Enter alpha numeric value, Enter Alphabets, and so on. Instead of testing
numeric values such as 0, 1, 2, 3, and so on.
BLACK BOX TESTING
• Equivalence Partitioning is also known as Equivalence Class Partitioning. In equivalence
partitioning, inputs to the software or system are divided into groups that are expected
to exhibit similar behavior, so they are likely to be proposed in the same way. Hence
selecting one input from each group to design the test cases.
• Each and every condition of particular partition (group) works as same as other. If a
condition in a partition is valid, other conditions are valid too. If a condition in a partition
is invalid, other conditions are invalid too.
• It helps to reduce the total number of test cases from infinite to finite. The selected test
cases from these groups ensure coverage of all possible scenarios.
• Equivalence partitioning is applicable at all levels of testing
BLACK BOX TESTING
Example 1:
• Assume, we have to test a filed which accepts a Mobile Number of ten digits.
• Valid input: 10 digits
• Invalid Input: 9 digits, 11 digits
• Valid Class: Enter 10 digit mobile number = 9876543210
• Invalid Class Enter mobile number which has less than 10 digits = 987654321
• Invalid Class Enter mobile number which has more than 11 digits = 98765432109
BLACK BOX TESTING
BOUNDARY VALUE ANALYSIS:
• Using Boundary value analysis (BVA), we take the test conditions as partitions and design
the test cases by getting the boundary values of the partition. The boundary between two
partitions is the place where the behavior of the application varies. The test conditions on
either side of the boundary are called boundary values. In this we have to get both valid
boundaries (from the valid partitions) and invalid boundaries (from the invalid partitions).
• For example: If we want to test a field which should accept only amount more than 10
and less than 20 then we take the boundaries as 10-1, 10, 10+1, 20-1, 20, 20+1. Instead of
using lots of test data, we just use 9, 10, 11, 19, 20 and 21
BLACK BOX TESTING
• Boundary value analysis (BVA) is based on testing the boundary values of valid and invalid
partitions.The Behavior at the edge of each equivalence partition is more likely to be
incorrect than the behavior within the partition, so boundaries are an area where testing is
likely to yield defects.
• Every partition has its maximum and minimum values and these maximum and minimum
values are the boundary values of a partition.
• A boundary value for a valid partition is a valid boundary value. Similarly a boundary value for
an invalid partition is an invalid boundary value.
• Tests can be designed to cover both valid and invalid boundary values. When designing test
cases, a test for each boundary value is chosen.
• For each boundary, we test +/-1 in the least significant digit of either side of the boundary.
• Boundary value analysis can be applied at all test levels.
BLACK BOX TESTING
Example 1
Decision Table is aka Cause-Effect Table. This test technique is appropriate for functionalities
which has logical relationships between inputs (if-else logic). In Decision table technique, we deal
with combinations of inputs. To identify the test cases with decision table, we consider
conditions and actions. We take conditions as inputs and actions as outputs.
Examples
Here the conditions to transfer money are ACCOUNT ALREADY APPROVED, OTP (One Time
Password) MATCHED, SUFFICIENT MONEY IN THE ACCOUNT
And the actions performed are TRANSFER MONEY, SHOW A MESSAGE AS INSUFFICIENT
AMOUNT, BLOCK THE TRANSACTION INCASE OF SUSPICIOUS TRANSACTION.
BLACK BOX TESTING
• In the first column I took all the conditions and actions related to the requirement. All
the other columns represent Test Cases.
• T = True, F = False, X = Not possible
BLACK BOX TESTING
• From the case 3 and case 4, we could identify that if condition 2 failed then system will
execute Action 3. So we could take either of case 3 or case 4
• So finally concluding with the below tabular column.
• We write 4 test cases for this requirement.
BLACK BOX TESTING
Example 2:
Take another example – login page validation. Allow user to login only when both the ‘User
ID’ and ‘Password’ are entered correct.
• Here the Conditions to allow user to login are Enter Valid User Name and Enter Valid
Password.
• The Actions performed are Displaying home page and Displaying an error message that
User ID or Password is wrong.
BLACK BOX TESTING
• From the case 2 and case 3, we could identify that if one of the condition failed then the
system will display an error message as Invalid User Credentials.
• Eliminating one of the test case from case 2 and case 3 and concluding with the below
tabular column
BLACK BOX TESTING
State Transition Testing:
• Using state transition testing, we pick test cases from an application where we need to
test different system transitions. We can apply this when an application gives a different
output for the same input, depending on what has happened in the earlier state.
• Some examples are Vending Machine, Traffic Lights.
• Vending machine dispenses products when the proper combination of coins is deposited.
• Traffic Lights will change sequence when cars are moving / waiting
BLACK BOX TESTING
Example 1
Withdrawal of money from ATM. ‘User A’ wants to withdraw 30,000 from ATM. Imagine he
could take 10,000 per transaction and total balance available in the account is 25,000. In the
first two attempts, he could withdraw money. Whereas in the third attempt, ATM shows a
message as “Insufficient balance, contact Bank”. Same Action but due to change in the state,
he couldn’t withdraw the money in the third transaction.
GREY BOX TESTING