Writing Tests for This Higher-Order Function First: Automatically Identifying Future Callings to Assist Testers

Writing Tests for This Higher-Order Function First: Automatically Identifying Future Callings to Assist Testers
复制标题

DOI:
10.1145/3361242.3361256
复制
发表时间:
2019-10
期刊:
Proceedings of the 11th Asia-Pacific Symposium on Internetware
影响因子:
--
通讯作者:
Yisen Xu;Xiangyang Jia;J. Xuan
Yisen Xu;Xiangyang Jia;J. Xuan
中科院分区:
其他
文献类型:
--
作者:
Yisen Xu;Xiangyang Jia;J. Xuan

文献摘要

被引文献

相似文献

在函数式编程语言(例如 Scala 和 Haskell)中,高阶函数是一种接受一个或多个函数作为参数或返回一个函数的函数。在程序中使用高阶函数可以增加通用性,减少源代码的冗余。为了测试高阶函数,测试人员需要检查需求并编写另一个函数作为测试输入。然而,由于高阶函数的复杂性,测试高阶函数是一项耗时耗力的任务。测试人员必须花费大量的手动工作来测试所有高阶函数。如果时间预算有限,例如项目发布前的一段时间,这样的测试是不可行的。在本文中,我们提出了一种自动方法,即 PHOF,它预测将来是否会调用高阶函数。应首先测试最有可能被调用的高阶函数。我们的方法可以帮助开发人员减少测试中的高阶函数的数量。在 PHOF 中,我们从源代码和日志中提取了 24 个特征,以训练基于已知高阶函数调用的预测模型。我们对来自 6 个现实 Scala 项目的 2854 个高阶函数进行了实证评估。实验结果表明,基于随机森林算法和SMOTE策略的PHOF在高阶函数调用的预测方面表现良好。我们的工作可以用来支持有限测试资源的调度。
In functional programming languages, such as Scala and Haskell, a higher-order function is a function that takes one or more functions as parameters or returns a function. Using higher-order functions in programs can increase the generality and reduce the redundancy of source code. To test a higher-order function, a tester needs to check the requirements and write another function as the test input. However, due to the complexity of higher-order functions, testing higher-order functions is a time-consuming and labor-intensive task. Testers have to spend an amount of manual effort in testing all higher-order functions. Such testing is infeasible if the time budget is limited, such as a period before a project release. In this paper, we propose an automatic approach, namely PHOF, which predicts whether a higher-order function will be called in the future. Higherorder functions that are most likely to be called should be tested first. Our approach can assist developers to reduce the number of higherorder functions under test. In PHOF, we extracted 24 features from source code and logs to train a predictive model based on known higher-order functions calls. We empirically evaluated our approach on 2854 higher-order functions from six real-world Scala projects. Experimental results show that PHOF based on the random forest algorithm and the SMOTE strategy performs well in the prediction of calls of higher-order functions. Our work can be used to support the scheduling of limited test resources.