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%(49例中的31例)的异步等待不稳定测试中,开发者通过调整等待时间进行修复,即使根本原因在于其他方面。基于这一发现,我们提出TRaf——一种面向Web应用中异步等待不稳定测试的自动化基于时间修复方法。TRaf通过代码相似性和历史变更记录为Web应用中的每次异步调用建议合适的等待时间,从而解决不稳定性问题。其核心思路在于:由于开发者常重复犯同类错误,当前或历史代码库中已存在高效等待时间的线索。分析表明,与开发者编写的修复方案相比,TRaf能建议更短的等待时间以解决测试不稳定性,使测试执行时间减少11.1%。通过进一步对新增等待时间进行动态调整,TRaf可将执行时间再降低20.2%。