# 一致性测试

一致性测试是一种测试方法，它通过运行由规范要求推导出的测试套件，并将观察到的行为与预期结果进行比较，来检查某个标准或规范的一项实现是否按要求行事以及行事的程度。ISO/IEC 9646 是 1991 年发布的基础方法论标准，它将一致性测试定义为：测试被测实现（IUT）在多大程度上是一项一致性实现。<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> 在实践中，规范可以是一份书面标准，其要求被逐条检查；也可以是一个形式化模型，例如标记迁移系统，测试用例从该模型自动生成。<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup> 该方法在协议工程中居于核心地位：对于通信产品而言，其主要目标是提高同一标准的不同实现之间能够互操作的概率。<sup>[3](https://www.etsi.org/deliver/etsi_i_ets/300400_300499/300406/01_60/ets_300406e01p.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 测试被测实现在多大程度上是一项一致性实现（ISO/IEC 9646，1991）<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> |
| 核心形式关系 | ioco：在规范的每一条迹之后，实现的输出（以及静止）必须在规范中是可能的<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup> |
| 判定 | 通过、失败和不确定，一种三值逻辑<sup>[4](https://www.etsi.org/deliver/etsi_etr/001_099/049/01_60/etr_049e01p.pdf)</sup> |
| 套件质量 | 可靠套件只检测不一致性；完备套件在几乎所有实际情形中都会是无限大的<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup> |
| 完备性代价 | m-完备的 FSM 测试套件随额外实现状态数 \( m - n \) 呈指数增长<sup>[5](https://arxiv.org/pdf/2410.19405)</sup> |
| 根本局限 | 测试检测的是错误的存在而非不存在，因此通过一个套件并不能证明一致性<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> |
| 旗舰应用 | 蓝牙资格认证、ETSI 协议测试和 NIST XML/DOM 测试套件<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/QPRD/out/en/index-en.html)</sup><sup> • </sup><sup>[3](https://www.etsi.org/deliver/etsi_i_ets/300400_300499/300406/01_60/ets_300406e01p.pdf)</sup><sup> • </sup><sup>[7](https://www.nist.gov/itl/ai/applied-ai-research-group/what-thing-called-conformance)</sup> |

## 工作原理

形式化方法建立在测试假设之上：假定每一个真实实现都有一个形式化模型，因此可以将实现作为形式对象来推理。<sup>[8](https://people.irisa.fr/Nicolas.Markey/PDF/Papers/cnISDNs29%281%29-Tre.pdf)</sup> 规范是一个模型，通常是标记迁移系统，而一致性是模型与实现所观察行为之间的一种实现关系。

有两种关系占据主导地位。**conf 关系**将观察限制在规范的迹之内：它要求实现做它应该做的事，而不要求它克制自己不去做不被允许的事。<sup>[8](https://people.irisa.fr/Nicolas.Markey/PDF/Papers/cnISDNs29%281%29-Tre.pdf)</sup> **ioco 关系**则通过同时观察阻塞来精化 conf，阻塞被建模为静止 \( \delta \)，即输出的缺失。<sup>[9](https://www.lri.fr/~longuet/Publications/PdLHL14-STVR.pdf)</sup> 形式上，当且仅当对于 S 的每一条迹 σ，都有 out(I after σ) ⊆ out(S after σ) 时，I ioco S 成立，其中静止通过 Δ 构造来处理。<sup>[10](https://cadp.inria.fr/ftp/publications/others/Desmoulin-Viho-07-a.pdf)</sup>

套件质量用三个术语来定义。如果一个实现恰好在其一致时通过套件，则该套件是**完备的**；如果否定判定意味着不一致，则该套件是**可靠的**；如果通过套件即保证一致性，则该套件是**穷尽的**。在几乎所有实际情形中，完备套件都会是无限大的，因此实际测试只限于可靠套件。<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup>

## 如何实施

从业者的工作流程源自 ISO 方法论。在测试之前，供应方需产出一份协议实现一致性声明（PICS），声明该标准的哪些能力和选项已被实现。<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> 测试本身是黑箱的：只考虑外部可见的行为，在控制与[观察](https://www.edgepedia.org/zh/observation)点发送输入抽象服务原语并观察输出原语。<sup>[4](https://www.etsi.org/deliver/etsi_etr/001_099/049/01_60/etr_049e01p.pdf)</sup>

在 ioco 框架中，测试用例是一个具有有限行为的确定性标记迁移系统，它在每个状态要么向实现提供一个特定输入，要么接受所有可能的输出，并在每个状态上附加通过或失败的判定。<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup> 测试推导通过三个递归选择进行：以通过终止、提供下一个输入，或检查下一个输出，同时为规范不允许的输出添加失败迁移，为允许的输出（包括静止）添加延续。<sup>[11](https://www.cis.upenn.edu/~lee/05cis700/papers/Tre99.pdf)</sup>

对于基于文档的标准，W3C 的方法为每项一致性要求标注一个唯一标识符及其 RFC 2119 关键词级别（必须、应该、可以、可选），从而使要求无需形式语言即可转换为测试用例。<sup>[12](http://www.w3c.org/TR/test-methodology/)</sup> [蓝牙](https://www.edgepedia.org/zh/bluetooth)测试用例同样带有一个预期结果部分：当所有详细通过标准都满足时，被测实现通过；一旦有一项标准无法满足，即告失败。<sup>[13](https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=173655)</sup>

## 起源

该方法论在 ISO/IEC 9646（1991）中得以标准化，这是一项由五部分组成的标准，定义了方法论、用于规定一致性测试套件的框架，以及 OSI 一致性测试期间应遵循的程序。<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> 同一方法论在 ITU-T X.290 系列建议书中也有定义，并应用于所有 ETSI 一致性测试规范<sup>[14](https://www.itu.int/rec/dologin_pub.asp?id=T-REC-X.Sup4-200809-I%21%21PDF-E&lang=f&type=items)</sup>；ETSI 自己的协议和轮廓一致性测试方法论直接建立在 ISO/IEC 9646 之上。<sup>[3](https://www.etsi.org/deliver/etsi_i_ets/300400_300499/300406/01_60/ets_300406e01p.pdf)</sup>

形式理论也同步发展。一致性通过死锁来定义：当且仅当在 I 中发生的死锁也在 S 中发生时，进程 I 才与进程 S 一致，并用为 S 定义的相同迹来测试<sup>[4](https://www.etsi.org/deliver/etsi_etr/001_099/049/01_60/etr_049e01p.pdf)</sup>；仅将观察建立在规范的迹之上则产生 conf 关系。<sup>[9](https://www.lri.fr/~longuet/Publications/PdLHL14-STVR.pdf)</sup> 在这一研究脉络中，ioco 关系及其测试生成算法被提出，其中每个生成的测试用例都是可靠的，而所有可能测试用例的集合是穷尽的。<sup>[2](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)</sup>

## 变体

**协议与轮廓测试。** ETSI 的方法论将 ISO/IEC 9646 扩展到针对协议、轮廓、信息对象、接口和服务的一致性测试规范，并建议每个协议只使用一个抽象测试套件，因为多个 ATS 实现成本更高，且会引发覆盖范围和测试结果等价性的问题。<sup>[3](https://www.etsi.org/deliver/etsi_i_ets/300400_300499/300406/01_60/ets_300406e01p.pdf)</sup>

**ioco 的基于模型的扩展。** ioco 测试理论已成为扩展的基于状态模型的标准基础，包括限制性迁移系统、符号迁移系统、时间自动机和多端口有限状态机。<sup>[9](https://www.lri.fr/~longuet/Publications/PdLHL14-STVR.pdf)</sup> 从输入-输出符号迁移系统（IOSTS）进行符号测试生成，允许以安全性和可能性属性作为观察者进行离线测试选择，比枚举式即时生成能更好地处理状态空间爆炸。<sup>[15](https://www.irisa.fr/vertecs/Publis/Ps/2007-IEEE-TSE.pdf)</sup>

**FSM 方法。** 对于有限状态机，W-方法构建一个 k-完备套件 \( T = A \cdot I^{\leq k+1} \cdot W \)，其中 \( A \) 是状态覆盖集，\( W \) 是特征集，\( I^{\leq k+1} \) 是所有长度至多为 k+1 的输入序列。<sup>[16](https://sws.cs.ru.nl/publications/papers/fvaan/ConformanceTestingApartness.pdf)</sup> 较老的迁移巡回方法测试每一条状态迁移，但不验证到达的新状态。<sup>[4](https://www.etsi.org/deliver/etsi_etr/001_099/049/01_60/etr_049e01p.pdf)</sup>

**基于 LLM 的测试。** 2025 年，孙希凯及其同事提出的智能体 iPanda 被报道为一个端到端框架，使用大语言模型来自动化协议一致性测试，从规范文档生成测试用例，并从实现生成可执行测试代码。<sup>[17](https://doi.org/10.48550/arxiv.2507.00378)</sup>

## 应用

**蓝牙资格认证。** 每个成员使用每项规范的实现一致性声明、包含配置详情的 IXIT、测试用例套件和测试用例参考列表来证明产品合规性。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/QPRD/out/en/index-en.html)</sup> 在某一层的套件中，能力（CA）测试依据 ICS 验证所声称的能力，有效行为（BV）测试在有效 PDU 之后验证一致性，无效行为（BI）测试在无效 PDU 之后验证一致性。<sup>[13](https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=173655)</sup>

**Web 与文档标准。** 有一个包含约 2000 个测试文件的 XML 处理器测试套件，以及 NIST DOM 测试套件，其中针对 DOM Level 1 有超过 800 个 [ECMAScript](https://www.edgepedia.org/zh/ecmascript) 测试和超过 200 个 Java 测试。<sup>[7](https://www.nist.gov/itl/ai/applied-ai-research-group/what-thing-called-conformance)</sup>

**信息物理系统。** 一种针对采样连续信号的可靠一致性测试方法已在 Matlab 中使用 CORA 工具箱实现，并在汽车空燃比控制系统上得到验证。<sup>[18](https://www.diva-portal.org/smash/get/diva2:1242186/FULLTEXT01.pdf)</sup>

## 局限与替代方案

**测试表明错误的存在，而非不存在。** ISO/IEC 9646 指出，测试无法保证一致性，因为它检测的是错误的存在而非不存在，而一致性是保证互通性的必要但不充分条件。<sup>[1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)</sup> NIST 将此描述为证伪策略：发现错误即证明不一致，但未发现错误并不能证明一致。<sup>[7](https://www.nist.gov/itl/ai/applied-ai-research-group/what-thing-called-conformance)</sup> 更一般地说，测试无法证明一项实现是一致的；它只能检测不一致性，因此验证与一致性测试是互补的。<sup>[15](https://www.irisa.fr/vertecs/Publis/Ps/2007-IEEE-TSE.pdf)</sup>

**定量局限。** 没有任何有限测试套件能对所有实现都是完备的：对于任何有限套件，一个实现可能在所有被测试的输入上表现得与规范一致，而在之后发生偏离。<sup>[16](https://sws.cs.ru.nl/publications/papers/fvaan/ConformanceTestingApartness.pdf)</sup> 因此，有保证的覆盖是相对于故障模型而言的，故障模型是为避免穷尽测试而引入的一种手段<sup>[19](https://www.site.uottawa.ca/~bochmann/Curriculum/Pub/1993%20-%20Conformance%20relations%20and%20test%20derivation.pdf)</sup>；即便如此，除非事先已知整个输入字母表和最小形式下的最大状态数，否则有限状态机无法通过黑箱测试被辨识。<sup>[19](https://www.site.uottawa.ca/~bochmann/Curriculum/Pub/1993%20-%20Conformance%20relations%20and%20test%20derivation.pdf)</sup> 对于 FSM，m-完备套件随 \( m - n \) 呈指数增长，因此只能在小数值下运行。<sup>[5](https://arxiv.org/pdf/2410.19405)</sup>

**其他失效模式。** ioco 不保持安全性属性：即使属性在规范上成立且实现与规范满足 ioco 一致性关系，实现仍可能违反这些属性。<sup>[15](https://www.irisa.fr/vertecs/Publis/Ps/2007-IEEE-TSE.pdf)</sup> 如果标准中未规定一致性的判定标准，就不可能存在一致性测试。<sup>[20](https://www.nist.gov/itl/ai/applied-ai-research-group/conformance-testing)</sup> 对于信息物理系统，时间和数值上的误差裕度必须与采样率协调，否则判定可能不可靠。<sup>[18](https://www.diva-portal.org/smash/get/diva2:1242186/FULLTEXT01.pdf)</sup>

**邻近活动。** [互操作性](https://www.edgepedia.org/zh/interoperability)测试与一致性测试不同，它没有被形式化定义，也没有精确的刻画<sup>[10](https://cadp.inria.fr/ftp/publications/others/Desmoulin-Viho-07-a.pdf)</sup>；两者是互补的，建议在测试互操作性之前先测试一致性。<sup>[14](https://www.itu.int/rec/dologin_pub.asp?id=T-REC-X.Sup4-200809-I%21%21PDF-E&lang=f&type=items)</sup> 确认（validation）是以规定方式使用官方测试套件执行一致性测试，而认证（certification）是对确认已完成且满足认证组织标准的认可。<sup>[7](https://www.nist.gov/itl/ai/applied-ai-research-group/what-thing-called-conformance)</sup>

## References

1. [ISO/IEC 9646-1:1991, OSI Conformance testing methodology and framework, Part 1](https://cdn.standards.iteh.ai/samples/17472/ebb7e17f48984202ba28336170ec8520/ISO-IEC-9646-1-1991.pdf)
2. [Test Generation with Inputs, Outputs and Nondeterminism (Jan Tretmans)](https://ris.utwente.nl/ws/files/6144406/276_Tre96.pdf)
3. [ETS 300 406 - MTS; Protocol and profile conformance testing specifications; Standardization methodology](https://www.etsi.org/deliver/etsi_i_ets/300400_300499/300406/01_60/ets_300406e01p.pdf)
4. [ETR 049, Advanced Testing Methods (ATM); State of research in the area of formal test specification methods (ETSI, October 1992)](https://www.etsi.org/deliver/etsi_etr/001_099/049/01_60/etr_049e01p.pdf)
5. [Solving Hennie's open problem about m-complete test suites (k-A-completeness)](https://arxiv.org/pdf/2410.19405)
6. [Bluetooth Qualification Program Reference Document (QPRD)](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/QPRD/out/en/index-en.html)
7. [What is this thing called Conformance? (NIST)](https://www.nist.gov/itl/ai/applied-ai-research-group/what-thing-called-conformance)
8. [cnISDNs29(1) Tre (people.irisa.fr)](https://people.irisa.fr/Nicolas.Markey/PDF/Papers/cnISDNs29%281%29-Tre.pdf)
9. [Model Based Testing for Concurrent Systems with Labeled Event Structures (Ponce-de-León, Longuet et al., STVR)](https://www.lri.fr/~longuet/Publications/PdLHL14-STVR.pdf)
10. [A New Method for Interoperability Test Generation (Desmoulin & Viho)](https://cadp.inria.fr/ftp/publications/others/Desmoulin-Viho-07-a.pdf)
11. [Testing Concurrent Systems: A Formal Approach (Tretmans, 1999)](https://www.cis.upenn.edu/~lee/05cis700/papers/Tre99.pdf)
12. [A Method for Writing Testable Conformance Requirements (W3C)](http://www.w3c.org/TR/test-methodology/)
13. [Bluetooth Test Suite Structure (TSS) and test cases for the Bluetooth RF layer](https://www.bluetooth.org/docman/handlers/DownloadDoc.ashx?doc_id=173655)
14. [ITU-T X-series Supplement 4 (09/2008) - Interoperability testing with conformance testing](https://www.itu.int/rec/dologin_pub.asp?id=T-REC-X.Sup4-200809-I%21%21PDF-E&lang=f&type=items)
15. [Conformance Testing for Reactive Systems (IEEE TSE, 2007)](https://www.irisa.fr/vertecs/Publis/Ps/2007-IEEE-TSE.pdf)
16. [A New Perspective on Conformance Testing Based on Apartness](https://sws.cs.ru.nl/publications/papers/fvaan/ConformanceTestingApartness.pdf)
17. [Sun, Xikai and colleagues (2025). iPanda: An LLM-based Agent for Automated Conformance Testing of Communication Protocols. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2507.00378)
18. [Sound conformance testing for cyber-physical systems: Theory and implementation](https://www.diva-portal.org/smash/get/diva2:1242186/FULLTEXT01.pdf)
19. [Conformance relations and test derivation (Bochmann et al., 1993)](https://www.site.uottawa.ca/~bochmann/Curriculum/Pub/1993%20-%20Conformance%20relations%20and%20test%20derivation.pdf)
20. [Conformance Testing | NIST](https://www.nist.gov/itl/ai/applied-ai-research-group/conformance-testing)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 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/conformance-testing

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