Software Testing Tutorial #19 - What is White Box Testing

Software Testing Mentor
16 Nov 202012:00

Summary

TLDRThis tutorial explains white box testing, highlighting its differences from black box testing. Unlike black box testing, where the internal code isn't visible, white box testing focuses on the internal structure and code logic of the application. The video provides examples, such as a calculator application, to demonstrate how testing methods like statement coverage, branch coverage, condition coverage, loop testing, and path testing are applied. The tutorial emphasizes that white box testing is typically performed during unit and integration testing phases, with tools like JUnit used for verifying code coverage.

Takeaways

  • 🧐 White box testing involves understanding the internal structure of the code, unlike black box testing where you only verify input and output.
  • πŸ’» In white box testing, the tester has knowledge of the internal workings, such as methods and classes used in the functionality.
  • πŸ” White box testing is also known as clear box, glass box, or structural testing, as it focuses on the internal code structure.
  • πŸ§‘β€πŸ’» An example of white box testing is knowing the code behind a calculator, such as how addition or multiplication functions are implemented.
  • πŸ“‘ Techniques in white box testing include statement coverage, branch coverage, condition coverage, loop testing, and path testing.
  • βš™οΈ White box testing is often used during unit testing and integration testing phases to ensure code-level functionality.
  • πŸ“Š Code coverage tools are used in white box testing to measure how much of the code has been exercised by test cases.
  • πŸ”— Developers usually perform white box testing by writing unit tests to cover different conditions and code paths.
  • πŸ”§ White box testing involves verifying how the code handles various scenarios, including valid, invalid, and edge case inputs.
  • πŸ“š Black box testing focuses on input-output verification without any knowledge of the internal code, while white box testing involves inspecting the code itself.

Q & A

  • What is white box testing?

    -White box testing is a testing method where the internal structure, code, and implementation of the software are known to the tester. It involves verifying the internal workings of the code, such as methods, classes, and logic flow.

  • How does white box testing differ from black box testing?

    -In black box testing, the tester does not have access to the internal workings of the software and focuses only on the inputs and outputs. In contrast, white box testing involves understanding and testing the internal code and structure of the application.

  • Can you give an example of black box testing?

    -An example of black box testing is testing a user registration feature on an e-commerce website. The tester clicks the register button (input) and checks if the registration page is displayed correctly (output), without needing to know the internal code.

  • What are some common types of white box testing?

    -Some common types of white box testing include statement coverage, branch coverage, condition coverage, loop testing, and path testing. These techniques ensure that all parts of the code are tested for correctness.

  • What is statement coverage in white box testing?

    -Statement coverage ensures that every statement in the code has been executed and tested at least once during the testing process.

  • What is branch coverage in white box testing?

    -Branch coverage checks that all possible branches of decision points (e.g., if-else conditions) are tested to ensure each branch executes as expected.

  • At what stages of testing is white box testing typically performed?

    -White box testing is typically performed during unit testing and integration testing. In unit testing, small units of code are tested individually, while in integration testing, the interaction between different units is tested.

  • What tools are commonly used for white box testing?

    -Tools such as JUnit for Java and other unit testing frameworks are commonly used for white box testing. These tools help in verifying code coverage, ensuring the different parts of the code are tested adequately.

  • How is white box testing applied to a calculator application?

    -In a calculator application, white box testing would involve inspecting and testing the internal code for operations like addition, subtraction, multiplication, and division. The tester would verify how the code handles valid and invalid inputs.

  • What is loop testing in white box testing?

    -Loop testing involves verifying that loops within the code function correctly under different conditions, such as with no iterations, a single iteration, or multiple iterations.

Outlines

00:00

πŸ” Introduction to White Box Testing

This paragraph introduces white box testing, explaining the contrast between white box and black box testing. The speaker reviews black box testing, where the tester only provides input and verifies the output without knowing how the internal functionality works, using an example of a user registration process. White box testing is then introduced as a method that focuses on understanding the internal code and functionality, such as the methods and classes used for a given feature.

05:02

πŸ’» White Box Testing and Code Access

