White Box Testing

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){
  1. Int x,y;
  2. If(a>b){
  3. X=a;
  4. Y=b;
  5. }
  6. else{
  7. X = b;
  8. Y = a;
  9. }
  10. }
to make sure that all statements are tested at least once let’s test this function with different values.
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
  1. Function dummy(){
  2. Int a, b;
  3. If(a < b){
  4. Cout<<”something …………is happning here”;
  5. }
  6. If(a > 50){
  7. Cout<<”this point to be tested when value of a is greater than 50”;
  8. }
  9. If(b <10 li="">
  10. Cout<<”this part is tested because value of b is less than 10”;
  11. }
  12. }
To test all possible paths the following test values we will passed for variables a and b
  1. Test 1. a=10, b=15 only first If part is executed.
  2. Test 2. a= 55,b = 6 second if and last if part is executed
  3. Test 3. a = 10,b= 5 last if part is executed.
  4. Test 4. a = 60, b= 20 second if part is executed.
White box testing is not only limited to the above testing situation as it consider also data structure and algorithm implementation so if the variables in a program are not declared are their naming convention is not followed then after testing it also need to be consider if a redundant code is written it need to be wiped.
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

Defect prevention

Defect prevention is SQA technique the purpose of which is to identify root causes of defects and prevent them from reoccurring...