Friday, October 23, 2009

5. Testing Techniques

5. Testing Techniques:
Testing Techniques will be
5.1. Black-Box Testing.
5.2. White-Box Testing.
5.3. Grey Box Testing.

5.1. Black-Box Testing:
Black box testing treats the system as a “black-box”, so it doesn’t explicitly use Knowledge of the internal structure or code. Or in other words the Test engineer need not know the internal working of the “Black box” or application.
Main focus in black box testing is on functionality of the system as a whole.
Each testing method has its own advantages and disadvantages. There are some bugs that cannot be found using only black box or only white box. Majority of the application are tested by black box testing method. We need to cover majority of test cases so that most of the bugs will get discovered by blackbox testing.
a. Tools used for Black Box testing:
Black box testing tools are mainly record and playback tools. These tools are used for regression testing that to check whether new build has created any bug in previous working application functionality. These record and playback tools records test cases in the form of some scripts like TSL, VB script, Java script, Perl.


b. Advantages of Black Box Testing
· Tester can be non-technical.
· Used to verify contradictions in actual system and the specifications.
· Test cases can be designed as soon as the functional specifications are complete.
c. Disadvantages of Black Box Testing:
· The test inputs needs to be from large sample space.
· It is difficult to identify all possible inputs in limited testing time. So writing test cases is slow and difficult
· Chances of having unidentified paths during this testing
5.1.1. Types of Black-box Testing:
i. Boundary Value Analysis:
Many systems have tendency to fail on boundary. So testing boundry values of application is important. Boundary Value Analysis (BVA) is a test Functional Testing technique where the extreme boundary values are chosen. Boundary values include maximum, minimum, just inside/outside boundaries, typical values, and error values. Extends equivalence partitioning Test both sides of each boundary Look at output boundaries for test cases too Test min, min-1, max, max+1, typical values
a. BVA techniques:
1. Number of variables For n variables: BVA yields 4n + 1 test cases.
2. Kinds of ranges Generalizing ranges depends on the nature or type of variables
Advantages of Boundary Value Analysis:
1. Robustness Testing - Boundary Value Analysis plus values that go beyond the limits
2. Min - 1, Min, Min +1, Nom, Max -1, Max, Max +1
3. Forces attention to exception handling
b. Limitations of Boundary Value Analysis
Boundary value testing is efficient only for variables of fixed values i.e boundary.
ii. Equivalence Class Partitioning:
Equivalence partitioning is a black box testing method that divides the input domain of a program into classes of data from which test cases can be derived.
How this partitioning is performed while testing:
1. If an input condition specifies a range, one valid and one two invalid classes are defined.
2. If an input condition requires a specific value, one valid and two invalid equivalence classes are defined.
3. If an input condition specifies a member of a set, one valid and one invalid equivalence class is defined.
4. If an input condition is Boolean, one valid and one invalid class is defined.
iii. Error Guessing:
This is purely based on previous experience and judgment of tester. Error Guessing is the art of guessing where errors can be hidden. For this technique there are no specific tools, writing the test cases that cover all the application paths.
5.2. White Box Testing:
White box testing (WBT) is also called Structural or Glass box testing.
White box testing involves looking at the structure of the code. When you know the internal structure of a product, tests can be conducted to ensure that the internal operations performed according to the specification. And all internal components have been adequately exercised.
5.2.1. Types of white-box testing:
· Basic Path Testing:
· Control Structure testing:
· Program technique testing:
· Mutation Testing:
i. Basic Path Testing:
The white box testers are using this technique to estimate the execution of a program, without any disturbance such that the program should cover all the independent paths defined in it. That is the program has to be executed depending upon how many no of independent paths defined in it.
To implement this technique , the programmers are follow the approaches.
Step1: preparing a program with respect to design logic.
Step2: prepare flowchart for that program.
Step3: calculating cyclomatic complexity.
Step 4: run the program more than 1 time to cover all the independent paths.

a. Cyclomatic Complexity:
The cyclomatic complexity is a measurement for finding the no of independent paths in a flow graph.
ii. Control Structure Testing:
Validating every input statement and output statement correctness for a control structure.
a. Branch testing:
also called Decision Testing
Definition: "For every decision, each branch needs to be executed at least once."
Shortcoming - ignores implicit paths that result from compound conditionals.
Treats a compound conditional as a single statement. (We count each branch taken out of the decision, regardless which condition lead to the branch.)
This example has two branches to be executed:
IF ( a equals b) THEN
statement 1
ELSE
statement 2
END IF

This examples also has just two branches to be executed, despite the compound conditional:
IF ( a equals b AND c less than d ) THEN
statement 1
ELSE
statement 2
END IF

