CH05.L07 . White Box techniques
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
🔍 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
💡Statement testing
💡Decision testing
💡Control flow graph
💡Coverage
💡Test case
💡Code lines
💡Decision points
💡Practical Software Testing
💡A Practitioner's Guide to Software Test Design
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
As we have learned, white box testing techniques
are used when I have the possibility to
see the source code of
the software that I'll test.
Its techniques are many,
but we''ll focus on 2 of them:
Statement testing
and Decision or branch testing.
In Statement testing technique,
We aim to execute all the code lines.
or to overview all of them
using the less number of
test cases. As for the
Decision technique, our aim is to write
test cases for all tracks that cover
all possibilities for the code.
This technique cannot be
applied unless there are possibilities
or decisions in the code, which appear
when the code contains: if,
then, else or while
we'll understand this more by
applying the 2 techniques on
the following examples; to clarify
the difference between them. In the first
example, there is a source code of 7 lines
for which we will draw a control flow graph,
to make easy for us to apply each technique .
if you still don't know how to draw
a control flow graph, you can
check the "practical software testing" book.
we'll start with applying the Statement testing,
in which we will choose a track on the graph
that help us to write a test case
which can execute all lines
of the code. The track which
helps to go through all the code lines
is the one in which we can choose
a vehicle: "car", and its color is "red"
so it will print the word "fast".
so we can understand that one test case
has resulted a 100% statement coverage
which means that the track of
the test case we wrote can
execute all the statements.
so, how to count the coverage?
we divide the number of Executed statement
on the total number of statements.
Now, we move to applying
the Decision testing technique on this
example. First, you should notice that
the decision points are at node 3 & 4,
from which we have some branches appearing
in the control flow graph.
In order to cover their possibilities,
we should write 3 test cases,
to have 100% decision coverage.
the first test case will be
for the track that covers the possibility
that: type is "true" with (a car)
and color is "true" with (red).
this test case covered the code
possibilities with a percentage of 75%
This is by calculating the decision coverage
which =the executed decisions
divided total number of decisions
but we need to have
a 100% decision coverage.
therefore the rest of test cases will
cover the rest of percentage 25%
of the decision coverage.
the second test case will be for the track
covers the possibility that: type is "car"
but the color is not "red".
the third test case will be for the track
covers the possibility that: type
is not "car" and not "red".
so from the first example, if we apply
the Statement technique, so we need to
write one test case. but for
the Decision technique we need to
write 3 test cases.
Another example to apply the 2
techniques. we will show it to clarify
that it is not necessary in the Statement technique
to use all the code lines
and to have 100% statement
coverage for one test case.
while there are some cases like this example,
to use all the code lines
the minimum number of test cases
should be 3, that is because
there are many the decision points
at the node 3, 4, 6, 9.
the first test case to use
the track 4, 6,
5, 8, 11. when the choice
is (Tuna Roll ). this test case
had 80% statement coverage.
the second test case is when
the choice is like the example of (Cheese Roll).
in order to use the statement no. 7,
this test case had
10% statement coverage.
a third test case to use
the statement no. 10 if the choice
is (Cheese Sandwich).
this test case had
10% statement coverage.
Therefore, all the 3 test cases have resulted
a 100% statement coverage .
if we applied the Decision technique,
it will have the same results of the 3 test
cases we wrote in the Statement technique.
We can conclude from applying
the 2 techniques,is that the number of
test cases we extract from
the Statement testing is always less than
or equal to the number of test cases
from the Decision testing.
we should make sure that the Decision technique
covers testing the code better than
the Statement technique. If you need
a good reference for the 2 types of
White box techniques: the Statement &
Branch testing, there is a book called
A Practitioner's Guide to Software Test Design
Weitere ähnliche Videos ansehen
ISTQB FOUNDATION 4.0 | Tutorial 35 | Branch Testing & Branch Coverage | Test Case Techniques | CTFL
ISTQB FOUNDATION 4.0 | Tutorial 34 | Statement Testing | Statement Coverage | Test Techniques | CTFL
Statement Coverage - Georgia Tech - Software Development Process
Branch Coverage - Georgia Tech - Software Development Process
CH05.L08 . Conclusion
Software Testing Tutorial #34 - Equivalence Partitioning in Testing
5.0 / 5 (0 votes)