The paragraph provides an example of white box testing using a calculator. The focus is on accessing the actual code to understand how operations like addition, subtraction, and other functions are implemented. A simple pseudo-code for addition is used to illustrate how white box testing involves testing code behavior with different types of inputs, such as valid and invalid values. The idea is to ensure the code functions correctly and handles edge cases, like invalid data inputs.

10:02

πŸ§ͺ Techniques in White Box Testing

This section covers specific techniques used in white box testing, including statement coverage, branch coverage, condition coverage, loop testing, and path testing. These techniques ensure that all parts of the code are covered and tested. Various code coverage tools can help in this process, and the white box testing is generally done during unit and integration testing phases.

Mindmap

Keywords

πŸ’‘White Box Testing

White box testing is a software testing technique where the tester has access to the internal workings of the system, such as the code, methods, and logic. In the video, it is described as a method of testing where the tester verifies the structure and flow of the code, ensuring that all statements and paths are covered. An example given is testing a calculator’s internal code for addition, subtraction, etc.

πŸ’‘Black Box Testing

Black box testing is a technique where the tester does not have access to the internal code or structure of the system and only tests the functionality by providing inputs and checking outputs. In the video, it is explained that black box testing focuses on verifying outcomes without knowing the internal code. An example given is clicking the 'register' button on an e-commerce site and checking if the registration page appears without understanding the backend processes.

πŸ’‘Statement Coverage

Statement coverage is a white box testing technique where the goal is to execute all the statements in the code at least once. In the video, statement coverage is presented as one of the methods of ensuring that every line of code is tested. The goal is to make sure no part of the code goes untested during the verification process.

πŸ’‘Branch Coverage

Branch coverage is another white box testing method that checks whether each branch (e.g., the 'if' and 'else' statements) has been executed during testing. In the video, this is introduced as a technique to ensure that both the true and false branches of conditional statements are tested to avoid missing any logic.

πŸ’‘Condition Coverage

Condition coverage focuses on testing all the possible conditions in the code, ensuring that every condition in a decision statement is tested. This helps guarantee that the software behaves correctly under various conditions. In the video, condition coverage is mentioned as part of the comprehensive testing done in white box techniques.

πŸ’‘Loop Testing

Loop testing is a white box testing technique used to validate that loops within the code work as expected. This includes testing loops with zero iterations, one iteration, or multiple iterations to ensure the program handles different scenarios. In the video, loop testing is mentioned as part of verifying that all loops in the program are functioning properly.

πŸ’‘Unit Testing

Unit testing is a testing method where individual components or units of a program are tested in isolation. In white box testing, unit tests are typically written by developers to test the code’s internal logic. In the video, unit testing is highlighted as a phase where white box testing commonly occurs, focusing on testing small code segments.

πŸ’‘Integration Testing

Integration testing is the process of testing how different units or modules of the program work together. In white box testing, this might involve verifying how well different pieces of code interact. The video explains that integration testing is often a stage where white box testing is applied to ensure that combined units function correctly after integration.

πŸ’‘Code Coverage Tools

Code coverage tools are software tools that help measure how much of the code is covered by test cases. They ensure that all parts of the code are tested during white box testing. In the video, tools like JUnit for Java are mentioned as examples of frameworks that assist in achieving code coverage during unit testing.

πŸ’‘E-commerce Example

The e-commerce example is used in the video to illustrate both black box and white box testing. In black box testing, the tester checks if the registration page loads correctly after clicking the register button. In white box testing, the tester would examine the code to understand which methods and functions are called after clicking the button, ensuring proper internal functionality.

Highlights

Introduction to white box testing and distinction from black box testing.

In black box testing, the tester has no access to the code and verifies functionality only based on input and output.

White box testing requires understanding of internal code structure, methods, and classes involved in a functionality.

White box testing is also referred to as clear box or structural testing.

Example of black box testing with an e-commerce user registration: testing by clicking buttons and verifying the expected outcomes.

In white box testing, the tester is concerned with the internal operations, such as methods or classes triggered after actions.

Example of white box testing using a calculator, focusing on how the code handles operations like addition and multiplication.

