CH 2 Black Box Testing and White Box Testing
CH 2 Black Box Testing and White Box Testing
• Black-box testing is a software testing method where the tester evaluates the
functionality of an application without having access to its internal code
structure, algorithms, or implementation details. Instead, the tester interacts
with the software through its user interface or exposed APIs, treating it as a
"black box" whose internal workings are not visible or known.
• The focus lies solely on examining the software's external behavior, inputs,
outputs, and responses to different user actions or system interactions.
• Black-box testing, sometimes referred to as specification-based testing, is a
method of software testing that examines the functionality of an application
without peering into its internal structures or workings.
• What are the Fundamentals of Black-Box Testing?
• This testing approach is essential for several reasons:
• Independence from Internal Implementation: Black-box testing allows testers to assess the
software's functionality without needing knowledge of its internal workings. This
independence ensures that the evaluation remains unbiased and realistic, as it mimics the
perspective of end-users who are unaware of the software's internal structure.
• User-Centric Perspective: By concentrating on the software's external behavior, black-box
testing aligns closely with the user's experience. It helps identify issues that impact user
interactions, such as usability flaws, incorrect outputs, or unexpected behaviors, leading to
a more user-centric approach to quality assurance.
• Comprehensive Test Coverage: Black-box testing facilitates comprehensive test coverage by
exploring various scenarios, inputs, and usage patterns. Testers can assess the software's
functionality across different environments, user roles, and usage scenarios, helping
uncover defects that might not be apparent during development or white-box testing.
•
• Validation of Requirements and Specifications: Black-box testing serves as
a validation mechanism for ensuring that the software meets its intended
requirements and specifications. By testing against user expectations and
documented requirements, testers can verify that the software behaves as
expected and fulfills its intended purpose.
• Detection of Defects and Vulnerabilities: Black-box testing helps uncover
defects, errors, and vulnerabilities in the software's external behavior. By
subjecting the application to diverse inputs, boundary conditions, and
usage scenarios, testers can identify issues such as functional errors,
security vulnerabilities, performance bottlenecks, and compatibility issues.
• Accessibility and Flexibility: Black-box testing is accessible and adaptable to testers
with varying levels of technical expertise. It does not require in-depth
programming knowledge or access to source code, making it suitable for testers
with diverse backgrounds and skill sets. Additionally, black-box testing techniques
can be applied to different types of software applications, including web
applications, mobile apps, and standalone software products.
•
• What are the Benefits of Black-Box Testing?
• Independence from Internal Implementation: Allows unbiased and realistic
assessment, mimicking end-user perspectives.
• User-Centric Perspective: Aligns testing with user experience, identifying usability
flaws and unexpected behaviors.
• Comprehensive Test Coverage: Covers various scenarios, inputs, and usage
patterns, uncovering defects not apparent during development.
• Validation of Requirements: Ensures the software meets documented
requirements and user expectations.
• Detection of Defects: Identifies functional errors, security vulnerabilities, and
performance bottlenecks.
• Accessibility: Suitable for testers with diverse backgrounds and skill sets, adaptable
to various software applications.
Whate are types of Black-Box Testing Techniques ?
• 1. Equivalence Partitioning:
• Equivalence partitioning is a black-box testing technique that divides the input
domain of a software application into equivalence classes. Each equivalence class
represents a set of valid or invalid inputs that should produce similar outputs from
the software. Test cases are then designed to cover at least one representative
from each equivalence class.
• Example: Consider a login screen for a web application that requires users to enter
their username and password. In equivalence partitioning, we can identify three
equivalence classes for each input:
• Valid username: Any valid username (e.g., "user123")
• Invalid username: Username that doesn't exist in the system (e.g., "invaliduser")
• Empty username: No username provided
• Similarly, for the password field, we can identify equivalence classes such as:
• Valid password: Correct password corresponding to the provided username
• Invalid password: Incorrect password for the provided username
• Empty password: No password provided
• Test cases would then be designed to cover at least one scenario from each
equivalence class, ensuring comprehensive test coverage while minimizing
redundancy.
• 2. Boundary Value Analysis:
• Boundary value analysis (BVA) is a black-box testing technique used to test the boundaries
of input domains. Test cases are designed to evaluate how the software behaves at the
edges or boundaries of valid and invalid input ranges. This helps identify potential errors
or unexpected behavior that may occur near the boundaries.
• Example: Consider a software application that accepts user input for the age of a person,
with the valid range defined as 18 to 65 years. In boundary value analysis, we would
design test cases to evaluate the behavior of the application at the boundaries and just
beyond them:
• Test case 1: Input age as 17 (just below the lower boundary)
• Test case 2: Input age as 18 (lower boundary)
• Test case 3: Input age as 19 (within the valid range)
• Test case 4: Input age as 65 (upper boundary)
• Test case 5: Input age as 66 (just above the upper boundary)
• By testing at these boundary values, we can uncover potential issues such as off-by-one
errors, boundary-related validation failures, and unexpected behaviors near the edges of
the input range.
• 3. Decision Table Testing:
• Decision table testing is a black-box testing technique used to test systems with
complex business logic or decision-making processes. A decision table is created to
represent all possible combinations of inputs and their corresponding outputs or
actions. Test cases are then derived from the decision table to ensure
comprehensive coverage of various decision paths.
• Example: Consider a shipping application that calculates shipping charges based on
the weight and destination of a package. The decision table would list all possible
combinations of inputs (weight and destination) and specify the corresponding
shipping charges or actions. Test cases would then be derived to cover each
combination:
• Test case 1: Package weight = 2 kg, Destination = Local (Domestic)
• Test case 2: Package weight = 5 kg, Destination = International
• Test case 3: Package weight = 10 kg, Destination = Local (Domestic)
• Test case 4: Package weight = 15 kg, Destination = International
• By testing each combination of inputs, decision table testing helps us ensuring that
the software behaves correctly under various scenarios.
• 4. State Transition Testing:
• State transition testing is a black-box testing technique used to test systems that
exhibit different states or modes of operation. Test cases are designed to validate
the transitions between different states and ensure that the software behaves
correctly throughout the state transition process.
• Example: Consider a traffic light control system with three states: Green, Yellow,
and Red. State transition testing would involve designing test cases to validate the
transitions between these states based on predefined rules:
• Test case 1: Transition from Green to Yellow when the timer expires
• Test case 2: Transition from Yellow to Red when the timer expires
• Test case 3: Transition from Red to Green after a specified delay
• Test case 4: Validate that the system remains in the Red state during a power
outage
• By testing the transitions between states and verifying the system's behavior under
different conditions, state transition testing helps ensure the reliability and
correctness of state-based systems.
Comparison of Black-Box Testing and White-Box Testing
It is carried out by
Executed By It is carried out by testers.
software developers.
• Unit Testing: Imagine you’re building a bicycle. Unit testing would be like
checking each part separately – testing the brakes, the gears, the pedals, etc., to
ensure they all work correctly before assembling the whole bicycle.
• Static Analysis: This is like proofreading a book before it’s published. You’re
looking for errors in grammar, punctuation, and sentence structure. Still, you
need to read the book as a whole to understand the story (which would be more
like dynamic analysis).
• Dynamic Analysis: This would be like test-driving a car. You’re not just looking at
the components (like in static analysis), but you’re driving the car to see how it
performs on the road.
• Statement Coverage: Imagine you’re a teacher checking a student’s homework.
Statement coverage would be like ensuring the student has answered every
question on the assignment.
• Branch Testing: This is like exploring all possible routes on a GPS. If you’re at an
intersection, branch testing involves going straight, turning left, and turning right
to ensure all paths lead to valid destinations.
• Path Testing: This would be like a postman ensuring they can deliver mail to
every house on their route. They need to make sure every possible path is
covered.
• Loop Testing: This is like checking a playlist on repeat. You want to ensure it
loops back to the first song correctly after the last song finishes.
White Box Testing Example
• White Box Testing Example
• def Printme(a, b):
result = a + b
if result > 0:
print(“Positive”, result)
else:
print(“Negative”, result)
• In this code, Printme is a function that takes two inputs, adds them, and checks
whether the result is positive or negative. If the result is positive, it prints
“Positive”. If the result is not positive (i.e., zero or negative), it prints “Negative”
along with it.
• The goal of White Box Testing here is to verify all the decision branches (the
if-else condition) in the code.
Here’s what you need to verify in white box testing:
Code Paths: This is like checking every chapter in the book. You must ensure every
part of the code is visited and works correctly.
Loops: This is like checking if the book has any repeated chapters. In code, loops are
parts that can run multiple times. You must ensure these loops work correctly and
don’t repeat forever.
Conditions: This is like checking if the book has twists and turns. In code, conditions
can change what the software does. You need to ensure that every possible
outcome of these conditions is tested.
Inputs and Outputs: This is like checking the start and end of the book. You need to
ensure that for every input (start), the software produces the correct output (end).
Individual Parts: This is like checking every character in the book. In code, these are
the individual functions or objects. You need to make sure each one works correctly
on its own.
Techniques for White Box Testing
• Statement Coverage: This is like making sure you read every sentence in a book.
In code, it means ensuring every line or statement of the code is executed at
least once during testing.
• Branch Coverage: This is like choosing every possible outcome in a “Choose Your
Own Adventure” book. In code, it means testing every possible outcome of the
code’s decision points (like if-else conditions).
• Path Coverage: This is like reading a book’s possible combination of chapters. In
code, it means testing every possible path through the code from start to finish.
• Condition Coverage: This is like checking every possible answer to a question in
a book. In code, it means testing every possible outcome of logical conditions in
the code.
• Decision/Condition Coverage: This is like checking every possible combination of
answers to multiple questions in a book. In code, it means testing every possible
combination of outcomes in logical decisions (like a condition with and logic) in
the code.
• White Box Testing Techniques
• 1. Statement Coverage
• Statement Coverage involves executing all the executable statements in the code at least
once. This technique aims to ensure that every line of code has been tested, but it does not
guarantee the testing of every logical path.
• Example: Consider a simple function that categorizes an age into stages:
•
• def categorize_age(age):
• if age < 13:
• return 'Child' elif age < 20:
• return 'Teen' elif age < 60: return 'Adult' else:
• return 'Senior‘
• Statement coverage would require tests that ensure each return statement is executed at
least once.
•
• 2. Branch Coverage (Decision Coverage)
• Branch Coverage extends beyond statement coverage by ensuring that each
decision in the code executes in all directions at least once. This means testing both
the true and false outcomes of each if statement.
•
• Example with the categorize_age function: To achieve branch coverage, tests must
be designed to cover all age ranges, ensuring that each condition (if and elif)
evaluates to both true and false.
•
• 3. Condition Coverage
• Condition Coverage requires that each Boolean sub-expression of a decision
statement is evaluated to both true and false. This technique digs deeper than
branch coverage by examining the logical conditions within the decision branches.
• Example: If a function decides eligibility based on multiple conditions:
•
• Example: For a function with multiple conditions and loops, path coverage
would require creating test cases that traverse every possible path,
including all iterations of loops and combinations of conditions.
• 5. Loop Coverage
• Loop Coverage focuses specifically on the correctness and behavior of loop
constructs within the code. It tests loops with zero iterations, one iteration,
multiple iterations, and boundary conditions.
•
• def sum_to_limit(limit):
• sum = 0 for i in range(1, limit + 1):
• sum += i
• return sum
• Loop coverage would test the function with limit values of 0 (zero iterations), 1
(one iteration), a moderate number (multiple iterations), and a high number
close to potential boundary conditions.
• 6. MC/DC (Modified Condition/Decision Coverage)
• MC/DC requires each condition in a decision to independently affect the
decision's outcome. This technique is particularly valuable in high-integrity
systems where achieving a high level of confidence in the software's
behavior is crucial.