Asynchronous waits are one of the most prevalent root causes of flaky tests and a major time-influential factor of web application testing. To investigate the characteristics of asynchronous wait flaky tests and their fixes in web testing, we build a dataset of 49 reproducible flaky tests, from 26 open-source projects, caused by asynchronous waits, along with their corresponding developer-written fixes. Our study of these flaky tests reveals that in approximately 63% of them (31 out of 49), developers addressed Asynchronous Wait flaky tests by adapting the wait time, even for cases where the root causes lie elsewhere. Based on this finding, we propose TRaf, an automated time-based repair method for asynchronous wait flaky tests in web applications. TRaf tackles the flakiness issues by suggesting a proper waiting time for each asynchronous call in a web application, using code similarity and past change history. The core insight is that as developers often make similar mistakes more than once, hints for the efficient wait time exist in the current or past codebase. Our analysis shows that TRaf can suggest a shorter wait time to resolve the test flakiness compared to developer-written fixes, reducing the test execution time by 11.1%. With additional dynamic tuning of the new wait time, TRaf further reduces the execution time by 20.2%.
翻译:异步等待是导致脆性测试的最常见根因之一,也是影响Web应用测试耗时的主要因素。为探究Web测试中异步等待类脆性测试的特性及其修复模式,我们从26个开源项目中构建了包含49个由异步等待引发的可复现脆性测试及其开发者编写修复方案的数据集。研究发现,约63%(31/49)的脆性测试中,开发者通过调整等待时间来解决异步等待问题——即便在部分案例中根本原因存在于其他环节。基于此发现,我们提出TRaf——一种面向Web应用中异步等待脆性测试的自动化时间修复方法。该方法通过代码相似度分析与历史变更记录,为Web应用的每次异步调用建议合适的等待时间。其核心洞见在于:由于开发者常重复同类错误,当前或历史代码库中已隐含着有效等待时间的线索。实验表明,相比开发者编写的修复方案,TRaf可建议更短的等待时间以解决测试脆性问题,使测试执行时间减少11.1%。结合新等待时间的动态调优后,TRaf进一步将执行时间降低20.2%。