作者 | 孙海英 华东师范大学软件工程学院讲师
苏亭 华东师范大学软件工程学院教授
01
概述
02
方法说明
2.1 分支函数
其中,E1和E2是算术表达式。我们将简单的关系表达式称为分支表达式。为了覆盖分支,可以采用最优化方法计算使得分支表示式判定结果为真时的输入数据。具体地说,结合最优化理论中成本函数的含义可知,以分支覆盖为目标的成本函数如果构造为能够衡量候选输入与期望覆盖分支之间的远近,那么,其中距离最近的输入即为分支表达式的解。基于此,Korel定义了分支函数:
不同形式的分支表达式有不同形式的分支函数,如表1所示。分支函数具有如下特性:
表1 Korel定义的分支函数
为了说明SBST的主要思想,图1给出了能够覆盖示例代码中某条路径(10-11-12-13)的测试输入的搜索计算过程。需要说明的是,为了清晰简便,示例采用了最基本的直接搜索算法,不包含对搜索过程的优化方法,也不包含计算测试预期结果(Test Oracle)的方法。现代的SBST方法采用的搜索优化算法和成本函数远先进和复杂于示例中的方法。
03
主流方法
搜索最优解的算法和成本函数的构造是SBST的核心技术。常用的搜索最优解的算法有爬山算法、模拟退火算法和遗传算法。爬山算法、模拟退火属于局部搜索策略,因为这两种方法每次只考虑一个答案,且只在答案的受限毗邻区附近移动,遗传算法则属于全局搜索,同时考察搜索域中多个样本点,是当前SBST的主流。图3给出了基于遗传算法的SBST的主要流程。
图2 基于遗传算法的SBST主要流程
04
主要挑战
[1] W. Miller and D. Spooner, “Automatic generation of floatingpoint test data,” IEEE Transactions on Software Engineering, vol. 2, no. 3, pp. 223–226, 1976.
[2] B. Korel, “Automated software test data generation,” IEEE Transactions on Software Engineering, vol. 16, no. 8, pp. 870–879, 1990.
[3] Phil McMinn. Search-Based Software Testing: Past, Present and Future. Proceedings - 4th IEEE International Conference on Software Testing, Verification, and Validation Workshops, 153 – 163, 2011.
[4] J. Wegener, A. Baresel, and H. Sthamer, “Evolutionary test environment for automatic structural testing,” Information and Software Technology, vol. 43, no. 14, pp. 841–854, 2001.
[5] N. Tracey, J. Clark, K. Mander, and J. McDermid, “An automated framework for structural test-data generation,” in Proceedings of the International Conference on Automated Software Engineering. Hawaii, USA: IEEE Computer Society Press, 1998, pp. 285–288.
[6] A. Arcuri, “It does matter how you normalise the branch distance in search based software testing,” in Proceedings of the International Conference on Software Testing, Verification and Validation. IEEE, to appear, 2010.
[7] A. Panichella, "Beyond Unit-Testing in Search-Based Test Case Generation: Challenges and Opportunities," 2019 IEEE/ACM 12th International Workshop on Search-Based Software Testing (SBST), pp. 7-8, 2019.
[8] A. Arcuri, G. Fraser, and J. P. Galeotti. Automated unit test generation for classes with environment dependencies. In IEEE/ACM International Conference on Automated Software Engineering (ASE), pages 79–90, 2014.
[9] A. Arcuri, G. Fraser and R. Just, "Private API Access and Functional Mocking in Automated Unit Test Generation," 2017 IEEE International Conference on Software Testing, Verification and Validation (ICST), pp. 126-137, 2017.
1. 浅谈软件测试
2. 测试的充分性问题
3. 浅谈随机测试
已完成
数据加载中