4 White Box Testing

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

White Box Testing

Prepared By – Rajesh Popli & Sachin Jain


Agenda

• White box testing – Definition


• White box testing – Need
• Statement coverage
• Branch/Decision coverage
• Path coverage
• Mutation testing
• Advantages
• Disadvantages

Nagarro Public 2
What is White Box Testing?
• White Box Testing is a software testing technique
whereby explicit knowledge of the internal
workings of the item being tested are used to
select the test data.

• White Box Testing is testing the software at the


level of source code.

• Testing based on an analysis of the internal


structure of the component or
system. (ISTQB)
Nagarro Public 3
White Box - Need
• White box testing is the initial stage testing before
black box
• Some category of bugs can be revealed by only
white box testing
• Error come from design phase will be reflected in
code and white box testing helps to detect these
error before they go to next phase
• Some typographical errors are not observed and
go undetected during black box testing

Nagarro Public 4
White Box Testing - Focus

• Not the design, nor the implementation

• Focus is on the logic of implementation

Nagarro Public 5
Black Box Vs. White Box Testing

Nagarro Public 6
What are my other names?

Nagarro Public 7
What are my other names?

• Structural Testing

• Clear Box Testing

• Open Box Testing

• Glass box Testing

• Transparent Box Testing

• Code-Based Testing

Nagarro Public 8
Diff Types of White Box Testing

• Statement Coverage
• Branch/Decision Coverage
• Path Coverage
• Mutation testing

Nagarro Public 9
Statement Coverage

• Statement coverage is a simple metric to calculate & measure the number of


statements in a method or class which have been executed.
• Its key benefit is its ability to identify which blocks of code have not been
executed.
• The Disadvantage is that it cannot test the False conditions.

• Example:
READ P, Q
IF P+Q > 100 THEN
PRINT 'LARGE'
END IF
IF P>50
PRINT 'P Is Greater'
END IF

Nagarro Public 10
Statement Coverage ..contd

Nagarro Public 11
Statement coverage …contd
• P=60, Q=45
• P+Q=105, P>60
• Statement Coverage=(7/7)*100=100 %
• We need just 1 TC for 100% Statement Coverage

• P=45, Q=60
• P+Q=105, P<60
• Statement Coverage=(6/7)*100=86 % (approx)

Nagarro Public 12
Branch/Decision Coverage
• It is an outcome of a decision, & measures the no
of decision outcomes or branches, which have
been tested.

• More in-depth view of the source code compared


to Statement Coverage.

Nagarro Public 13
Branch/Decision Coverage …contd

• Example:
READ P, Q
IF P+Q > 100 THEN
PRINT 'LARGE'
END IF
IF P>50
PRINT 'P Is Greater'
END IF

Nagarro Public 14
Branch/Decision Coverage contd…

Nagarro Public 15
Branch/Decision Coverage contd…
• P=60, Q=45
• P+Q=105, P>60
• First branch is covered

• P=40, Q=50
• P+Q=90 and not > 100, P not > 50
• Second branch is also covered

• So, we need 2 Test cases to cover all branches in


the code.
Nagarro Public 16
Path Coverage

• Path Coverage ensures that we test all decision


outcomes independently of one another.

• In Path Coverage flow of execution takes place


from the start of a method to its exit.

• It is a method of testing which satisfies the


coverage criteria through which the program is
tested across each logical path.

Nagarro Public 17
Path Coverage contd…

• Example:
READ P, Q
IF P+Q > 100 THEN
PRINT 'LARGE'
END IF
IF P>50
PRINT 'P Is Greater'
END IF

Nagarro Public 18
Path Coverage contd…

Nagarro Public 19
Path Coverage contd…

Test case1:
• P=60, Q=45
• P+Q=105>100 & P>50

Test Case2:
• P=40, Q=70
• P+Q>100 but P<50

Nagarro Public 20
Path Coverage contd…

Test Case3:
• P=60, Q=30
• P+Q<100 but P>50

Test Case4:
• P=40, Q=50
• P+Q=90<100 & P<50

Nagarro Public 21
Path Coverage - Cyclomatic Complexity

• Software metric used to measure the complexity


of software
• Developed by Thomas McCabe
• A number of industry studies have indicated that
the higher cyclomatic complexity, higher the
probability of errors

Nagarro Public 22
Cyclomatic Complexity - How to calculate

• number of decisions points + 1

• number of enclosed areas + 1

• Edge-Node+2

Nagarro Public 23
Mutation Testing

• Involves running slightly corrupted versions of


target program through existing test suite to see if
any test cases flag the variations as defects
• Involves modifying a program's source code
or byte code in small ways
• Evaluates the quality of software tests
• A test suite that does not detect and reject the
mutated code is considered defective

Nagarro Public 24
Mutation Testing – Benefits

• Evaluates the quality of software tests


• Helps the tester develop effective tests or locate
weaknesses in the test data
• It answers following questions:
• How do you know that you can trust your unit tests?
• How do you know that they’re really telling you the truth?
• If they don't find a bug, does that really mean that there aren't any?
• What if you could test your tests?

Nagarro Public 25
Mutation Testing – How to apply

• Done by selecting a set of mutation operators and


then applying them to the source program one at
a time for each applicable piece of the source code
• Result of applying one mutation operator to the
program is called a mutant
• If the test suite is able to detect the change (i.e.
one of the tests fails), then the mutant is said to
be killed.

Nagarro Public 26
Mutation Testing – Example

• Given
if (a && b) {
c = 1;
} else {
c = 0;
}

• Condition mutation operator would replace && with || and


produce the mutant
if (a || b) {
c = 1;
} else {
c = 0;
}

• A test with test data a = 1 and b = 0 will kill this mutant

Nagarro Public 27
Mutation Testing – Mutation Operators

• Statement deletion.
• Replace each boolean subexpression with true and false.
• Replace each arithmetic operation with another one, e.g. + with *, -
and /.
• Replace each boolean relation with another one,
e.g. > with >=, == and <=.
• Replace each variable with another variable declared in the same
scope (variable types should be the same).

Nagarro Public 28
White Box Testing - Advantages

• Testing can be commenced at an earlier stage. One


need not wait for the GUI to be available.

• Testing is more thorough, with the possibility of


covering more paths.

Nagarro Public 29
White Box Testing - Disadvantages

• Since tests can be very complex, highly skilled


resources are required, with thorough knowledge
of programming and implementation.

• Test script maintenance can be a burden if the


implementation changes too frequently.

Nagarro Public 30
Thank You
www.nagarro.com

You might also like