In white box testing, testers can examine code for addition, subtraction, multiplication, and division, checking its behavior with different inputs (valid/invalid).

White box testing includes techniques such as statement coverage, branch coverage, condition coverage, loop testing, and path testing.

Statement coverage ensures that all statements in the code are executed at least once by the test cases.

Branch coverage focuses on ensuring that every possible branch of a decision point in the code is tested.

Condition coverage ensures that each logical condition in a decision statement has been tested with true and false outcomes.

Loop testing verifies that loops within the code are executed properly, including boundary conditions and multiple iterations.

White box testing is typically done during unit testing and integration testing phases, often by developers.

Unit testing frameworks like JUnit are commonly used for white box testing to check code functionality at a granular level.

Transcripts

play00:00

hello everyone welcome again in the

play00:02

software testing tutorial

play00:04

we are going to learn what is white box

play00:06

testing

play00:07

so we have already understood about the

play00:09

black box testing now let us understand

play00:11

what is white box testing because we

play00:13

need to understand the difference

play00:14

between white box and black box testing

play00:17

so in this tutorial i'll explain

play00:20

details about the white box testing so

play00:22

that you know what

play00:23

white box testing is and then the next

play00:25

tutorial i'll complete

play00:26

i'll complete the differences between

play00:29

black box

play00:30

and white box testing okay so as we have

play00:33

understood about the black box testing

play00:34

so

play00:35

in the black box testing we didn't had

play00:38

any access to the code or the

play00:41

functionality that has been developed

play00:43

right so this

play00:44

say for example i'm testing any

play00:47

functionality

play00:48

uh i simply will provide the input

play00:52

and based on the input i'll expect

play00:55

certain output so

play00:58

here i'll verify the output

play01:01

right so if this is the case wherein i

play01:04

don't have any knowledge of the internal

play01:06

working of that functionality say for

play01:08

example

play01:09

user registration in the e-commerce

play01:11

website when user clicks on register

play01:15

after click on clicking on register

play01:18

i only see the registration page being

play01:21

displayed

play01:22

for me right so when i click on register

play01:25

that click is my input and when

play01:28

the registration page is displayed with

play01:31

all the fields that's my output right

play01:35

so if i'm doing the black box testing

play01:38

i'll click on register and

play01:39

i'll verify that the registration page

play01:41

is opening successfully or not

play01:44

right so this is black box testing for

play01:46

me now when we talk about

play01:47

white box testing white box testing is

play01:50

concerned about what actually happens

play01:54

within this box right or

play01:57

what happens in the actual code so say

play02:00

for example if i click on register link

play02:03

i need to have understanding of what

play02:06

all happens within the code

play02:10

which is being written for that

play02:12

particular functionality right so

play02:14

before this registration page is being

play02:17

displayed

play02:19

what all methods are being called what

play02:22

all classes are being written so

play02:24

depending on which programming language

play02:25

you choose what implementation has been

play02:28

done by the developer

play02:29

if i am concerned about the details of

play02:32

those

play02:32

implementation then that is known as

play02:35

white box

play02:36

testing white box testing is also known

play02:38

as class

play02:39

box testing clear uh box testing

play02:43

or structural testing right so uh when

play02:46

you check

play02:47

the structure of the code so it's in in

play02:49

the structural testing there are many

play02:50

types of

play02:51

white box testing which will cover in

play02:53

detail in upcoming tutorials

play02:55

but as of now just understand when you

play02:58

are the

play02:58

when you want to understand the internal

play03:01

working how the code how the methods are

play03:03

written

play03:04

which methods or which class calls which

play03:07

class so all that details

play03:10

uh when you are trying to test then that

play03:12

is known as white box testing now let me

play03:14

take an example of

play03:16

white box testing and i'll explain you

play03:18

know how

play03:19

you can explain the white box testing to

play03:22

the interviewer

play03:23

now say for example i'll take very

play03:25

simple example of calculator

play03:27

okay say for example there is a website

play03:29

all right

play03:30

and uh on the website you have the

play03:32

calculator

play03:33

so usually what you'll do is you have

play03:36

certain you know like numbers there

play03:38

