CH05.L07 . White Box techniques

MaharaTech - ITI MOOCA
16 Apr 201704:26

Summary

TLDRThis script delves into white box testing, focusing on Statement and Decision techniques for software testing with visible source code. It illustrates how to achieve 100% statement coverage with the least test cases and emphasizes Decision testing for comprehensive code pathway exploration. The explanation includes practical examples, demonstrating the process of creating test cases and calculating coverage percentages. The script suggests that Decision testing generally requires more test cases for better code coverage and references 'A Practitioner's Guide to Software Test Design' for further insights.

Takeaways

  • πŸ“˜ White box testing involves examining the source code of software, allowing for detailed testing techniques.
  • πŸ” Two primary white box testing techniques discussed are Statement testing and Decision or branch testing.
  • πŸ“Š Statement testing aims to execute all lines of code with the fewest test cases possible, ensuring code coverage.
  • πŸ› οΈ Decision testing focuses on creating test cases that cover all possible outcomes of decision points in the code, such as if-else or while loops.
  • πŸ“š A control flow graph is a useful tool for visualizing the flow of a program, aiding in the application of these testing techniques.
  • πŸš— The first example demonstrates how selecting specific conditions (e.g., vehicle type and color) can achieve 100% statement coverage with a single test case.
  • πŸ“ˆ To calculate coverage, divide the number of executed statements by the total number of statements, or executed decisions by the total number of decisions.
  • πŸ”„ The second example shows that statement coverage does not always require using all code lines and can be achieved with multiple test cases.
  • πŸ”’ In the second example, three test cases with varying conditions are needed to achieve 100% statement coverage, illustrating the complexity of some code structures.
  • πŸ’‘ The number of test cases required for Statement testing is generally less than or equal to those needed for Decision testing, highlighting the thoroughness of Decision testing.
  • πŸ“š For further reading on white box testing techniques, 'A Practitioner's Guide to Software Test Design' is recommended.

Q & A

  • What are white box testing techniques?

    -White box testing techniques are methods used when the tester has access to the source code of the software being tested. These techniques allow for a deeper understanding and testing of the internal workings of the software.

  • What are the two white box testing techniques discussed in the script?

    -The two white box testing techniques discussed are Statement testing and Decision or branch testing.

  • What is the goal of Statement testing?

    -The goal of Statement testing is to execute all the code lines or to review all of them using the least number of test cases possible.

  • How is 100% statement coverage achieved according to the script?

    -100% statement coverage is achieved when a single test case can execute all the statements in the code, ensuring that every line of code is tested.

  • What is Decision or branch testing?

    -Decision or branch testing is a technique aimed at writing test cases that cover all possible paths in the code, especially focusing on decision points such as if-then-else or while loops.

  • How many test cases are needed to achieve 100% decision coverage in the first example provided?

    -Three test cases are needed to achieve 100% decision coverage in the first example, each covering different branches of the decision points.

  • What is a control flow graph and how is it used in white box testing?

    -A control flow graph is a diagram that represents the flow of control in a program, showing decision points and the paths that can be taken. It is used in white box testing to visually plan test cases that cover all possible execution paths.

  • How is decision coverage calculated?

    -Decision coverage is calculated by dividing the number of executed decisions by the total number of decisions in the code.

  • What is the relationship between the number of test cases in Statement testing and Decision testing?

    -The number of test cases needed for Statement testing is always less than or equal to the number of test cases needed for Decision testing, as Decision testing aims to cover all possible paths, including all decisions.

  • Why is it not always necessary to use all code lines for 100% statement coverage in some cases?

    -In some cases, due to the structure of the code and decision points, it may be possible to achieve 100% statement coverage with fewer test cases than the total number of statements, as some paths may naturally cover multiple statements.

  • Which book is recommended for a good reference on white box testing techniques?

    -The book 'A Practitioner's Guide to Software Test Design' is recommended for a comprehensive understanding of white box testing techniques, including Statement and Branch testing.

Outlines

00:00

πŸ” Introduction to White Box Testing Techniques

This paragraph introduces the concept of white box testing, which involves examining the internal structure of software. It focuses on two specific techniques: Statement testing and Decision or branch testing. Statement testing aims to execute all lines of code with minimal test cases, while Decision testing ensures all possible code paths are covered. The paragraph also mentions the importance of understanding control flow graphs for applying these techniques effectively. The author suggests referring to the 'Practical Software Testing' book for more details on drawing control flow graphs.

Mindmap

Keywords

πŸ’‘White box testing

