Mining unit test cases to synthesize API usage examples

被引:5
作者
Ghafari, Mohammad [1 ]
Rubinov, Konstantin [2 ]
Pourhashem K, Mohammad Mehdi [2 ]
机构
[1] Univ Bern, Software Composit Grp, Bern, Switzerland
[2] Politecn Milan, DeepSE Grp, Milan, Italy
基金
瑞士国家科学基金会;
关键词
API usage examples; code mining; traceability; unit test cases; TRACEABILITY;
D O I
10.1002/smr.1841
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Software developers study and reuse existing source code to understand how to properly use application programming interfaces (APIs). However, manually finding sufficient and adequate code examples for a given API is a difficult and a time-consuming activity. Existing approaches to find or generate examples assume availability of a reasonable set of client code that uses the API. This assumption does not hold for newly released API libraries, non-widely used APIs, nor private ones. In this work we reuse the important information that is naturally present in test code to circumvent the lack of usage examples for an API when other sources of client code are not available. We propose an approach for automatically identifying the most representative API uses within each unit test case. We then develop an approach to synthesize API usage examples by extracting relevant statements representing the usage of such APIs. We compare the output of a prototype implementation of our approach to both human-written examples and to a state-of-the-art approach. The obtained results are encouraging; the examples automatically generated with our approach are superior to the state-of-the-art approach and highly similar to the manually constructed examples.
引用
收藏
页数:19
相关论文
共 37 条
[1]  
AMINTABAR V, 2015, EXCEPTIONTRACER A SO, P299, DOI DOI 10.1109/ICPC.2015.45
[2]   API Code Recommendation using Statistical Learning from Fine-Grained Changes [J].
Anh Tuan Nguyen ;
Hilton, Michael ;
Codoban, Mihai ;
Hoan Anh Nguyen ;
Mast, Lily ;
Rademacher, Eli ;
Nguyen, Tien N. ;
Dig, Danny .
FSE'16: PROCEEDINGS OF THE 2016 24TH ACM SIGSOFT INTERNATIONAL SYMPOSIUM ON FOUNDATIONS OF SOFTWARE ENGINEERING, 2016, :511-522
[3]  
BUSE RPL, 2012, SYNTHESIZING API USA, P782
[4]  
Chatterjee S, 2009, LECT NOTES COMPUT SC, V5503, P385
[5]  
DAGENAIS B, 2012, RECOVERING TRACEABIL, P47
[6]  
De Souza LB., 2014, P 22 INT C PROGR COM, P72, DOI DOI 10.1145/2597008.2597146
[7]  
DENARO G, 2015, DYNAMIC DATA FLOW TE, P947, DOI DOI 10.1109/ICSE.2015.104
[8]  
GALENSON J, 2014, CODEHINT DYNAMIC AND, P653, DOI DOI 10.1145/2568225.2568250
[9]  
Gallagher M., 2005, POLITICS ELECTORAL S, P1, DOI [10.1093/0199257566.001.0001, DOI 10.1093/0199257566.001.0001]
[10]  
GHAFARI M, 2015, AUTOMATICALLY IDENTI, P61