TESTING
unit 4
• Program Testing:
Testing a program consists of providing the program with a set of test inputs (or test
cases) and observing if the program behaves as expected.
If the program fails to behave as expected, then the conditions under which failure
occurs are noted for later debugging and correction.
Some commonly used terms associated with testing are:
1. Failure: This is a display of an error (or defect or bug). But, the mere presence of
an error may not necessarily lead to a failure.
2. Test case: This is the triplet [I,S,O], where I is the data input to the system, S is
the state of the system at which the data is input, and O is the expected output
of the system.
3. Test suite: This is the set of all test cases with which a given software product is
to be tested
Aim of Testing
• The aim of the testing process is to identify all defects existing in a
software product.
• By the testing provides a practical way of reducing defects in a system
and increasing the users’ confidence in a developed system
Verification Vs Validation
• Verification: It is the process of determining whether the output of
one phase of software development conforms to that of its previous
phase.
• Validation: It is the process of determining whether a fully developed
system conforms to its requirements specification.
• Thus while verification is concerned with phase containment of
errors, the aim of validation is that the final product be error free.
Design of Test Cases
• Exhaustive Testing
• Definition
• Exhaustive testing, also known as complete testing, aims to test all possible combinations of
inputs and conditions for a software system.
• Exhaustive testing would involve testing every possible input, path, and scenario within the
software.
• It ensures that every aspect of the software is thoroughly tested, leaving
no room for undiscovered defects.
Example
• Consider a simple login system with a username and password field.
• Exhaustive testing would involve testing every possible combination of
valid and invalid usernames and passwords, including variations in
length, characters, and special symbols.
• For just a few characters in each field, the number of possible
combinations quickly becomes impractical to test exhaustively.
• Note:
• While exhaustive testing is the ideal approach in theory, it is rarely feasible in
practice due to its impracticality, time constraints, and diminishing returns.
• Testing strategies such as risk-based testing, equivalence partitioning, and
boundary value analysis are often employed to achieve thorough testing
coverage within practical constraints.
Functional Testing Vs. Structural Testing
• In the black-box testing approach, test cases are designed using only
the functional specification of the software, i.e. without any
knowledge of the internal structure of the software. For this reason,
black-box testing is known as functional testing.
• On the other hand, in the white-box testing approach, designing test
cases requires thorough knowledge about the internal structure of
software, and therefore the white-box testing is called structural
testing.
BLACK-BOX TESTING
Black-Box testing Techniques
Boundary Value Analysis (BVA) Technique
• In this technique we used to identify errors at boundaries rather than
finding those that exist in the center of input domains.
Explanation
• BVA focuses on testing the boundaries of input domains to ensure
that the software behaves correctly at these critical points.
• The goal is to identify errors that often occur at the edges of input
ranges, such as off-by-one errors, boundary condition errors, and
arithmetic overflow/underflow errors.
Characteristics
• Tests at the edge of input ranges: Focuses on minimum and maximum
valid input values, as well as just below and just above these
boundaries.
• Identifies potential errors: Helps in catching boundary-related issues
that might not be discovered through other testing techniques.
• Efficient use of resources: Provides effective test coverage with fewer
test cases compared to exhaustive testing.
Example: Testing a Login System
• Consider a login system that requires a username and password.
• BVA would involve testing the boundary conditions for both
username and password fields.
Example Test Cases
• Minimum Valid Username Length
• Input: Username with the minimum allowed length
• Expected Behavior: Successful login
• Maximum Valid Username Length
• Input: Username with the maximum allowed length
• Expected Behavior: Successful login
• One Character Below Minimum Username Length
• Input: Username with one character less than the minimum allowed length
• Expected Behavior: Login failure (boundary condition)
• One Character Above Maximum Username Length
• Input: Username with one character more than the maximum allowed length
• Expected Behavior: Login failure (boundary condition)
Advantages
• Effective at Catching Boundary-Related Errors: Helps identify common
errors that occur at input boundaries.
• Efficient Test Coverage: Provides thorough testing with a relatively
small number of test cases.
Disadvantages
• Limited to Boundary Conditions: BVA may not uncover errors that
exist outside of boundary conditions.
• Does Not Replace Exhaustive Testing: While effective, BVA should be
used in combine with other testing techniques for comprehensive
test coverage.
Equivalence class Partitioning Testing Technique
• Equivalence class Partitioning is a software testing technique that divides
the input domain of a system into classes of data from which test cases can
be derived.
• Equivalence Partitioning aims to reduce the number of test cases by
grouping inputs into equivalence classes that are likely to exhibit similar
behavior.
• The goal is to ensure that each class is tested at least once, as testing one
representative value from each class is as effective as testing all values
within the class.
Characteristics
• Divides Inputs into Classes: Inputs are categorized into equivalence
classes based on similar behavior.
• Reduces Test Cases: By testing one value from each equivalence class,
the number of test cases can be significantly reduced.
• Efficient Use of Resources: Provides effective test coverage while
optimizing testing efforts.
Example: Testing a Login System
• Consider a login system that requires a username and password.
• Equivalence Partitioning would involve dividing the input domain of
usernames and passwords into valid and invalid classes.
Example Test Cases
• Valid Username
• Input: Username from the valid class
• Expected Behaviour: Successful login
• Invalid Username
• Input: Username from the invalid class
• Expected Behaviour: Login failure
• Valid Password
• Input: Password from the valid class
• Expected Behaviour: Successful login
• Invalid Password
• Input: Password from the invalid class
• Expected Behavior: Login failure
Advantages
• Efficient Test Coverage: Provides comprehensive testing with a
reduced number of test cases.
• Reduces Redundancy: Avoids testing every possible input value,
leading to efficient use of resources.
Disadvantages
• Assumption of Similar Behavior: Assumes that all values within an
equivalence class behave similarly, which may not always be the case.
• Potential Missed Defects: Testing only one value from each class may
result in missing defects specific to other values within the class.
23
24
Example
• For a function that computes the
square root of an integer in the
range of 1 and 5000:
• test cases must include the values:
{0,1,5000,5001}.
1 5000
25
26
27
28
29
30
31
32
33
34
35
Boundary Value Analysis:
• Boundary Value Analysis:
1. Lower Boundary - Minimum Length (Numeric)
1. Test Case 1: Enter a password with 3 characters (too short)
2. Test Case 2: Enter a password with 4 characters (minimum length)
3. Test Case 3: Enter a password with 5 characters
2. Upper Boundary - Maximum Length (Numeric)
1. Test Case 4: Enter a password with 27 characters
2. Test Case 5: Enter a password with 28 characters (maximum length)
3. Test Case 6: Enter a password with 29 characters (too long)
3. Lower Boundary - Minimum Length (Alphabetic)
1. Test Case 7: Enter a password with "aaa" (3 characters)
2. Test Case 8: Enter a password with "aaaa" (4 characters, minimum length)
3. Test Case 9: Enter a password with "aaaaa" (5 characters)
4. Upper Boundary - Maximum Length (Alphabetic)
1. Test Case 10: Enter a password with "aaaaaaaaaaaaaaaaaaaaaaaaaaaa" (27 characters)
2. Test Case 11: Enter a password with "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" (28 characters, maximum length)
3. Test Case 12: Enter a password with "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" (29 characters, too long)
Equivalent Partitioning:
1. Valid Inputs (Numeric)
1. Test Case a: Enter a password with 4 numeric characters
2. Test Case b: Enter a password with 10 numeric characters
3. Test Case c: Enter a password with 28 numeric characters
2. Valid Inputs (Alphabetic)
1. Test Case a: Enter a password with "abcd" (4 alphabetic characters)
2. Test Case b: Enter a password with "password" (8 alphabetic characters)
3. Test Case c: Enter a password with "abcdefghijklmnopqrstuvwxyz" (26 alphabetic characters)
1. Invalid Inputs - Too Short (Numeric)
1. Test Case a: Enter a password with 2 numeric characters
2. Test Case b: Enter a password with 3 numeric characters (boundary)
2. Invalid Inputs - Too Short (Alphabetic)
1. Test Case a: Enter a password with "abc" (3 alphabetic characters)
2. Test Case b: Enter a password with "abcd" (boundary)
3. Invalid Inputs - Too Long (Alphabetic)
1. Test Case a: Enter a password with "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" (29 alphabetic characters)
2. Test Case b: Enter a password with "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" (30 alphabetic characters)
4. Invalid Inputs - Too Long (Numeric)
1. Test Case a: Enter a password with 29 numeric characters (boundary)
2. Test Case b: Enter a password with 30 numeric characters
39
40
Decision Table Testing
• Decision Table Testing is a software testing technique used to test
combinations of inputs and conditions by representing them in a
tabular format.
• Decision tables provide a systematic way to identify test cases for
different combinations of inputs and conditions.
• The technique is particularly useful when there are multiple inputs
and conditions that affect the behavior of the system.
Characteristics
• Tabular Representation: Inputs, conditions, and corresponding actions
are organized in a table format.
• Comprehensive Coverage: Tests all possible combinations of inputs
and conditions.
• Systematic Test Design: Provides a structured approach to identify
and document test cases.
Example: Testing a Weather Application
• Consider a weather application that provides recommendations
based on temperature and weather conditions.
• Decision Table Testing can help determine the appropriate
recommendations for different combinations of inputs and
conditions.
Example Decision Table
Temperature Weather Condition Recommendation
High Sunny Wear sunscreen
High Cloudy Bring an umbrella
Low Sunny Wear a jacket
Low Cloudy Bring a sweater
Advantages
• Comprehensive Coverage: Tests all possible combinations of inputs
and conditions.
• Clear Documentation: Provides a structured and easily
understandable representation of test cases.
Disadvantages
• Complexity: Decision tables can become complex, especially with a
large number of inputs and conditions.
• Maintenance Overhead: Updating decision tables can be time-
consuming, especially when requirements change.
Triangle problem by Decision table
• Credit card example:
Let’s take another example. If you are a new customer and you
want to open a credit card account then there are three
conditions first you will get a 15% discount on all your
purchases today, second if you are an existing customer and
you hold a loyalty card, you get a 10% discount and third if you
have a coupon, you can get 20% off today (but BOTH Coupon
and new customer discount can’t be used simultaneously).