so you have the screen and you have

play03:42

if you are accessing the the calculator

play03:44

on the website so there will be the

play03:46

sunscreen and

play03:47

there will be you know like certain

play03:48

numbers one two three uh

play03:50

four five six seven eight nine right

play03:53

and then plus minus uh multiplication

play03:56

and division

play03:56

and equal to sign so very simple so for

play03:59

example i have taken the calculator

play04:00

so if you are trying to test the

play04:03

calculator

play04:04

using the black box technique what you

play04:06

will do is uh if you want to you know

play04:08

test all the functionality you will test

play04:10

the addition subtraction multiplication

play04:12

and division right so this is simple

play04:14

calculators what i'll do is i'll try a

play04:16

couple of scenarios with the addition so

play04:17

i'll say

play04:18

seven i'll press seven and then plus

play04:20

eight and then i'll verify

play04:22

uh press equal to and verify that the

play04:24

sum is what i

play04:25

expect okay similarly if i want to

play04:29

verify the subtraction multiplication

play04:32

division i'll follow

play04:33

the different scenarios or the test

play04:35

cases to verify those scenarios

play04:36

so this type of testing will be the

play04:38

black box testing for me because

play04:41

once i press seven and then plus press

play04:44

plus and then press eight and equal to i

play04:47

am not

play04:48

concerned how internally that

play04:50

calculation

play04:51

is happening okay so

play04:55

the internal working of this particular

play04:57

calculator i don't know

play04:59

and that is why this is black box for me

play05:01

when i talk about the white box testing

play05:04

the same calculator basically what i'll

play05:07

do is

play05:08

um i'll open the box right so

play05:11

as it says white box in black box so in

play05:13

the white box the box is open or it's

play05:16

not a black

play05:16

box for me uh i know

play05:20

the internal working or i need to know

play05:22

how the actual calculation happens so in

play05:24

the white box testing you will

play05:25

mostly work with the actual code right

play05:29

so in that particular case what you will

play05:31

do is

play05:33

say for example i'll write

play05:36

some pseudo code here so i have an

play05:40

a number a a number b and

play05:44

then say for example this is integer

play05:48

integer and then there is another

play05:50

integer

play05:52

c and c is equal to a

play05:55

plus b and then basically return

play06:01

c so for example this is one of the

play06:03

addition method that has been

play06:05

implemented

play06:06

as code right so if it is white box then

play06:10

i know

play06:11

that this is what the code has been

play06:13

written for the additional functionality

play06:15

similarly i'll have access

play06:17

to the code that is implemented for the

play06:19

multiplication for division

play06:21

and similar will be the case in the

play06:23

actual applications the complex

play06:25

application say for example e-commerce

play06:26

website

play06:27

you will have access to the actual code

play06:30

or the methods that are written

play06:32

to perform a particular functionality or

play06:35

the requirement if you're testing that

play06:37

and you are verifying

play06:39

the code within it how the code behaves

play06:43

then that it will be white box testing

play06:45

now in this white box testing what i'll

play06:47

do is now

play06:48

because i have access to code as well

play06:50

i'll try to

play06:51

test this particular you know code with

play06:55

valid values invalid values

play06:57

so i'll try with float i'll try with you

play07:00

know invalid numbers

play07:01

i'll try with with passing all other you

play07:04

know negative scenarios and see

play07:06

how this particular code behaves whether

play07:08

it just

play07:09

accepts integers and returns the integer

play07:12

you know sum or multiplication etc

play07:15

or it crashes if i provide some invalid

play07:18

value

play07:19

right so when you do this type of you

play07:22

know verification

play07:23

then that is white box testing i think

play07:25

white box testing there are many

play07:26

techniques so basically statement

play07:28

coverage

play07:28

so there are many types of testing so

play07:31

the

play07:32

statement coverage when you cover each

play07:35

and every

play07:35

you write the test case so that you

play07:37

verify that the

play07:39

statements all the statements in the

play07:40

code are being covered

play07:42

that is known as statement coverage um

play07:44

then you have you know condition

play07:46

coverage

play07:47

loop coverage um and then you know like

play07:50

