0% found this document useful (0 votes)
9 views11 pages

Unit 2 STM

The document outlines various black-box and white-box testing techniques, including Boundary Value Analysis, Equivalence Class Testing, State Table Based Testing, Decision Table Based Testing, Cause-Effect Graphing, Error Guessing, and several white-box methods such as Basis Path Testing and Mutation Testing. Each technique is described with its principles, advantages, disadvantages, and examples to illustrate their application in software testing. The conclusion emphasizes the importance of these techniques in enhancing software reliability and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Unit 2 STM

The document outlines various black-box and white-box testing techniques, including Boundary Value Analysis, Equivalence Class Testing, State Table Based Testing, Decision Table Based Testing, Cause-Effect Graphing, Error Guessing, and several white-box methods such as Basis Path Testing and Mutation Testing. Each technique is described with its principles, advantages, disadvantages, and examples to illustrate their application in software testing. The conclusion emphasizes the importance of these techniques in enhancing software reliability and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

Boundary Value Analysis (BVA)


Introduction:

Boundary Value Analysis (BVA) is a black-box testing technique used to identify errors at
the boundaries of input ranges rather than focusing on center values. Since errors often
occur at the boundaries, BVA is considered one of the most effective techniques for
minimizing defects.

Principle:

The fundamental principle of BVA is to test input values at their boundaries. This typically
involves testing:

1. Minimum boundary value.


2. Maximum boundary value.
3. Just below the minimum.
4. Just above the maximum.

Example:

Consider a system that accepts age between 18 and 60. The test cases would include:

• Just below the minimum: 17


• Minimum boundary: 18
• Just above the minimum: 19
• Just below the maximum: 59
• Maximum boundary: 60
• Just above the maximum: 61

Advantages:

• Detects boundary-related defects efficiently.


• Reduces the number of test cases compared to exhaustive testing.

Disadvantages:

• Ineffective for non-numeric data.


• May miss defects if boundaries are not well defined.
2. Equivalence Class Testing
Introduction:

Equivalence Class Testing is a black-box testing technique that divides input data into
classes or groups that are expected to exhibit similar behavior. Instead of testing every
possible input, a single representative from each class is chosen.

Principle:

• Each class represents a set of valid or invalid states.


• The assumption is that if one element in the class passes or fails, all elements will
behave similarly.

Example:

For an input field that accepts numbers from 1 to 100:

• Valid class: 1 to 100 (e.g., 50)


• Invalid classes:
o Less than 1 (e.g., -5)
o Greater than 100 (e.g., 150)

Advantages:

• Reduces the number of test cases.


• Ensures coverage for a wide range of inputs.

Disadvantages:

• Ineffective if classes are not defined properly.


• Does not detect boundary defects.

3. State Table Based Testing


Introduction:

State Table Based Testing is used when a system's behavior changes depending on its
current state and the input. It involves creating a state transition table that maps inputs to
outputs based on current states.
Principle:

• Identifies states and events that trigger state transitions.


• Helps ensure all transitions are covered.

Example:

A login system might have the following states:

• Logged Out: Entering correct credentials moves to "Logged In."


• Logged In: Clicking "Logout" moves back to "Logged Out."

Advantages:

• Handles systems with complex state transitions.


• Ensures coverage of all possible state changes.

Disadvantages:

• Becomes complex when states and transitions are numerous.


• Difficult to maintain as the system evolves.

4. Decision Table Based Testing


Introduction:

Decision Table Based Testing is a technique that helps in designing test cases for systems
where the outcome is based on a combination of inputs or conditions.

Principle:

• Tables list all possible combinations of inputs and their corresponding outputs.
• Test cases are designed to cover each combination.

Example:

A discount system based on customer age and membership status:


Age Group Member Discount

Adult Yes 20%

Adult No 10%

Senior Yes 30%

Senior No 15%

Advantages:

• Provides a clear view of decision logic.


• Ensures comprehensive testing of all combinations.

Disadvantages:

• Complex tables may lead to redundancy.


• Requires thorough analysis to avoid mistakes.

5. Cause-Effect Graphing Based Testing


Introduction:

Cause-Effect Graphing is a technique used to represent the relationship between causes


(inputs) and effects (outputs) using a graphical representation.

Principle:

• Causes are represented as input conditions.


• Effects are output conditions resulting from specific combinations of causes.

Example:

In a grading system, the cause could be a student's score range, and the effect would be
the grade assigned (A, B, C, etc.).

Advantages:

• Visual representation aids in understanding complex logic.


• Identifies cause-effect relationships effectively.
Disadvantages:

• Difficult to construct for large systems.


• Graph creation can be time-consuming.

6. Error Guessing
Introduction:

Error Guessing is an informal testing technique that relies on the tester's experience and
intuition to predict areas prone to errors.

Principle:

• Based on past experiences and knowledge of common pitfalls.


• No formal procedure; creativity and intuition play key roles.

Example:

Guessing that a calculator app might fail with division by zero.

Advantages:

• Quickly identifies critical defects.


• Complements formal testing techniques.

Disadvantages:

• Highly subjective and unstructured.


• Dependent on tester expertise.

White Box Testing Techniques

White box testing (also known as clear box, glass box, or structural testing) involves examining
the internal structure, code, and implementation of a software application. It aims to verify the
flow of inputs and outputs through the code, enhance code coverage, and detect logical and
structural errors.
Objectives of White Box Testing:

1. Verify the correctness of code logic and flow.