This example has three branches to be executed:
IF ( a equals b) THEN
statement 1
ELSE
IF ( c equals d) THEN
statement 2
ELSE
statement 3
END IF
END IF
Obvious decision statements are if, for, while, switch.
Subtle decisions are return (Boolean expression), ternary expressions, and try-catch.
For this course you don't need to write test cases for IOException and OutOfMemory exception.

b. Condition testing:
Validating a simple Boolean “if” condition with respect to its input statements and output statements correctness.
(Or)
Condition testing is a test construction method that focuses on exercising the logical conditions in a program module.
Errors in conditions can be due to:
Boolean operator error
Boolean variable error
Boolean parenthesis error
Relational operator error
Arithmetic expression error
Definition: "For a compound condition C, the true and false branches of C and every simple condition in C need to be executed at least once."Multiple-condition testing requires that all true-false combinations of simple conditions be exercised at least once. Therefore, all statements, branches, and conditions are necessarily covered.
c. Dataflow testing:
Validating the flow of data with respect to a control statement.
(Or)
Selects test paths according to the location of definitions and use of variables. This is a somewhat sophisticated technique and is not practical for extensive use. Its use should be targeted to modules with nested if and loop statements.



d. Loop testing:
Validating the looping control structures for its defined no of iterations.
(Or)
Loops are fundamental to many algorithms and need thorough testing.
There are four different classes of loops: simple, concatenated, nested, and unstructured.
Examples:
Create a set of tests that force the following situations:
Simple Loops, where n is the maximum number of allowable passes through the loop.
Skip loop entirely
Only one pass through loop
Two passes through loop
m passes through loop where mNested Loops
Start with inner loop. Set all other loops to minimum values.
Conduct simple loop testing on inner loop.
Work outwards
Continue until all loops tested.
Concatenated Loops
If independent loops, use simple loop testing.
If dependent, treat as nested loops.
Unstructured loops
Don't test - redesign.
public class loopdemo
{ private int[] numbers = {5,-3,8,-12,4,1,-20,6,2,10};
/** Compute total of numItems positive numbers in the array
* @param numItems how many items to total, maximum of 10.
*/
public int findTotal(int numItems)
{ int total = 0;
if (numItems > 0 && numItems <= 10) { for (int count=0; count < count =" count"> 0)
{ total = total + numbers[count];
} } } return total;
}}
public void testOne()
{ loopdemo app = new loopdemo();
assertEquals(0, app.findTotal(0));
assertEquals(5, app.findTotal(1));
assertEquals(5, app.findTotal(2));
assertEquals(17, app.findTotal(5));
assertEquals(26, app.findTotal(9));
assertEquals(36, app.findTotal(10));
assertEquals(0, app.findTotal(11));
}

iii. Program technique Testing:
During this testing the programmers are calculating the execution time of a program using monitors. If the program execution is not acceptable then the programmers are performing changes in the structures of a program without disturbing the functionality. I.e. if a program takes more time to complete its execution the programmers are reducing the internal steps of the program without disturbing the external functionality of the program.
iv. Mutation testing:
It means a change in a program. Mutation testing means the programmers are performing changes in a testing program to estimate the correctness & completeness of program testing .i.e. they will make modifications within a program and validates that modified program to check whether it is working properly or not with respect to the modifications.

5.2.2. Why we do White Box Testing?
To ensure:
That all independent paths within a module have been exercised at least once.
All logical decisions verified on their true and false values.
All loops executed at their boundaries and within their operational bounds internal data structures validity.
5.2.3. Need of White Box Testing?
To discover the following types of bugs:

Logical error tend to creep into our work when we design and implement functions, conditions or controls that are out of the program
The design errors due to difference between logical flow of the program and the actual implementation
Typographical errors and syntax checking
Skills Required:
We need to write test cases that ensure the complete coverage of the program logic. For this we need to know the program well i.e. we should know the specification and the code to be tested. Knowledge of programming languages and logic.
5.2.4. Limitations of WBT:
Not possible for testing each and every path of the loops in program. This means exhaustive testing is impossible for large systems.
This does not mean that WBT is not effective. By selecting important logical paths and data structure for testing is practically possible and effective.
5.3. Grey Box Testing:
Grey box Testing is the new term, which evolved due to the different architectural usage of the system. This is just a combination of both Black box & White box testing. Tester should have the knowledge of both the internals and externals of the function.
Tester should have good knowledge of White Box Testing and complete knowledge of Black Box Testing.
Grey box testing is especially important with Web and Internet applications, because the Internet is built around loosely integrated components that connect via relatively well defined interfaces

No comments:

Post a Comment