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

Published in Proceedings of the 11th Asia-Pacific Symposium on Internetware (Internetware ’19), October 28–29, 2019, Fukuoka, Japan., 2019


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. Higher- order functions that are most likely to be called should be tested first. Our approach can assist developers to reduce the number of higher- order 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.

Download paper here