[INF43] Lecture 14 Testing part 4

软件工程 SoftwareEngineering

   
   

@ZYX 写于2020年05月26日

White box testing

  • Use source code to derive test cases
    • Build a graph model of the system
    • State test cases in terms of graph coverage
  • Choose test cases that guarantee different types of coverage
    1. Node/statement coverage
    2. Edge/branch coverage
    3. Loop coverage
    4. Condition coverage
    5. Path coverage

Node Coverage

  • Select test cases such that every node in the graph is visited
    • Also called statement coverage
  • Selects minimal number of test cases

Edge Coverage

  • Select test cases such that every edge in the graph is visited
    • Also called branch coverage
  • More thorough than node coverage
    • More likely to reveal logical errors

Other Coverage Criteria

  • Loop coverage
    • Select test cases such that every loop boundary and interior is tested
  • Condition coverage
    • Select test cases such that all conditions are tested
      • if (a > b || c > d) …
  • Fault injection
    • Select test cases such that all possible exceptions are thrown
  • Path coverage
    Select test cases such that every path in the graph is visited
    Loops are a problem
    0, 1, average, max iterations
    Most thorough…
    …but is it feasible?

Challenges with white box testing

  • Can be useful for identifying under-tested parts of a program
  • Can cover all nodes or edges without revealing obvious faults
  • Some nodes, edges, or loop combinations may be infeasible

Inspections and Reviews

  • Humans read documents and look for defects
  • Surprisingly effective

Benefits of Inspections and Reviews

Find defects
Improve code understandability
Improve code quality
Transfer knowledge
Avoid breaking builds
Share code ownership
Team assessment

Formal Methods

Proofs of correctness
Note: verification only
Usually done with formal specifications

Static Analysis

  • A computer program analyzes source code and finds defects (without running the code)
  • Results are reviewed by a person because many “errors” are not errors at all