Given, When, Then, Again: Mining Subscenario Refactoring Candidates in Behaviour-Driven Test Suites with ML Classifiers and LLM-Judge Baselines
作者: Ali Hassaan Mughal, Noor Fatima, Muhammad Bilal
分类: cs.SE, cs.CL, cs.LG
发布日期: 2026-06-12
💡 一句话要点
提出一种基于机器学习的BDD测试套件子场景重构候选挖掘方法
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 行为驱动开发 测试重构 机器学习 聚类分析 分类器 软件工程 自动化测试
📋 核心要点
- 现有BDD测试套件中存在大量重复的步骤子序列,缺乏有效的自动化重构方法。
- 提出一种基于机器学习的框架,通过聚类和分类技术识别和评估重构候选。
- 实验结果表明,所提分类器在重构适用性评估中表现优异,F1值达到0.891,显著优于其他基线。
📝 摘要(中文)
背景:行为驱动开发(BDD)测试套件中存在重复的步骤子序列。已有三种重构模式,但缺乏自动化提取和适用机制的研究。目标:对重复步骤子序列进行重构适用性排名,并映射到三种模式,量化其在公共BDD生态系统中的普遍性。方法:在339个仓库的Gherkin语料库中,使用SBERT、UMAP和HDBSCAN聚类技术识别等价的子序列。通过XGBoost分类器评估重构适用性,结果显示分类器的F1值为0.891,优于基线模型和大型语言模型评估者。结论:该研究提供了BDD重构候选的全面调查,相关数据和工具已开放发布。
🔬 方法详解
问题定义:论文旨在解决BDD测试套件中重复步骤子序列的自动化重构问题。现有方法未能有效识别哪些子序列值得提取,以及适用的重构机制。
核心思路:通过对Gherkin语料库中的步骤子序列进行聚类和分类,评估其重构适用性,并将其映射到已有的重构模式中。此设计旨在提高BDD测试的可维护性和重用性。
技术框架:整体流程包括数据收集、步骤子序列的聚类(使用SBERT、UMAP和HDBSCAN)、标注和分类(使用XGBoost),最终输出重构候选的统计数据。
关键创新:该研究首次实现了BDD测试套件中重复步骤子序列的自动化挖掘与评估,提供了系统化的重构候选识别方法,显著提升了重构效率。
关键设计:采用5折交叉验证训练XGBoost分类器,使用F1值作为评估指标,确保模型的泛化能力和准确性。聚类过程中使用的参数设置经过调优,以提高聚类效果。
🖼️ 关键图片
📊 实验亮点
实验结果显示,所提分类器的F1值达到0.891,显著优于规则基线的0.836和大型语言模型评估者的0.728,表明该方法在重构候选识别中的有效性和准确性。
🎯 应用场景
该研究的成果可广泛应用于软件开发中的BDD测试优化,帮助开发者自动识别和重构重复的测试步骤,提高测试用例的可维护性和重用性。未来,随着BDD实践的普及,该方法有望在更大规模的项目中发挥重要作用。
📄 摘要(原文)
Context. Behaviour-Driven Development (BDD) test suites accumulate duplicated step subsequences. Three published refactoring patterns are available (within-file Background, within-repo reusable-scenario invocation, cross-organisational shared higher-level step), but no prior work automates which recurring subsequences are worth extracting or which mechanism applies. Objective. Rank recurring step subsequences ("slices") by refactoring suitability (extraction-worthy), pre-map each to one of the three patterns, and quantify prevalence across the public BDD ecosystem. Method. Every contiguous L-step window (L in [2, 18]) in a 339-repository / 276-upstream-owner Gherkin corpus is keyed by paraphrase-robust cluster identifiers and counted under three scopes. SBERT / UMAP / HDBSCAN clustering recovers paraphrase-equivalent slices. Three authors label a stratified 200-slice pool against a written rubric. An XGBoost extraction-worthy classifier trained under 5-fold cross-validation is compared with a tuned rule baseline and two open-weight Large Language Model (LLM) judges. Results. The miner produces 5,382,249 slices collapsing to 692,020 recurring patterns. Three-author Fleiss' kappa = 0.56 (extraction-worthy) and 0.79 (mechanism). The classifier reaches out-of-fold F1 = 0.891 (95% CI [0.852, 0.927]), outperforming both the rule baseline (F1 = 0.836, p = 0.017) and the better LLM judge (F1 = 0.728, p = 1.5e-4). 75.0%, 59.5%, and 11.7% of scenarios carry a within-file Background, within-repo reusable-scenario, and cross-organisational shared-step candidate, respectively; the figures are stable under a sweep of the classifier decision threshold. Conclusion. Paraphrase-robust subscenario discovery yields a corpus-wide census of BDD refactoring candidates; pipeline, classifier predictions, labelled pool, and rubric are released under Apache-2.0.