White box testing
White box testing also known as structural testing is a software testing technique in which the internal structure of the software is tested, such as coding standard, data structure used, algorithm, in this type of testing the code is executed with intention to test all possible branching point (if-else, loops, switch) and all possible path(path coverage) and test whether the program is executing all of these are not if so then result is checked with the desired outcome, white box testing is mostly performed by developer is it ‘s needs extensive knowledge and flow of the code.Example
Following example is of branch level and statement level testing which insure that every branch and statement of the code is executed at least once.
Function test(int a, int b){
- Int x,y;
- If(a>b){
- X=a;
- Y=b;
- }
- else{
- X = b;
- Y = a;
- }
- }
Test 1.
Let’s pass value of a = 4 and b = 6
Test(4,6);
Calling with this values will test first statement of the function which is variable declaration and then the program will jump to else part as since the value of b is greater than a, and will execute all the statements of else part. Now to test the if part we‘ll call the function by passing the values below
Test 2.
now we shall pass value of a is greater than b so that the program execute the if part.
A = 6. And b = 4
Test(6,4)
This will test all the statements of the if part of the code and hence we have now achieved white box testing of the above simple function.
Now let’s see an example of testing paths coverage which ensure that all decision points to be tested and ensure maximum coverage of the code.
Example
- Function dummy(){
- Int a, b;
- If(a < b){
- Cout<<”something …………is happning here”;
- }
- If(a > 50){
- Cout<<”this point to be tested when value of a is greater than 50”;
- }
- If(b <10 li=""> 10>
- Cout<<”this part is tested because value of b is less than 10”;
- }
- }
- Test 1. a=10, b=15 only first If part is executed.
- Test 2. a= 55,b = 6 second if and last if part is executed
- Test 3. a = 10,b= 5 last if part is executed.
- Test 4. a = 60, b= 20 second if part is executed.
Unit testing is another form of white box testing technique in which individual testable unit of the code such as a class an interface or a function is tested individually and its algorithm is verified independently.
Example suppose we are making a calculator application then to perform unit testing.
Suppose we have first written a function of addition so we will test the addition function independently and verify it’s functionality without the whole application.
image src: https://wpdistrict.sitelock.com/blog/black-box-vs-white-box-part2-sast/
No comments:
Post a Comment