An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generation

计算机科学 单元测试 正确性 文档 JavaScript 考试(生物学) 自动化 人工智能 软件 软件工程 机器学习 程序设计语言 机械工程 生物 工程类 古生物学
作者
Max Schäfer,Sarah Nadi,Aryaz Eghbali,Frank Tip
出处
期刊:IEEE Transactions on Software Engineering [IEEE Computer Society]
卷期号:50 (1): 85-105 被引量:264
标识
DOI:10.1109/tse.2023.3334955
摘要

Unit tests play a key role in ensuring the correctness of software. However, manually creating unit tests is a laborious task, motivating the need for automation. Large Language Models (LLMs) have recently been applied to various aspects of software development, including their suggested use for automated generation of unit tests, but while requiring additional training or few-shot learning on examples of existing tests. This paper presents a large-scale empirical evaluation on the effectiveness of LLMs for automated unit test generation without requiring additional training or manual effort. Concretely, we consider an approach where the LLM is provided with prompts that include the signature and implementation of a function under test, along with usage examples extracted from documentation. Furthermore, if a generated test fails, our approach attempts to generate a new test that fixes the problem by re-prompting the model with the failing test and error message. We implement our approach in TestPilot , an adaptive LLM-based test generation tool for JavaScript that automatically generates unit tests for the methods in a given project's API. We evaluate TestPilot using OpenAI's gpt3.5-turbo LLM on 25 npm packages with a total of 1,684 API functions. The generated tests achieve a median statement coverage of 70.2% and branch coverage of 52.8%. In contrast, the state-of-the feedback-directed JavaScript test generation technique, Nessie, achieves only 51.3% statement coverage and 25.6% branch coverage. Furthermore, experiments with excluding parts of the information included in the prompts show that all components contribute towards the generation of effective test suites. We also find that 92.8% of TestPilot 's generated tests have $\leq$ 50% similarity with existing tests (as measured by normalized edit distance), with none of them being exact copies. Finally, we run TestPilot with two additional LLMs, OpenAI's older code-cushman-002 LLM and StarCoder , an LLM for which the training process is publicly documented. Overall, we observed similar results with the former (68.2% median statement coverage), and somewhat worse results with the latter (54.0% median statement coverage), suggesting that the effectiveness of the approach is influenced by the size and training set of the LLM, but does not fundamentally depend on the specific model.
最长约 10秒,即可获得该文献文件

科研通智能强力驱动
Strongly Powered by AbleSci AI
科研通是完全免费的文献互助平台,具备全网最快的应助速度,最高的求助完成率。 对每一个文献求助,科研通都将尽心尽力,给求助人一个满意的交代。
实时播报
田様的应助被晴天采纳,获得10
刚刚
搜集达人的应助被温暖砖头采纳,获得10
2秒前
包邮上車完成签到,获得积分10
3秒前
4秒前
4秒前
肥陈的应助被坦率冰珍采纳,获得10
4秒前
tlm完成签到,获得积分10
4秒前
Mexsol完成签到,获得积分10
4秒前
zhuangzhuang完成签到,获得积分10
5秒前
壑舟完成签到,获得积分10
5秒前
西蜀小吏发布了新的文献求助10
10秒前
10秒前
鱼头汤完成签到,获得积分10
10秒前
yu完成签到,获得积分10
11秒前
11秒前
JJ完成签到,获得积分10
11秒前
12秒前
12秒前
12秒前
123完成签到,获得积分10
14秒前
科研通AI6.4的应助被耳东采纳,获得10
14秒前
云府有知完成签到,获得积分10
14秒前
韶芸遥发布了新的文献求助10
15秒前
橘子海完成签到 ,获得积分10
15秒前
ErkangQin发布了新的文献求助10
16秒前
yu发布了新的文献求助10
16秒前
asia完成签到,获得积分10
16秒前
sek完成签到,获得积分10
17秒前
17秒前
123发布了新的文献求助30
18秒前
搜集达人的应助被温暖的夏岚采纳,获得20
18秒前
十三发布了新的文献求助10
19秒前
Wty完成签到,获得积分10
20秒前
Future完成签到,获得积分10
20秒前
爆米花的应助被你叉叉穷哈哈采纳,获得10
21秒前
21秒前
hej完成签到 ,获得积分10
23秒前
23秒前
llyyz的应助被魔幻的舞蹈采纳,获得10
23秒前
dfw完成签到,获得积分10
24秒前
高分求助中
(应助此贴封号)【重要!!请各用户(尤其是新用户)详细阅读】【科研通的精品贴汇总】 10000
Aspects of Post-SPE Phonology 2000
Performance standards for antimicrobial disk and dilution susceptibility tests for bacteria isolated from animals 888
Rosenblum, Global Change Biology 800
Holistic Discourse Analysis, Second Edition by Robert E. Longacre (2012-09-10) 666
Final Report for the 2-D Test of Model 901 Rotor and Wing Airfoils (BSWT 592) 528
Berberine regulates the TLR4 signaling pathway to suppress hypoxia-induced proliferation and migration of pulmonary arterial smooth muscle cells 520
热门求助领域 (近24小时)
化学 材料科学 医学 生物 计算机科学 工程类 纳米技术 物理 有机化学 化学工程 内科学 生物化学 复合材料 催化作用 心理学 细胞生物学 无机化学 电极 光电子学 人工智能
热门帖子
关注 科研通微信公众号,转发送积分 7889200
求助须知:如何正确求助?哪些是违规求助? 9400875
关于积分的说明 20842612
捐赠科研通 7492067
什么是DOI,文献DOI怎么找? 3357441
关于科研通互助平台的介绍 2496075
邀请新用户注册赠送积分活动 2385731