一句话:提出基于学习的测试 oracle,无需断言即可判定单元测试通过或失败。
测试 oracle 自动化是软件测试中的难点:传统 oracle 依赖能区分正确与缺陷行为的地面真值,而对精确正确或缺陷行为的假设使其不可判定且难以实现。本文提出一种学习型方法,在缺少断言或其他 oracle 时,通过将单元测试与被测方法实现联合嵌入统一向量空间,使测试与通过的 MUT 表示相似、与失败的 MUT 表示相异,并训练分类器作为 oracle 预测 pass/fail 标签。在 5K+ 个来自多样开源 Java 项目的单元测试上,该方法取得 93% 准确率、86% 精确率、94% 召回率和 90% F1;跨项目泛化性能几乎不下降,平均仅需 6.5 毫秒检测缺陷。通过解释神经模型,作者还验证了 oracle 依赖相关特征进行预测。
Automation of test oracles is one of the most challenging facets of software testing, but remains comparatively less addressed compared to automated test input generation. Test oracles rely on a ground-truth that can distinguish between the correct and buggy behavior to determine whether a test fails (detects a bug) or passes. What makes the oracle problem challenging and undecidable is the assumption that the ground-truth should know the exact expected, correct, or buggy behavior. However, we argue that one can still build an accurate oracle without knowing the exact correct or buggy behavior, but how these two might differ. This paper presents , a learning-based approach that in the absence of test assertions or other types of oracle, can determine whether a unit test passes or fails on a given method under test (MUT). To build the ground-truth, jointly embeds unit tests and the implementation of MUTs into a unified vector space, in such a way that the neural representation of tests are similar to that of MUTs they pass on them, but dissimilar to MUTs they fail on them. The classifier built on top of this vector representation serves as the oracle to generate “fail” labels, when test inputs detect a bug in MUT or “pass” labels, otherwise. Our extensive experiments on applying to more than 5K unit tests from a diverse set of open-source Java projects show that the produced oracle is (1) effective in predicting the fail or pass labels, achieving an overall accuracy, precision, recall, and F1 measure of 93%, 86%, 94%, and 90%, (2) generalizable, predicting the labels for the unit test of projects that were not in training or validation set with negligible performance drop, and (3) efficient, detecting the existence of bugs in only 6.5 milliseconds on average. Moreover, by interpreting the neural model and looking at it beyond a closed-box solution, we confirm that the oracle is valid, i.e., it predicts the labels through learning relevant features.