# 动态测试

动态测试是一种软件测试方式，通过以选定输入执行测试项并观察其运行时行为来对测试项进行评估，这是 ISO/IEC/IEEE 29119-1:2022 采用的定义。<sup>[1](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)</sup>《SWEBOK 指南》将同一思想表述为：在通常无限的执行域中选取有限测试用例集，对照规定的预期行为，对程序行为进行动态验证。<sup>[2](http://www.chaseplace.com/UWClass-3/files/SWEbok/SWEBOK-Test.pdf)</sup>其目标是提供关于质量和残余风险的信息，在发布前发现缺陷，并缓解利益相关方因产品质量不佳而承担的风险。<sup>[1](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)</sup>静态测试则不执行代码，通过评审或静态分析来检查测试项；该标准指出，动态测试对于保证是必要但不充分的，应与静态活动结合使用。<sup>[1](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)</sup><sup> • </sup><sup>[3](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-2.pdf)</sup>

| 关键事实 | 值 | 来源 |
|---|---|---|
| 定义 | “通过执行测试项对其进行评估的测试”（定义 3.29） | <sup>[1](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)</sup> |
| 输入域 | 通常无限的执行域中的有限样本 | <sup>[2](http://www.chaseplace.com/UWClass-3/files/SWEbok/SWEBOK-Test.pdf)</sup> |
| 标准化过程 | 四个动态测试过程：设计与实现、环境建立、执行、事件报告 | <sup>[3](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-2.pdf)</sup> |
| 技术族 | 基于规格（黑盒）、基于结构（白盒）、基于经验 | <sup>[4](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-4.pdf)</sup> |
| 自动化覆盖率 | KLEE 在 89 个 Coreutils 工具上生成的测试平均行覆盖率超过 90% | <sup>[5](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)</sup> |
| 每个缺陷的成本（40 ¢/kWh） | 静态分析器 0.0003–1.9 ¢/缺陷；最佳模糊测试器 AFL++ 58.5 ¢/缺陷 | <sup>[6](https://arxiv.org/pdf/2505.22052)</sup> |
| 2024 年基准结果 | 在 5,693 个 C 程序上，测试生成器在缺陷发现方面优于模型检查器 | <sup>[7](https://link.springer.com/article/10.1007/s10009-024-00769-8)</sup> |

## 工作原理

在几乎所有非平凡情形中，穷尽测试都是不可能的，因为可能的测试数量巨大，所以动态测试通过采样输入来工作。<sup>[1](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)</sup>动态分析是精确的，因为它观察实际、确切的运行时行为，不做任何近似；其弱点在于结果可能无法推广到未来的执行，因为测试套件可能并不代表程序所有可能的行为。某些静态分析是可靠且保守的，可推广到所有执行，但不精确；其他实用静态分析则牺牲了可靠性；相比之下，动态结果只涉及实际观察到的执行。<sup>[8](https://homes.cs.washington.edu/%7Emernst/pubs/staticdynamic-woda2003.pdf)</sup>

第二个区分是故障与失效。静态分析检测软件包含的故障，而动态分析只能检测失效，还需要进一步步骤才能识别观察到的失效背后的故障。<sup>[9](http://www.grise.upm.es/docs/ESERNET_Functional_Testing.pdf)</sup>记录在 SWEBOK 中的迪杰斯特拉（Dijkstra）箴言指出，程序测试可以表明缺陷的存在，但永远不能表明缺陷的不存在。<sup>[2](http://www.chaseplace.com/UWClass-3/files/SWEbok/SWEBOK-Test.pdf)</sup>古迪纳夫（Goodenough）和格哈特（Gerhart）的基本定理给出了形式上的对应：如果一个选择准则既可靠又有效，那么成功执行一个完整测试集意味着程序不包含错误，因此在某些情况下，测试就是正确性证明。<sup>[10](https://psycnet.apa.org/doi/10.1109/TSE.1975.6312836)</sup>

## 如何实施

测试用例是一组为驱动测试项执行而开发的前置条件、输入和预期结果；测试执行是运行测试并产生实际结果。<sup>[3](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-2.pdf)</sup>预期结果应在执行前定义；否则，一个看似合理但错误的结果可能被接受为正确。<sup>[11](https://else.fcim.utm.md/pluginfile.php/154842/mod_resource/content/1/ISEB_Fundation_Guide_Second_Edition.pdf)</sup>

ISO/IEC/IEEE 29119-2 将工作组织为四个动态测试过程：测试设计与[实现](https://www.edgepedia.org/zh/implementation)、测试环境建立与维护、测试执行、测试事件报告。<sup>[3](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-2.pdf)</sup>退出准则使覆盖率可度量：如果准则是 85% 语句覆盖率而执行达到 75%，选项是更改准则或运行更多测试。<sup>[11](https://else.fcim.utm.md/pluginfile.php/154842/mod_resource/content/1/ISEB_Fundation_Guide_Second_Edition.pdf)</sup>修复后，重新测试确认更改区域，回归测试覆盖主要功能以捕获意外更改。<sup>[11](https://else.fcim.utm.md/pluginfile.php/154842/mod_resource/content/1/ISEB_Fundation_Guide_Second_Edition.pdf)</sup>当目标是运行时观察而非通过/失败检查时，动态分析分两阶段运行：程序插桩并生成性能剖析数据或跟踪记录，然后分析，可离线进行（成本较低，用于发现错误）或与执行并行在线进行（成本较高）。<sup>[12](https://www.promptedu.se/promptwp/wp-content/uploads/2015/01/Dynamic-Analysis-Survey-FICTA-14.pdf)</sup>

## 起源

形式化时代始于 1975 年。古迪纳夫和格哈特的论文《走向测试数据选择理论》于 1975 年发表在《ACM SIGPLAN Notices》上，将核心问题框定为什么构成充分的测试，并定义了测试准则的可靠性和有效性要求。<sup>[13](https://doi.org/10.1145/390016.808473)</sup>豪登（Howden）1975 年发表在《IEEE Transactions on Computers》上的论文描述了一个定义良好的测试数据生成过程模型，可用于构建自动测试数据生成系统。<sup>[14](https://doi.org/10.1109/t-c.1975.224259)</sup>朱（Zhu）、霍尔（Hall）和梅（May）的综述将“什么是测试准则？”这一早期突破归功于古迪纳夫和格哈特，但记录到没有可计算准则同时满足两项要求，从而将研究转向实用充分性准则，如语句、分支、路径和变异覆盖率。<sup>[15](https://people.irisa.fr/Sophie.Pinchinat/VTS/DocumentsWebPage/p366-zhu.pdf)</sup>

[符号执行](https://www.edgepedia.org/zh/symbolic-execution)是现代自动化动态测试的基础，出现在 20 世纪 70 年代的两项记录中：SELECT，由罗伯特·S·博耶（Robert S. Boyer）、伯纳德·埃尔斯帕斯（Bernard Elspas）和卡尔·N·莱维特（Karl N. Levitt）提出的通过符号执行测试和调试程序的形式系统（《ACM SIGPLAN Notices》，1975），<sup>[16](https://doi.org/10.1145/390016.808445)</sup>以及詹姆斯·C·金（James C. King）的《符号执行与程序测试》（《Communications of the ACM》，1976）。<sup>[17](https://doi.org/10.1145/360248.360252)</sup>

## 变体

ISO/IEC/IEEE 29119-4 将测试设计技术分为基于规格（黑盒）、基于结构（白盒）和基于经验的测试。<sup>[4](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-4.pdf)</sup>[黑盒测试](https://www.edgepedia.org/zh/black-box-testing)像客户一样运行程序，不了解代码，以规格作为测试基础。<sup>[18](https://ptgmedia.pearsoncmg.com/imprint_downloads/informit/sams/sample_chapters/SAMS_CH05_0672327988.pdf)</sup>等价划分将无限可能的测试用例集缩减为更小、同等有效的集合；等价类是测试同一事物或揭示同一缺陷的测试用例集。<sup>[18](https://ptgmedia.pearsoncmg.com/imprint_downloads/informit/sams/sample_chapters/SAMS_CH05_0672327988.pdf)</sup>[随机测试](https://www.edgepedia.org/zh/random-testing-software-testing)使用输入域模型和输入分布，没有公认的覆盖项。<sup>[4](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-4.pdf)</sup>压力测试使软件资源匮乏，负载测试向其施加所能承受的全部负载，重复测试针对内存泄漏。<sup>[18](https://ptgmedia.pearsoncmg.com/imprint_downloads/informit/sams/sample_chapters/SAMS_CH05_0672327988.pdf)</sup>

**符号与混合执行技术**利用程序自身结构来选择输入。符号执行将输入表示为符号值，因此输出成为符号输入的函数。<sup>[5](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)</sup>动态符号执行（混合执行测试）在具体输入上运行程序，同时维护符号状态，使用约束求解器将下一次执行导向替代可行路径；具体执行直接测试分支可满足性。<sup>[5](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)</sup><sup> • </sup><sup>[19](https://arxiv.org/pdf/1610.00502v3.pdf)</sup>命名的工具包括 CUTE，由库希克·森（Koushik Sen）、达尔科·马里诺夫（Darko Marinov）和古尔·阿迦（Gul Agha）提出的 C 语言混合执行单元测试引擎（2005），<sup>[20](https://doi.org/10.21236/ada482657)</sup>EXE，由克里斯蒂安·卡达尔（Cristian Cadar）及其同事提出的执行生成测试（2006），<sup>[5](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)</sup>KLEE，由克里斯蒂安·卡达尔、丹尼尔·邓巴（Daniel Dunbar）和道森·恩格勒（Dawson Engler）提出（2008），<sup>[21](https://doi.org/10.5555/1855741.1855756)</sup>以及威廉·维瑟（Willem Visser）、科琳娜·S·帕萨雷亚努（Corina S. Pǎsǎreanu）和萨弗拉兹·库尔希德（Sarfraz Khurshid）使用 Java PathFinder 模型检查器进行测试输入生成（2004）。<sup>[22](https://doi.org/10.1145/1013886.1007526)</sup>白盒模糊测试，由帕特里斯·戈德弗鲁瓦（Patrice Godefroid）、迈克尔·Y·莱文（Michael Y. Levin）和大卫·A·莫尔纳（David A. Molnar）于 2008 年作为 SAGE 系统报告，在 x86 指令级别应用这种搜索风格。<sup>[5](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)</sup><sup> • </sup><sup>[23](https://patricegodefroid.github.io/public_psfiles/icse2011.pdf)</sup>DART 深度优先地否定分支，而 SAGE 的分代搜索以固定顺序否定约束并限制回溯。<sup>[19](https://arxiv.org/pdf/1610.00502v3.pdf)</sup>混合工具将模糊测试（完全深度探索某些路径）与符号执行（低深度探索大多数分支）相结合；Driller 根据基本块覆盖率的增长率在定向符号执行和模糊测试之间自适应切换。<sup>[24](https://ar5iv.labs.arxiv.org/html/1712.06843)</sup>

## 应用

动态测试涵盖单元、集成、系统和回归级别，重新测试和回归测试如上所述加以区分。<sup>[11](https://else.fcim.utm.md/pluginfile.php/154842/mod_resource/content/1/ISEB_Fundation_Guide_Second_Edition.pdf)</sup>在工业规模上，SAGE 自 2008 年以来在微软专用安全实验室中平均 100 多台机器上持续运行，对数百个应用进行模糊测试，发现了 [Windows 7](https://www.edgepedia.org/zh/windows-7) 开发期间文件模糊测试发现的所有缺陷中约三分之一。<sup>[23](https://patricegodefroid.github.io/public_psfiles/icse2011.pdf)</sup>动态分析工具服务于内存分析、不变式检测和竞态检测：Valgrind 是检测内存管理和线程缺陷的插桩框架，Pin 执行动态二进制插桩，Daikon 是离线动态不变式检测器。<sup>[12](https://www.promptedu.se/promptwp/wp-content/uploads/2015/01/Dynamic-Analysis-Survey-FICTA-14.pdf)</sup>在服务规模上，截至 2025 年 5 月，OSS-Fuzz 已帮助在 1,000 个项目中识别并修复超过 13,000 个漏洞和 50,000 个缺陷；截至 2026 年 2 月，谷歌的 ClusterFuzz 已在 [Chromium](https://www.edgepedia.org/zh/chromium-web-browser) 等谷歌代码中发现 30,000 多个缺陷。<sup>[25](https://cmu-313.github.io/assets/pdfs/12-dynamic-analysis.pdf)</sup>

## 局限性与替代方案

**判定问题**是核心：决定观察到的结果是否可接受，通过人工检查或与参考系统比较来解决。<sup>[2](http://www.chaseplace.com/UWClass-3/files/SWEbok/SWEBOK-Test.pdf)</sup>模糊测试的判定“程序不应崩溃”支持自动输入生成，但很弱，因为不崩溃并不意味着正确；`-fsanitize=address` 等运行时错误检测工具通过编译时插桩检测非法状态来强化它，代价是执行变慢，而逻辑缺陷仍无法揭示。<sup>[25](https://cmu-313.github.io/assets/pdfs/12-dynamic-analysis.pdf)</sup>

系统化动态测试生成受困于沿个别路径的符号执行不精确性以及路径爆炸，即依赖输入的循环或递归使路径数量无限或非常大。<sup>[26](https://patricegodefroid.github.io/public_psfiles/marktoberdorf2015.pdf)</sup><sup> • </sup><sup>[24](https://ar5iv.labs.arxiv.org/html/1712.06843)</sup>尽管如此，它仍是已知最精确的代码驱动测试生成形式，比静态、随机、基于污点和基于覆盖启发式的生成更精确，但它需要自动定理证明来处理路径约束。<sup>[26](https://patricegodefroid.github.io/public_psfiles/marktoberdorf2015.pdf)</sup>模糊测试器无法在未覆盖代码中发现缺陷，且只能在活动环境中发现缺陷；一个 32 位整数溢出在 x86_64 构建上未被任何模糊测试器触发，而静态分析推理所有环境但产生更多误报。<sup>[6](https://arxiv.org/pdf/2505.22052)</sup>与形式化替代方案相比：可靠验证对执行进行过近似以证明无错误，但产生虚假警告；测试进行欠近似以证明错误存在；大多数实用静态分析牺牲可靠性，因此工程师必须像未应用静态分析一样进行测试。<sup>[27](https://mariachris.github.io/Pubs/IT-2017.pdf)</sup>2024 年对 SV-COMP 和 Test-Comp 竞赛在 5,693 个 C 程序上的重新分析发现，尽管模型检查器仍极具竞争力，但在缺陷发现方面现已被参赛测试生成器超越，其中大多数使用包括形式化方法的混合方法。<sup>[7](https://link.springer.com/article/10.1007/s10009-024-00769-8)</sup>

自 2023 年底以来，基于大语言模型（LLM）的生成已进入工作流程。一项系统综述发现，LLM 生成的测试有时在覆盖率上超过传统工具且更易读，但传统方法在准确性和可靠性上仍更可预测，上下文长度限制和语法错误是持续挑战。<sup>[28](https://link.springer.com/article/10.1007/s10586-026-06021-z)</sup>结构感知模型优于简单提示：GLMTest 在代码属性图上联合训练异构图神经网络与 LLM，在 TestGenEval 基准上相比 Claude-Sonnet-4.5 提示将分支准确率从 27.4% 提高到 50.2%。<sup>[29](https://aclanthology.org/2026.findings-acl.540.pdf)</sup>HITS，由王泽军（Zejun Wang）及其同事提出（2024，arXiv），应用方法切片来提高 LLM 单元测试覆盖率。<sup>[30](https://doi.org/10.48550/arxiv.2408.11324)</sup>

## References

1. [ISO/IEC/IEEE 29119-1:2022, Concepts and definitions (official preview; full-text copy merged)](https://cdn.standards.iteh.ai/samples/81291/6694557ff8304df8841bb191a00ecc6f/ISO-IEC-IEEE-29119-1-2022.pdf)
2. [SWEBOK Guide, Software Testing Knowledge Area](http://www.chaseplace.com/UWClass-3/files/SWEbok/SWEBOK-Test.pdf)
3. [ISO/IEC/IEEE 29119-2, Test processes](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-2.pdf)
4. [ISO/IEC/IEEE 29119-4:2015, Test techniques](https://wildart.github.io/MISG5020/standards/ISO-IEC-IEEE-29119-4.pdf)
5. [Symbolic Execution for Software Testing: Three Decades Later (Cadar & Sen, CACM 2013, open version)](https://cacm.acm.org/research/symbolic-execution-for-software-testing/)
6. [A Comparative Study of Fuzzers and Static Analysis Tools for Finding Memory Unsafety in C and C++ (2025)](https://arxiv.org/pdf/2505.22052)
7. [Six years later: testing vs. model checking (Beyer et al., STTT 2024)](https://link.springer.com/article/10.1007/s10009-024-00769-8)
8. [Static and dynamic analysis: synergy and duality (Ernst, WODA 2003)](https://homes.cs.washington.edu/%7Emernst/pubs/staticdynamic-woda2003.pdf)
9. [Functional Testing, Structural Testing and Code Reading: What Fault Type do they Each Detect? (Juristo & Vegas, 2003)](http://www.grise.upm.es/docs/ESERNET_Functional_Testing.pdf)
10. [Toward a theory of test data selection (Goodenough & Gerhart, IEEE TSE 1975)](https://psycnet.apa.org/doi/10.1109/TSE.1975.6312836)
11. [ISEB Foundation Guide (2nd edition), Software Testing](https://else.fcim.utm.md/pluginfile.php/154842/mod_resource/content/1/ISEB_Fundation_Guide_Second_Edition.pdf)
12. [A Survey of Dynamic Program Analysis Techniques and Tools (Gosain & Sharma, FICTA 2014)](https://www.promptedu.se/promptwp/wp-content/uploads/2015/01/Dynamic-Analysis-Survey-FICTA-14.pdf)
13. [John B. Goodenough, Susan L. Gerhart (1975). Toward a theory of test data selection. ACM SIGPLAN Notices.](https://doi.org/10.1145/390016.808473)
14. [W.E. Howden (1975). Methodology for the Generation of Program Test Data. IEEE Transactions on Computers.](https://doi.org/10.1109/t-c.1975.224259)
15. [Software Unit Test Coverage and Adequacy (Zhu, Hall & May, ACM Computing Surveys 1997)](https://people.irisa.fr/Sophie.Pinchinat/VTS/DocumentsWebPage/p366-zhu.pdf)
16. [Robert S. Boyer, Bernard Elspas, Karl N. Levitt (1975). SELECT, a formal system for testing and debugging programs by symbolic execution. ACM SIGPLAN Notices.](https://doi.org/10.1145/390016.808445)
17. [James C. King (1976). Symbolic execution and program testing. Communications of the ACM.](https://doi.org/10.1145/360248.360252)
18. [Testing the Software with a Blindfold On (sample chapter, Sams)](https://ptgmedia.pearsoncmg.com/imprint_downloads/informit/sams/sample_chapters/SAMS_CH05_0672327988.pdf)
19. [A Survey of Symbolic Execution Techniques (Baldoni et al., ACM Computing Surveys, author manuscript)](https://arxiv.org/pdf/1610.00502v3.pdf)
20. [Koushik Sen, Darko Marinov, Gul Agha (2005). CUTE: A Concolic Unit Testing Engine for C. .](https://doi.org/10.21236/ada482657)
21. [Cristian Cadar, Daniel Dunbar, Dawson Engler (2008). KLEE: unassisted and automatic generation of high-coverage tests for complex systems programs. .](https://doi.org/10.5555/1855741.1855756)
22. [Willem Visser, Corina S. Pǎsǎreanu, Sarfraz Khurshid (2004). Test input generation with java PathFinder. ACM SIGSOFT Software Engineering Notes.](https://doi.org/10.1145/1013886.1007526)
23. [Symbolic Execution for Software Testing in Practice – A Preliminary Assessment (Godefroid et al., ICSE 2011)](https://patricegodefroid.github.io/public_psfiles/icse2011.pdf)
24. [An Exploratory Survey of Hybrid Testing Techniques Involving Symbolic Execution and Fuzzing](https://ar5iv.labs.arxiv.org/html/1712.06843)
25. [Beyond Traditional Testing with Dynamic Analysis (CMU 17-313 course notes)](https://cmu-313.github.io/assets/pdfs/12-dynamic-analysis.pdf)
26. [Between Testing and Verification (Patrice Godefroid, Marktoberdorf 2015 lecture notes)](https://patricegodefroid.github.io/public_psfiles/marktoberdorf2015.pdf)
27. [On Narrowing the Gap between Verification and Systematic Testing (Christakis et al.)](https://mariachris.github.io/Pubs/IT-2017.pdf)
28. [Test case generation using large language models: a systematic literature review (Cluster Computing)](https://link.springer.com/article/10.1007/s10586-026-06021-z)
29. [Program Structure-aware Language Models: Targeted Software Testing beyond Textual Semantics (GLMTest, ACL Findings 2026)](https://aclanthology.org/2026.findings-acl.540.pdf)
30. [Wang, Zejun and colleagues (2024). HITS: High-coverage LLM-based Unit Test Generation via Method Slicing. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2408.11324)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software testing and quality

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/dynamic-testing

English original: https://www.edgepedia.org/dynamic-testing