White box testing is a method of software testing that involves examining the internal workings of the application. It is applicable when the tester has access to the source code, allowing for a more thorough examination of the software's logic and flow. In the video, white box testing is the overarching theme, with a focus on two specific techniques: Statement testing and Decision testing.

πŸ’‘Statement testing

Statement testing is a white box testing technique aimed at executing every line of code in a program. The goal is to achieve 100% coverage by writing the minimum number of test cases necessary to ensure each statement is executed. In the script, the example of choosing a 'car' with a color 'red' to print 'fast' demonstrates achieving 100% statement coverage with a single test case.

πŸ’‘Decision testing

Decision testing, also known as branch testing, is another white box technique focused on covering all possible paths through the code, particularly at decision points such as 'if', 'then', 'else', or 'while' statements. The script illustrates this by requiring three test cases to cover all outcomes at decision nodes 3 and 4, aiming for 100% decision coverage.

πŸ’‘Control flow graph

A control flow graph is a visual representation of all possible paths that might be executed in a program. It is used to facilitate the application of testing techniques by providing a clear view of the program's structure. The script mentions drawing a control flow graph for the first example to help apply both Statement and Decision testing techniques.

πŸ’‘Coverage

Coverage in the context of software testing refers to the extent to which the code has been tested. It can be measured for statements (statement coverage) or decisions (decision coverage). The script explains how to calculate coverage by dividing the number of executed statements or decisions by the total number of statements or decisions.

πŸ’‘Test case

A test case is a set of conditions or variables under which a tester evaluates a particular part of the software to determine if it performs as expected. The script provides examples of creating test cases for both Statement and Decision testing, with the aim of achieving full coverage.

πŸ’‘Code lines

Code lines refer to individual lines of source code within a program. Statement testing specifically targets executing all code lines. The script uses the term in the context of ensuring that every line is tested, as demonstrated by the example where choosing 'car' and 'red' executes all lines.

πŸ’‘Decision points

Decision points are locations in the code where the flow of execution can diverge based on a condition, such as an 'if' statement. The script identifies nodes 3 and 4 in the control flow graph as decision points, which are critical for the Decision testing technique.

πŸ’‘Practical Software Testing

This is a book mentioned in the script for those who need guidance on drawing control flow graphs. It suggests the book as a resource for further understanding of the practical aspects of software testing, including the creation of control flow graphs.

πŸ’‘A Practitioner's Guide to Software Test Design

This book is recommended in the script as a good reference for understanding white box techniques, specifically Statement and Branch testing. It is presented as a valuable resource for those looking to delve deeper into the subject.

Highlights

White box testing techniques are used when the source code of the software is available for examination.

Two main white box testing techniques are discussed: Statement testing and Decision or branch testing.

Statement testing aims to execute all code lines using the least number of test cases.

Decision testing involves writing test cases to cover all possible paths in the code.

Decision testing requires the presence of conditional statements like if, then, else, or while in the code.

A control flow graph is helpful for applying both Statement and Decision testing techniques.

A test case for Statement testing can achieve 100% statement coverage by executing all code lines.

Statement coverage is calculated by dividing the number of executed statements by the total number of statements.

Decision testing requires writing multiple test cases to cover all decision points and branches.

100% decision coverage is achieved by executing all decision points in the code.

The first example demonstrates Statement testing with one test case that covers all lines of code.

The first example also shows Decision testing with three test cases needed for full coverage.

The second example clarifies that 100% statement coverage does not always require using all code lines.

In the second example, a minimum of three test cases is needed for 100% statement coverage due to multiple decision points.

The second example shows that the same test cases can be used for both Statement and Decision testing, achieving the same results.

The number of test cases required by Statement testing is always less than or equal to that of Decision testing.

Decision testing is considered to provide better code coverage than Statement testing.

A Practitioner's Guide to Software Test Design is recommended for further study on white box testing techniques.

Transcripts

play00:05

As we have learned, white box testing techniques

play00:07

are used when I have the possibility to

play00:09

see the source code of

play00:11

the software that I'll test.

play00:13

Its techniques are many,

play00:15

but we''ll focus on 2 of them:

play00:17

Statement testing

play00:19

and Decision or branch testing.

play00:21

In Statement testing technique,

play00:23

We aim to execute all the code lines.

play00:25

or to overview all of them

play00:27

using the less number of

play00:29

test cases. As for the

play00:31

Decision technique, our aim is to write

play00:33

test cases for all tracks that cover

play00:35

all possibilities for the code.

play00:37

This technique cannot be

play00:39

applied unless there are possibilities

play00:41