2. Ensure all independent paths are tested.
3. Check the internal workings of the application.
4. Identify poorly structured code and potential vulnerabilities.

1. Basis Path Testing


Definition:

Basis Path Testing is a white box testing technique that ensures the execution of all possible
paths in a program at least once. It is based on graph theory and uses the control flow graph to
analyze the paths.

Steps to Perform Basis Path Testing:

1. Draw the Control Flow Graph (CFG): Represent nodes as statements and edges as
control flows.
2. Calculate Cyclomatic Complexity:
o Formula:

V(G)=E−N+2PV(G) = E - N + 2P

▪E: Number of edges.


▪N: Number of nodes.
▪P: Number of connected components.
3. Identify Independent Paths: Independent paths are those that introduce at least one new
edge not covered in any previous path.
4. Design Test Cases: Ensure each path is tested at least once.

Example:

Consider a simple program to find the maximum of two numbers:

if (a > b)
max = a;
else
max = b;

Cyclomatic Complexity Calculation:

• Edges (E) = 3 (if, true branch, false branch)


• Nodes (N) = 3 (start, if condition, end)
• Components (P) = 1

V(G)=3−3+2=2V(G) = 3 - 3 + 2 = 2

This means there are two independent paths:

1. Path 1: Start → if (true) → max = a → End


2. Path 2: Start → if (false) → max = b → End

2. Loop Testing
Definition:

Loop testing is used to test the correctness and functionality of loops within the program. It
focuses on the loop's execution and boundary conditions.

Types of Loops:

1. Simple Loops: A single loop without nesting.


2. Nested Loops: One or more loops within another loop.
3. Concatenated Loops: Series of independent loops.
4. Unstructured Loops: Loops with irregular control flow.

Techniques for Loop Testing:

1. Zero Iterations: Check how the loop behaves when it is not executed.
2. One Iteration: Verify loop execution with a single iteration.
3. Maximum Iterations: Test the loop with the maximum allowable limit.
4. Exceeding Iterations: Check how the system handles when the iteration count is
exceeded.

Example:

A loop to print numbers from 1 to 5:

for (int i = 1; i <= 5; i++) {


System.out.println(i);
}

Test Cases:

1. Zero Iterations: Modify loop to i = 6 to check non-execution.


2. One Iteration: Modify condition to i <= 1.
3. Maximum Iterations: Use i <= 5.
4. Exceeding Iterations: Use i <= 6 to see if the loop breaks correctly.

3. Condition and Decision Coverage Testing


Definition:

• Condition Coverage: Ensures every Boolean expression in a decision has been


evaluated both true and false.
• Decision Coverage: Ensures that every decision in the code has been tested with both
true and false outcomes.

Example:

Consider a code snippet:

if (x > 10 && y < 5)


result = "Pass";
else
result = "Fail";

Test Cases for Condition Coverage:

1. x = 15, y = 3: True AND True (Pass)


2. x = 5, y = 3: False AND True (Fail)
3. x = 15, y = 7: True AND False (Fail)
4. x = 5, y = 7: False AND False (Fail)

4. Data Flow Testing


Definition:

Data flow testing tracks the flow of data variables and identifies possible anomalies related to
variable definitions and usages. It ensures that:

1. Variables are defined before use.


2. No variables are defined but never used.
3. No variables are used without initialization.

Types of Data Flow Anomalies:

1. Define-Use (DU) Chain: Variable is defined and then used.


2. Define-Kill (DK) Chain: Variable is defined and then redefined without usage.
3. Use-Define (UD) Chain: Variable is used without being defined.
Example:
int x;
x = 10; // Define
y = x + 5; // Use
x = 20; // Redefine (Kill)

Analysis:

• Correctly initialized and used.


• No undefined usage.

5. Mutation Testing
Definition:

Mutation Testing involves intentionally introducing small changes (mutations) into the source
code to check whether the existing test cases can detect the changes. The goal is to measure the
effectiveness of the test suite.

Mutation Operators:

1. Arithmetic Operator Mutations: Change + to - or * to /.


2. Relational Operator Mutations: Change > to < or == to !=.
3. Conditional Operator Mutations: Change && to ||.

Example:

Original Code:

if (a > b)
max = a;
else
max = b;

Mutated Code:

if (a < b)
max = a;
else
max = b;

If the test cases fail with the mutated code, it indicates strong coverage.
6. Statement and Branch Coverage
Statement Coverage:

Ensures that every executable statement in the code is tested at least once.

• Formula:

Statement Coverage=Number of statements executedTotal number of statements×


100\text{Statement Coverage} = \frac{\text{Number of statements
executed}}{\text{Total number of statements}} \times 100

• Example:
• int x = 10;
• if (x > 5)
• x++;
• x = x * 2;

Test Case: x = 10 ensures all statements are executed.

Branch Coverage:

Ensures that each branch of every decision point is executed.

• Formula:

Branch Coverage=Number of branches executedTotal number of branches×100\text


{Branch Coverage} = \frac{\text{Number of branches executed}}{\text{Total number
of branches}} \times 100

• Example:
• if (x > 5)
• System.out.println("High");
• else
• System.out.println("Low");

Test Cases: x = 6 (True) and x = 4 (False) to cover both branches.

Conclusion:

White box testing techniques offer a comprehensive approach to code verification by focusing on
internal logic and structure. Techniques like basis path testing, loop testing, data flow testing,
and mutation testing enhance code quality by identifying logical errors and untested paths. By
thoroughly testing each path and condition, software reliability and maintainability are
significantly improved.

You might also like