程序不变量可以揭示程序的内部属性和动态执行情况,已经成功应用于软件测试用例的生成与约简。然而,每新增一个用例都要在整个测试用例集合上重新提取程序不变量,时间开销较大。提出一种基于正则表达式的将程序不变量自动转换为对应断言的方法,并利用断言判断新用例是否冗余,仅当新用例非冗余时才提取程序不变量,从而大幅度减小时间开销。将这种基于断言的测试方法应用于回归测试,可以有效约简测试用例集合,识别程序改动所影响的元素,进而发现潜在的程序错误。实验结果表明,与其它测试用例选择方法相比,该方法时间消耗小、测试用例集合约简率高、揭错能力强。
Program invariants,which can reveal internal properties and dynamic execution situations of the program,have been successfully applied to generation and reduction of software test case.However,the program invariants have to be re-extracted from entire test suite for every new test case added,this causes a heavy time cost.This paper proposes a novel method to automatically convert program invariants into corresponding assertions,which is based on regular expression.Assertions are used to judge whether a new test case is the redundancy,this saves a great deal of time since the program invariants are re-extracted only when the new test case is not the redundant one.Applying this assertion-based testing method to regression test,the test suite can be effectively reduced,and the elements affected by the program modification can be identified,thus the latent program errors can be further found as well.Experiment results show that compared with other test case selection techniques,the method proposed in the paper costs less time and has a higher test suite reduction rate and stronger errors exposing ability.