白盒测试
字数: 0
White-box testing
把测试对象看作一个打开的透明盒子。测试时,利用程序内部的逻辑结构及有关信息,通过在不同点检查程序状态,检验程序中的每条通路是否都能按预定要求进行正确工作。

流程图的构造

Control Flow Graph (CFG)
不同测试的流程图原理基本是相同的,只是测试用例表不同。
If-Then-Else
notion image
Case / Switch
notion image
Pre-test Loop
notion image
notion image
Post-test Loop
notion image

相关应用

Represented as a regular expression
  • Concatenation . : represen a sequence of nodes in the graph
  • Selection + : represents a decision in the graph
  • Iteration * : represents a repetition in the graph.
Calculate the Number of Paths
  • Replacing node numbers and nulls by the value 1 .
  • Evaluate the expression as a mathematical formula.
    • The selection becomes addition.
    • The concatenation becomes multiplication.
例子
Loops
notion image
notion image
Simplifying:
  • 0 : a null iteration
 
notion image
notion image
Identify all paths
notion image
Null else
There is an if, but without else, the expression (n + 0) is used.
  • The node n represents the true decision.
  • The node 0 represents the null else decision.
notion image
 
 
 
notion image
notion image
 
Switch
notion image
 
 
 
notion image
notion image
 

语句覆盖

Statement Coverage
Make sure that every line of code has been executed during testing.
  • Each node on the CFG is a test case

Test Cases
notion image
Test Data
notion image
 
七个点 七个 case
七个点 七个 case
 
notion image

分支覆盖

Branch Coverage
Make sure that all branches in the source code have been checked during testing.
  • Each branch in the source code is a test case.

Test Case
notion image
Test Data
notion image
九条边 九个case
九条边 九个case
notion image

条件覆盖

Condition Coverage

Every condition in every decision to take on the values true and false.

Test Case
notion image
 
Test Data
notion image

Multiple Condition Coverage

(An example for Line 6: the compound condition only)
notion image
Test Case
 
notion image
notion image
Test Data
notion image

Condition Decision Coverage

Decisions containing multiple conditions. It supplement to the Condition Coverage.

notion image
Test Case
notion image
Identify the Sequences of Decisions
notion image
 
Can we have two Sequences, i.e., {CDC-1, CDC-3, CDC-5} and {CDC-2, CDC-4, CDC-6}, instead of three
  • No. The Condition CDC-4 and CDC-6 can NOT be satisfied at the same time.
    • (短路求值)&&:当前一个已经被判断 false,则不会继续判断下一个条件
Test Data
notion image

Modified Condition Decision Coverage

notion image
Test Case
notion image
 
 
notion image
In addition to Decision Condition Coverage, a Modified Condition Decision Coverage examines the independent effect of each condition from Condition Decision Coverage on the output.
 
Condition Truth Table
Condition Truth Table
Test Data
notion image

路径覆盖

Path Coverage
Path testing causes every possible path from entry to exit of the program to be exercised during testing. Each unique path from start to finish is a test case.

Test Case
notion image
notion image
Test Data
notion image

数据流覆盖

Data Flow Coverage: Indentify Variable Definitions and Uses
变量异常情况
  • Type 1: Defined and then defined again
  • Type 2: Undefined but referenced
  • Type 3: Defined but not referenced

DU-pair Table

notion image
notion image
第五行的”自减“,既是”使用”也是”重新定义”。
notion image

Test Case
notion image
Test Data
notion image

变异测试

Mutation Testing: a form of “fault-insertion” testing
In Mutation Testing faults are inserted into “mutations” of the source code, and the tests (developed using one of the previous techniques) are run against these.
  • A mutation operator is a rule to derive mutants from a software under testing.

A Version of Mutation Operators for Java

notion image
notion image

Example

ABS Mutation Operator
notion image
notion image
ROR Mutation Operator
notion image
 
2023 - 2026