or decisions in the code, which appear

play00:43

when the code contains: if,

play00:45

then, else or while

play00:47

we'll understand this more by

play00:49

applying the 2 techniques on

play00:51

the following examples; to clarify

play00:53

the difference between them. In the first

play00:55

example, there is a source code of 7 lines

play00:57

for which we will draw a control flow graph,

play00:59

to make easy for us to apply each technique .

play01:03

if you still don't know how to draw

play01:05

a control flow graph, you can

play01:07

check the "practical software testing" book.

play01:09

we'll start with applying the Statement testing,

play01:11

in which we will choose a track on the graph

play01:13

that help us to write a test case

play01:15

which can execute all lines

play01:17

of the code. The track which

play01:19

helps to go through all the code lines

play01:21

is the one in which we can choose

play01:23

a vehicle: "car", and its color is "red"

play01:25

so it will print the word "fast".

play01:27

so we can understand that one test case

play01:29

has resulted a 100% statement coverage

play01:31

which means that the track of

play01:33

the test case we wrote can

play01:35

execute all the statements.

play01:37

so, how to count the coverage?

play01:39

we divide the number of Executed statement

play01:41

on the total number of statements.

play01:43

Now, we move to applying

play01:45

the Decision testing technique on this

play01:47

example. First, you should notice that

play01:49

the decision points are at node 3 & 4,

play01:51

from which we have some branches appearing

play01:53

in the control flow graph.

play01:55

In order to cover their possibilities,

play01:57

we should write 3 test cases,

play01:59

to have 100% decision coverage.

play02:01

the first test case will be

play02:03

for the track that covers the possibility

play02:05

that: type is "true" with (a car)

play02:07

and color is "true" with (red).

play02:09

this test case covered the code

play02:11

possibilities with a percentage of 75%

play02:13

This is by calculating the decision coverage

play02:15

which =the executed decisions

play02:17

divided total number of decisions

play02:19

but we need to have

play02:21

a 100% decision coverage.

play02:23

therefore the rest of test cases will

play02:25

cover the rest of percentage 25%

play02:27

of the decision coverage.

play02:29

the second test case will be for the track

play02:31

covers the possibility that: type is "car"

play02:33

but the color is not "red".

play02:35

the third test case will be for the track

play02:37

covers the possibility that: type

play02:39

is not "car" and not "red".

play02:41

so from the first example, if we apply

play02:43

the Statement technique, so we need to

play02:45

write one test case. but for

play02:47

the Decision technique we need to

play02:49

write 3 test cases.

play02:51

Another example to apply the 2

play02:53

techniques. we will show it to clarify

play02:55

that it is not necessary in the Statement technique

play02:57

to use all the code lines

play02:59

and to have 100% statement

play03:01

coverage for one test case.

play03:03

while there are some cases like this example,

play03:05

to use all the code lines

play03:07

the minimum number of test cases

play03:09

should be 3, that is because

play03:11

there are many the decision points

play03:13

at the node 3, 4, 6, 9.

play03:15

the first test case to use

play03:17

the track 4, 6,

play03:19

5, 8, 11. when the choice

play03:21

is (Tuna Roll ). this test case

play03:23

had 80% statement coverage.

play03:25

the second test case is when

play03:27

the choice is like the example of (Cheese Roll).

play03:29

in order to use the statement no. 7,

play03:31

this test case had

play03:33

10% statement coverage.

play03:35

a third test case to use

play03:37

the statement no. 10 if the choice

play03:39

is (Cheese Sandwich).

play03:41

this test case had

play03:43

10% statement coverage.

play03:45

Therefore, all the 3 test cases have resulted

play03:47

a 100% statement coverage .

play03:49

if we applied the Decision technique,

play03:51

it will have the same results of the 3 test

play03:53

cases we wrote in the Statement technique.

play03:55

We can conclude from applying

play03:57

the 2 techniques,is that the number of

play03:59

test cases we extract from

play04:01

the Statement testing is always less than

play04:03

or equal to the number of test cases

play04:05

from the Decision testing.

play04:07

we should make sure that the Decision technique

play04:09

covers testing the code better than

play04:11

the Statement technique. If you need

play04:13

a good reference for the 2 types of

play04:15

White box techniques: the Statement &

play04:17

Branch testing, there is a book called

play04:19

A Practitioner's Guide to Software Test Design

play04:21

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

5.0 / 5 (0 votes)

Related Tags
White BoxTesting TechniquesStatement TestingDecision TestingCode CoverageSoftware QualityControl FlowTest CasesTest DesignPractical Guide