Flakify: A Black-Box, Language Model-Based Predictor for Flaky Tests

被引:22
作者
Fatima, Sakina [1 ]
Ghaleb, Taher A. [1 ]
Briand, Lionel [1 ,2 ]
机构
[1] Univ Ottawa, Sch EECS, Ottawa, ON K1N 6N5, Canada
[2] Univ Luxembourg, SnT Ctr Secur Reliabil & Trust, L-4365 Esch Sur Alzette, Luxembourg
基金
加拿大自然科学与工程研究理事会;
关键词
Flaky tests; software testing; black-box testing; natural language processing; CodeBERT;
D O I
10.1109/TSE.2022.3201209
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Software testing assures that code changes do not adversely affect existing functionality. However, a test case can be flaky, i.e., passing and failing across executions, even for the same version of the source code. Flaky test cases introduce overhead to software development as they can lead to unnecessary attempts to debug production or testing code. Besides rerunning test cases multiple times, which is time-consuming and computationally expensive, flaky test cases can be predicted using machine learning (ML) models, thus reducing the wasted cost of re-running and debugging these test cases. However, the state-of-the-art ML-based flaky test case predictors rely on pre-defined sets of features that are either project-specific, i.e., inapplicable to other projects, or require access to production code, which is not always available to software test engineers. Moreover, given the non-deterministic behavior of flaky test cases, it can be challenging to determine a complete set of features that could potentially be associated with test flakiness. Therefore, in this article, we propose Flakify, a black-box, language model-based predictor for flaky test cases. Flakify relies exclusively on the source code of test cases, thus not requiring to (a) access to production code (black-box), (b) rerun test cases, (c) pre-define features. To this end, we employed CodeBERT, a pre-trained language model, and fine-tuned it to predict flaky test cases using the source code of test cases. We evaluated Flakify on two publicly available datasets (FlakeFlagger and IDoFT) for flaky test cases and compared our technique with the FlakeFlagger approach, the best state-of-the-art ML-based, white-box predictor for flaky test cases, using two different evaluation procedures: (1) cross-validation and (2) per-project validation, i.e., prediction on new projects. Flakify achieved F1-scores of 79% and 73% on the FlakeFlagger dataset using cross-validation and per-project validation, respectively. Similarly, Flakify achieved F1-scores of 98% and 89% on the IDoFT dataset using the two validation procedures, respectively. Further, Flakify surpassed FlakeFlagger by 10 and 18 percentage points (pp) in terms of precision and recall, respectively, when evaluated on the FlakeFlagger dataset, thus reducing the cost bound to be wasted on unnecessarily debugging test cases and production code by the same percentages (corresponding to reduction rates of 25% and 64%). Flakify also achieved significantly higher prediction results when used to predict test cases on new projects, suggesting better generalizability over FlakeFlagger. Our results further show that a black-box version of FlakeFlagger is not a viable option for predicting flaky test cases.
引用
收藏
页码:1912 / 1927
页数:16
相关论文
共 69 条
[21]  
Guo CA, 2017, PR MACH LEARN RES, V70
[22]  
Guo D., 2021, PROC INT C LEARN REP, P1
[23]   Replication Study on the Usability of Code Vocabulary in Predicting Flaky Tests [J].
Haben, Guillaume ;
Habchi, Sarra ;
Papadakis, Mike ;
Cordy, Maxime ;
Le Traon, Yves .
2021 IEEE/ACM 18TH INTERNATIONAL CONFERENCE ON MINING SOFTWARE REPOSITORIES (MSR 2021), 2021, :219-229
[24]  
Hochreiter S, 1997, NEURAL COMPUT, V9, P1735, DOI [10.1162/neco.1997.9.1.1, 10.1007/978-3-642-24797-2]
[25]  
Howard J, 2018, PROCEEDINGS OF THE 56TH ANNUAL MEETING OF THE ASSOCIATION FOR COMPUTATIONAL LINGUISTICS (ACL), VOL 1, P328
[26]  
Husain H, 2020, Arxiv, DOI arXiv:1909.09436
[27]  
Jiang X, 2021, PR MACH LEARN RES, V161, P54
[28]  
Kanade A, 2020, PR MACH LEARN RES, V119
[29]   Does BERT Understand Code? - An Exploratory Study on the Detection of Architectural Tactics in Code [J].
Keim, Jan ;
Kaplan, Angelika ;
Koziolek, Anne ;
Mirakhorli, Mehdi .
SOFTWARE ARCHITECTURE (ECSA 2020), 2020, 12292 :220-228
[30]   Modeling and Ranking Flaky Tests at Apple [J].
Kowalczyk, Emily ;
Nair, Karan ;
Gao, Zebao ;
Silberstein, Leo ;
Long, Teng ;
Memon, Atif .
2020 IEEE/ACM 42ND INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING: SOFTWARE ENGINEERING IN PRACTICE (ICSE-SEIP), 2020, :110-119