paths testing or loop testing so all

play07:52

those type of testing

play07:54

will be part of the white box just

play07:56

testing now let me write some of those

play07:59

here as well so that you know so there

play08:01

is statement

play08:04

coverage and

play08:07

the second important one is the branch

play08:09

coverage

play08:10

so when you verify the branch

play08:15

the third important one to remember is

play08:17

the condition coverage

play08:23

then you have the loop

play08:27

testing so you verify there are loops

play08:30

different loops then you verify all the

play08:32

loops are being exercised

play08:33

with your test cases and then you have

play08:36

you know path so different path testing

play08:39

if there are multiple paths

play08:41

say for example you have conditions then

play08:43

you verify all those conditions right

play08:45

so these are some of the techniques or

play08:47

basically the coverage technique that

play08:48

you will verify

play08:50

and there are a lot of code coverage

play08:52

tools available so when you write your

play08:54

white box test cases

play08:55

you most of the time this will be done

play08:58

by the developers but as a tester

play09:01

you will be required to basically

play09:03

provide your inputs or

play09:05

in case you know white box testing or

play09:08

need to do in your organization then you

play09:10

need to cover all this

play09:11

you know white box testing techniques

play09:13

you need to verify

play09:15

that the code coverage or your test

play09:17

cases have

play09:19

or provide you the coverage of statement

play09:21

branch condition

play09:22

you know loop path all the code is being

play09:25

exercised

play09:26

in the white box testing now usually

play09:29

you know white box testing will happen

play09:32

uh in the unit test phase

play09:34

okay so unit testing phase uh is where

play09:37

the white box testing happens as well as

play09:39

in the integration

play09:40

testing okay so integration testing

play09:44

it can happen in both phases because in

play09:46

unit testing there will be small units

play09:48

where which will be you know which

play09:51

usually developers write the unit test

play09:53

cases for and

play09:54

there are you know unit test tools um

play09:57

for example unit test framework for

play09:58

example junit is very popular for java

play10:01

and then integration testing you

play10:02

integrate the units and make sure

play10:05

after integration all these you know

play10:07

statement branch coverage condition

play10:09

coverage

play10:10

loop and path testing is being done at

play10:12

all

play10:13

different levels all right so this is a

play10:16

brief about

play10:17

white box testing when you have

play10:19

understanding and when you have

play10:21

visibility of

play10:22

what exactly happens when you

play10:26

perform any operation or function on a

play10:29

particular application in this case the

play10:32

calculator when i press a

play10:36

when i you know try to add two numbers

play10:38

what exactly happens

play10:40

within the code then that is white box

play10:42

testing if

play10:43

i don't have visibility of what happens

play10:46

within the code

play10:47

then that is known as black box testing

play10:50

okay

play10:51

so this is a brief about the white box

play10:53

testing another example is of the

play10:55

e-commerce

play10:56

website so when i click on register link

play10:59

after clicking on register link which

play11:01

function got called

play11:03

if i have the you know details or i have

play11:07

the access to the actual code

play11:08

when i click on register i can go into

play11:10

the development

play11:13

id and verify which

play11:16

method got called and after that which

play11:17

method got called

play11:19

then that type of coverage and details

play11:22

if i am verifying

play11:23

with different test scenarios that i

play11:25

write as part of the unit test or

play11:27

integration test

play11:28

in my code then that is white box

play11:30

testing

play11:31

all right so that's pretty much all

play11:33

about the white box testing what white

play11:35

box testing is

play11:36

um different types of testing so

play11:39

basically unit testing integration

play11:40

testing you can do different

play11:42

you know white box testing at different

play11:44

levels

play11:45

and then these are some of the coverage

play11:48

or

play11:48

the white box testing techniques that

play11:50

will be utilized

play11:52

in the white box testing so that's all

play11:54

for this tutorial

play11:55

hope it was helpful please do share and

play11:57

subscribe and thank you very much for

play11:59

watching

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
White Box TestingBlack Box TestingSoftware TestingUnit TestingIntegration TestingCode CoverageTest TechniquesStatement CoverageBranch CoverageTesting Basics