
基于深度强化学习的类集成测试序列生成方法
Generation Method of Class Integration Test Order Based on Deep Reinforcement Learning
类集成测试序列的生成是面向对象软件测试中的关键步骤,当类的测试序列不同时,相应的测试代价也不相同.在集成测试中生成一个合理的类集成测试序列可以有效降低软件测试的代价.本文将深度强化学习中的Advantage Actor-Critic算法应用于解决类集成测试序列生成问题.首先,利用类间各种依赖关系构建与智能体交互的环境模型;然后,记录智能体从初始状态到终止状态的路径,即每次选择的动作对应每次选择集成到序列的类编号;最后,得出最终的类集成测试序列.实验结果表明,本文方法所得到的类集成测试序列花费的总体测试桩复杂度,在选取的7个项目中有5个表现最佳,在剩余2个项目中表现中等.
The generation of class integration test order is the key step in object-oriented software testing. When the class integration test order is different, the corresponding test cost is different. Generating a reasonable class integration test order in integration testing can effectively reduce the cost of software testing. This paper applies the advantage actor-critic algorithm in deep reinforcement learning to solve the problem of class integration test order generation. Firstly, the environment model of interaction with agents is constructed by using various dependencies between classes. Then, the path of the agent from the initial state to the termination state is recorded, that is, each selected action corresponds to each selected class number integrated into the order. Finally, the final class integration test order is obtained. The experimental results show that the total test stubs complexity of class integration test order cost obtained by the method in this paper has the best performance in 5 out of 7 selected subjects, and the average performance in the remaining 2 subjects.
集成测试 / 测试序列 / 深度强化学习 / advantage actor-critic / 测试桩复杂度 {{custom_keyword}} /
integration test / test order / deep reinforcement learning / advantage actor-critic / complexity {{custom_keyword}} /
表1 elevator 各类编号 |
类编号 | 类名称 | 类编号 | 类名称 |
---|---|---|---|
0 | Building | 6 | ElevatorState |
1 | DoorClosedException | 7 | Floor |
2 | Elevator | 8 | Logger |
3 | ElevatorController | 9 | Person |
4 | ElevatorFullException | 10 | PersonState |
5 | ElevatorMovingException | 11 | Simulator |
表2 elevator 属性依赖和方法依赖 |
类编号 | 0 | 2 | 3 | 7 | 9 | 11 |
---|---|---|---|---|---|---|
0 | - | - | - | - | (2,3) | (0,2) |
1 | - | (0,2) | - | - | - | - |
2 | - | - | (4,33) | (2,2) | (2,9) | - |
3 | (1,7) | (2,1) | - | (2,2) | - | - |
4 | - | (0,1) | - | - | - | - |
5 | - | (0,2) | - | - | - | - |
6 | (1,2) | (1,0) | (1,0) | - | - | - |
7 | (2,2) | - | (1,15) | - | (1,10) | - |
8 | - | (1,24) | (1,27) | (1,9) | (1,4) | - |
9 | - | (2,1) | (2,2) | (3,9) | - | (0,4) |
10 | - | (0,2) | - | - | (1,2) | - |
表3 elevator 耦合代价矩阵 |
类编号 | 0 | 2 | 3 | 7 | 9 | 11 |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0.359 | 0.043 |
1 | 0 | 0.043 | 0 | 0 | 0 | 0 |
2 | 0 | 0 | 1 | 0.356 | 0.403 | 0 |
3 | 0.232 | 0.354 | 0 | 0.356 | 0 | 0 |
4 | 0 | 0.021 | 0 | 0 | 0 | 0 |
5 | 0 | 0.043 | 0 | 0 | 0 | 0 |
6 | 0.177 | 0.182 | 0.177 | 0 | 0 | 0 |
7 | 0.356 | 0 | 0.367 | 0 | 0.278 | 0 |
8 | 0 | 0.544 | 0.605 | 0.262 | 0.197 | 0 |
9 | 0 | 0.354 | 0.356 | 0.564 | 0 | 0.086 |
|
---|
输入: 类间属性依赖Attr_Deps, 类间方法依赖Meth_Deps, 迭代次数T, 状态特征维数n, 动作集合A, 折扣因子γ, 当前网络 |
输出: 测试顺序的最低成本 |
构建代价耦合矩阵 |
随机初始化当前 |
FOR episode = 1, |
将 |
初始化状态 |
初始化环境 |
WHILE NOT |
将 |
得到其对应所有动作的 |
以 |
在状态 |
将 |
IF t |
从 |
计算出当前网络的Q值 |
|
|
更新策略网络 |
|
更新价值网络 |
|
IF |
更新目标网络参数 |
END IF |
IF |
记录智能体动作轨迹以及总体测试桩复杂度 |
|
END IF |
END WHILE |
IF |
|
|
END IF |
END FOR |
表5 项目详细信息 |
System | Description | Classes | Deps | Cycles | LOC |
---|---|---|---|---|---|
ANT | 部署工具 | 25 | 83 | 654 | 4 093 |
ATM | 自动柜员机系统 | 21 | 67 | 30 | 1 390 |
SPM | 安全巡逻监视项目 | 19 | 72 | 1 178 | 1 198 |
DNS | 域名解析系统 | 61 | 276 | 16 | 6 710 |
daisy | 网络文件系统 | 23 | 36 | 4 | 1 148 |
email-spl | 电子邮件工具 | 39 | 64 | 38 | 2 276 |
BCEL | 创建、分析、操作Java类文件的插桩工具 | 45 | 294 | 416 091 | 3 033 |
表6 参数设置 |
参数 | 含义 | 值 | 参数 | 意义 | 值 |
---|---|---|---|---|---|
WA | 属性权重 | 0.5 | | | 1 |
WM | 方法权重 | 0.5 | | | 0.01 |
γ | 折扣率 | 0.8 | T | 训练次数 | 200 000 |
c | 奖励倍数 | 10 000 | batch_size | 批处理单位 | 64 |
min_value | 最大惩罚 | -150 000 | | | 1 000 |
max_value | 最大奖励 | 150 000 | - | - | - |
表7 总体测试桩复杂度对比表 |
Category | Method | ANT | ATM | SPM | DNS | daisy | email-spl | BCEL |
---|---|---|---|---|---|---|---|---|
Graph | Le Traon | 3.72 | 3.37 | 8.4 | 5.02 | - | - | 8.23 |
Tai | 3.87 | 2.99 | 8.08 | 4.63 | - | - | 8.68 | |
Briand | 3.31 | 2.7 | 5.82 | 1.51 | - | - | 8.58 | |
Heuristic | GA | 3.64 | 2.68 | 5.77 | 7.15 | 2.63 | 1.56 | 13.70 |
RIA | 2.32 | 2.39 | 3.25 | 8.56 | 0.33 | 0.95 | 7.95 | |
PSO | 2.25 | 2.53 | 3.01 | 5.82 | 0.90 | 1.04 | 8.59 | |
RL | DRL | 1.479 5 | 2.052 | 4.028 3 | 3.409 1 | 0.192 8 | 0.52 | 7.105 1 |
表8 特定测试桩个数对比表 |
Category | Method | ANT | ATM | SPM | DNS | daisy | email-spl | BCEL |
---|---|---|---|---|---|---|---|---|
Graph | Le Traon | 18 | 9.1 | 24.7 | 11 | - | - | 67.5 |
Tai | 28 | 8 | 20.2 | 27 | - | - | 128 | |
Briand | 11 | 7 | 17 | 6 | - | - | 70 | |
Heuristic | GA | 12 | 7 | 17 | 6 | 12 | 27 | 71 |
RIA | 14.97 | 7.43 | 12.77 | 20.07 | 6 | 15 | 53.60 | |
PSO | 14.33 | 7.83 | 12.07 | 17.33 | 8 | 19 | 55.47 | |
RL | RL | 19.33 | 7.33 | 21.33 | 14.33 | 4.13 | 11.07 | 88.33 |
DRL | 19 | 18 | 19 | 32 | 4 | 13 | 93 |
表9 通用测试桩个数 |
ANT | ATM | SPM | DNS | daisy | email-spl | BCEL | |
---|---|---|---|---|---|---|---|
DRL | 11.33 | 14 | 17.33 | 22.5 | 4 | 12 | 18.34 |
表10 通用测试桩详细信息 |
项目名称 | 通用测试桩信息 |
---|---|
ANT | 1:BuildEvent,3:BuildListener,14:PathTokenizer,16:ProjectComponent,19:Target,20:Task,21:TaskAdapter,17:ProjectHelper,22:TaskContainer,23:UnknownElement,4:BuildLogger |
ATM | 0:ReceiptPrinter,1:Display,2:Keyboard,3:CardReader,4:OperatorPanel,5:EnvelopeAcceptor,6:CashDispenser,8:Bank,9:Session,10:Transaction,11:WithdrawlTransaction,12:DepositTransaction,13:TransferTransaction,14:InquiryTransaction |
SPM | 3:CheckpointControllerIdleState,4:CheckpointControllerNormalCheckingState,5:CheckpointControllerState,6:CheckpointControllerViolationCheckingState,7:CheckpointControllerViolationState,8:CheckpointReferences,0:CardReaderInterface,12:DoorLockInterface,13:GuardDueTimer,14:GuardLateTimer,15:PatrolSchedule,18:SecurityZone |
DNS | 4:BitString,7:Compression,10:DNAMERecord,27:Options,48:WireParseException,31:Record,54:Message,60:ResolverListener,6:CNAMERecord,34:RRset,43:TTL,9:DClass,14:Flags,26:Opcode,28:OPTRecord,42:TSIGRecord,52:Header,47:UNKRecord,11:dns,55:MX_KXRecord,37:SimpleResolver,51:ExtendedResolver,21:NameSet |
Daisy | 17:util.Debug,1:daisy.Daisy,21:util.SplitPrintStream,14:DaisyUserThread |
email-spl | 2:defpackage.PL_Interface,3:defpackage.PL_Interface_impl,8:EmailSystem.Client,24:runspl.RunSPL,16:featuremodel.FeatureID,14:featuremodel.Configuration,21:featuremodel.RelevantModelIterator,7:EmailSystem.ClientKeyringEntry,36:TestSpecifications.SpecificationManager,13:featuremodel.Configuration1,34:TestSpecifications.Specification9 |
BCEL | 7:ConstantCP,44:Visitor,5:Constant,16:ConstantObject,17:ConstantPool,1:Attribute,35:Node,10:ConstantFloat,11:ConstantInteger,12:ConstantInterfaceMethodref,15:ConstantNameAndType,0:AccessFlags,25:Field,34:Method,20:ConstantValue,21:Deprecated,36:PMGClass,37:Signature |
1 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
2 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
3 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
4 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
5 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
6 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
7 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
8 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
9 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
10 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
11 |
张艳梅, 姜淑娟, 张红昌. 一种基于动态依赖关系的类集成测试方法[J]. 计算机学报, 2011(6): 1075-1089.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
12 |
张艳梅. 基于依赖性分析的面向对象程序测试技术研究[D]. 徐州: 中国矿业大学, 2012.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
13 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
14 |
郑磊. 面向对象集成测试的分层增量测试策略[D]. 上海: 上海交通大学, 2007.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
15 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
16 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
17 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
18 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
19 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
20 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
21 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
22 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
23 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
24 |
刘颖莲. 面向对象软件集成测试策略研究[D]. 北京: 北京邮电大学, 2013.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
25 |
赵玉丽, 王莹, 于海 等. 基于复杂网络的类间集成测试序列生成方法[J]. 东北大学学报(自然科学版), 2015, 36(12): 1696-1700.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
26 |
王莹, 于海, 朱志良. 基于软件节点重要性的集成测试序列生成方法[J]. 计算机研究与发展, 2016, 53(3): 517-530.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
27 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
28 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
29 |
黄志清, 曲志伟, 张吉, 等. 基-于深度强化学习的端到端无人驾驶决策[J]. 电子学报, 2020, 48(9): 1711-1719.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
30 |
刘春阳, 谭应清, 柳长安, 等. 多智能体强化学习在足球机器人中的研究与应用[J]. 电子学报, 2010, 38(8): 1958-1962.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
31 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
32 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
33 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
34 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
35 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
36 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
37 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
38 |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
39 |
张悦宁, 姜淑娟, 张艳梅. 基于梦境粒子群优化的类集成测试序列生成方法[J]. 计算机科学, 2019, 46(2): 168-174.
{{custom_citation.content}}
{{custom_citation.annotation}}
|
{{custom_ref.label}} |
{{custom_citation.content}}
{{custom_citation.annotation}}
|
/
〈 |
|
〉 |