SE401 · Annotated SlidesWhite Box Testing — White-Box Testing
White Box Testing · Annotated slides

White-Box Testing

Static white-box testing (desk checking, walkthroughs, formal inspections and their roles) and dynamic white-box testing: statement, path, branch/decision, condition and decision/condition coverage, basis path testing with flow graphs and cyclomatic complexity.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up
Slide 1: Slide 1
Exam weight Low
    Slide 2: • To focus on white box testing • To distinguish between different types of white box
    Exam weight Low
      Slide 3: The slide
      Exam weight Low
        Slide 4: V design the
        Exam weight Low
          Slide 5: Should i memorize
          Exam weight Low
            Slide 6: • Requires access to code • Looks at the program code and performs testing by
            Exam weight Low
            1. White-box (structural) testing needs access to the code; tests are derived from its structure.
            Slide 7: • The program code truly represents what the program actually does and not just what it is intended to do!
            Exam weight Low
              Slide 8: Types of White Box Testing
              Exam weight Low
                Slide 9: • Involves only the source code and not the executables or binaries
                Exam weight Low
                1. Static testing: examine code without running it (reviews, walkthroughs, inspections, static analysis).
                Slide 10: • Humans can find errors that computers can’t. • Multiple humans can provide multiple perspectives.
                Exam weight Low
                  Slide 11: • Different types • Desk checking of the code
                  Exam weight Low
                    Slide 12: • Author informally checks the code against the specifications and corrects defects found.
                    Exam weight Low
                      Slide 13: • Advantages • The programmer knows the code and programming
                      Exam weight Low
                        Slide 14: • Group oriented (as against desk checking) • Brings in multiple perspectives
                        Exam weight High
                        1. Formal inspection: author, moderator, reader, recorder/scribe, inspectors; preparation, meeting, rework, follow-up.
                        🎯 How this can come up · 1 question
                        MCQ

                        In a formal inspection, who leads the meeting and keeps it on track?

                        Slide 15: • Group-oriented activity • Highly formal and structured
                        Exam weight Low
                          Slide 16: • Author • Author of the work product • Makes available the required material to the reviewers
                          Exam weight Low
                            Slide 17: • Typical documents circulated: • Program code
                            Exam weight Low
                              Slide 18: • Preliminary meeting (optional) • Author explains his / her perspective
                              Exam weight Low
                                Slide 19: do
                                Exam weight Low
                                  Slide 20: • Prioritizing various programs • High priority / important codes subject to formal
                                  Exam weight Low
                                    Slide 21: Help identify / are used:
                                    Exam weight Low
                                      Slide 22: • “Never leave home without it!” • The code review checklist aids in organizational
                                      Exam weight Low
                                        Slide 23: • Done by running the executable on the machine • Entails running the product against some predefined
                                        Exam weight Low
                                          Slide 24: • Initial quick checks by developer • Removes “obvious” errors
                                          Exam weight Low
                                            Slide 25: • Exercises different parts of code • Maps parts of code to required functionality
                                            Exam weight Low
                                              Slide 26: • Statement coverage • Path coverage
                                              Exam weight Low
                                              1. Coverage criteria from weak to strong: statement → branch/decision → condition → decision/condition → multiple-condition → path.
                                              Slide 27: de
                                              Exam weight Low
                                                Slide 28: • Generate test data to make the program enter the sequential block, to make it go through the entire
                                                Exam weight High
                                                1. Statement coverage: every statement executed at least once. Weak: can miss the false branch of an if.
                                                Exam trap100% statement coverage does NOT imply 100% branch coverage; 100% branch coverage DOES imply 100% statement coverage.
                                                🎯 How this can come up · 2 questions
                                                True / False

                                                100% decision (branch) coverage guarantees 100% statement coverage.

                                                True / False

                                                100% statement coverage guarantees 100% decision coverage.

                                                Slide 29: • Have data to test the THEN part • Have data to test the ELSE part
                                                Exam weight Low
                                                  Slide 30: • There should be test cases that:
                                                  Exam weight Low
                                                    Slide 31: • Even if we were to achieve a very high level of statement coverage, it does not mean that the program is defect-free.
                                                    Exam weight Low
                                                      Slide 32: • Statement Coverage may not indicate “true coverage” • Path Coverage provides better representation
                                                      Exam weight Low
                                                        Slide 33: Slide 33
                                                        Exam weight Low
                                                          Slide 34: • Further refinement of path coverage • Makes sure each constituent condition in a boolean
                                                          Exam weight Low
                                                            Slide 35: • Finds how many functions are covered by test cases • Higher level of abstraction; hence possible to achieve
                                                            Exam weight Low
                                                              Slide 36: • Performance analysis and optimization • Resource usage analysis
                                                              Exam weight Low
                                                                Slide 37: • Which of the paths are independent? (If paths are not independent, we may be able to minimize the number
                                                                Exam weight Low
                                                                  Slide 38: • Start with a conventional flow chart. • Identify the “decision points.”
                                                                  Exam weight Low
                                                                    Slide 39: Slide 39
                                                                    Exam weight Low
                                                                      Slide 40: • Start with a conventional flow chart.
                                                                      Exam weight Low
                                                                        Slide 41: Flow Diagram for Conventional Flow Chart Calculating Complexity
                                                                        Exam weight Low
                                                                          Slide 42: • Formal definitions • CC = # of predicate nodes + 1
                                                                          Exam weight High
                                                                          1. Cyclomatic complexity V(G) = E − N + 2 = decision nodes + 1 = number of independent paths (minimum tests for basis path coverage).
                                                                          🎯 How this can come up · 1 question
                                                                          MCQ

                                                                          A flow graph has 11 edges and 9 nodes. V(G) =

                                                                          Case (i): A hypothetical program with no decision node

                                                                          • # of independent paths = 1
                                                                          • # of nodes, N = 2;
                                                                          • # of edges, E = 1;
                                                                          • Cyclomatic complexity = E – N + 2 = 1
                                                                          • # of predicate nodes, P = 0;
                                                                          • Cyclomatic complexity = P + 1 = 1

                                                                          End

                                                                          43
                                                                          Exam weight Low
                                                                            Slide 44: Case (ii): Adding one decision node
                                                                            Exam weight Low
                                                                              Slide 45: • An independent path is a path in the flow graph that has not been traversed before in other paths.
                                                                              Exam weight Low
                                                                                Slide 46: Meaning and Interpretation of Cyclomatic Complexity
                                                                                Exam weight Low
                                                                                  Slide 47: • Developers “not finding time for testing” • They develop blind spots for their own defects
                                                                                  Exam weight Low
                                                                                    Slide 48: the
                                                                                    Exam weight Low
                                                                                      Slide 49: • It is concerned with the degree to which test cases exercise or cover the logic of source code of the program
                                                                                      Exam weight Low
                                                                                        Slide 50: void foo(int a, int b, int x) {
                                                                                        Exam weight Low
                                                                                          Slide 51: Slide 51
                                                                                          Exam weight Low
                                                                                            Slide 52: • A set of test cases that traverses every statement at least once.
                                                                                            Exam weight Low
                                                                                              Slide 53: • A stronger logic-coverage criterion than the statement coverage.
                                                                                              Exam weight Low
                                                                                              1. Decision (branch) coverage: every decision takes both true and false outcomes.
                                                                                              Slide 54: Slide 54
                                                                                              Exam weight Low
                                                                                                Slide 55: coverage
                                                                                                Exam weight Low
                                                                                                  Slide 56: • Exceptions
                                                                                                  Exam weight Low
                                                                                                    Slide 57: Slide 57
                                                                                                    Exam weight Low
                                                                                                      Slide 58: Problems!
                                                                                                      Exam weight Low
                                                                                                        Slide 59: Slide 59
                                                                                                        Exam weight Low
                                                                                                          Slide 60: Slide 60
                                                                                                          Exam weight Low
                                                                                                            Slide 61: • Four conditions
                                                                                                            Exam weight Low
                                                                                                            1. Condition coverage: every individual condition in a decision takes both true and false. Doesn’t guarantee decision coverage.
                                                                                                            Slide 62: • Condition coverage test cases must cover the following:
                                                                                                            Exam weight Low
                                                                                                              Slide 63: • Condition coverage test cases must cover the following:
                                                                                                              Exam weight Low
                                                                                                                Slide 64: • Another set of condition-coverage test cases A B X
                                                                                                                Exam weight Low
                                                                                                                  Slide 65: Solution! Decision/Condition Coverage
                                                                                                                  Exam weight High
                                                                                                                  1. Decision/condition coverage: both every condition AND every decision take both outcomes.
                                                                                                                  🎯 How this can come up · 1 question
                                                                                                                  MCQ

                                                                                                                  For "if (A && B)", tests (A=T, B=F) and (A=F, B=T) achieve:

                                                                                                                  Slide 66: decisions and conditions
                                                                                                                  Exam weight Low
                                                                                                                    Slide 67: • We write sufficient test cases so that all possible combinations of condition outcomes in each decision and all points of entry are exercised at least once
                                                                                                                    Exam weight Low
                                                                                                                      Slide 68: • In Figure the following, we need to write test cases that cover the following outcome
                                                                                                                      Exam weight Low
                                                                                                                        Slide 69: • The following test cases cover all eight possibilities:
                                                                                                                        Exam weight Low
                                                                                                                          Slide 70: NOTFOUND=TRUE; DO I=1 to TABSIZE WHILE (NOTFOUND); /*SEARCH TABLE*/ ...searching logic...; END
                                                                                                                          Exam weight Low
                                                                                                                            Slide 71: • You would need eight test cases for the following decision:
                                                                                                                            Exam weight Low
                                                                                                                              Slide 72: • For programs containing only one condition per decision, a minimum test criterion is a sufficient number of test cases to
                                                                                                                              Exam weight Low