Unit testing is an essential yet frequently arduous task. Various automated unit test generation tools have been introduced to mitigate this challenge. Notably, methods based on large language models (LLMs) have garnered considerable attention and exhibited promising results in recent years. Nevertheless, LLM-based tools encounter limitations in generating accurate unit tests. This paper presents ChatUniTest, an LLM-based automated unit test generation framework. ChatUniTest incorporates an adaptive focal context mechanism to encompass valuable context in prompts and adheres to a generation-validation-repair mechanism to rectify errors in generated unit tests. Subsequently, we have developed ChatUniTest Core, a common library that implements core workflow, complemented by the ChatUniTest Toolchain, a suite of seamlessly integrated tools enhancing the capabilities of ChatUniTest. Our effectiveness evaluation reveals that ChatUniTest outperforms TestSpark and EvoSuite in half of the evaluated projects, achieving the highest overall line coverage. Furthermore, insights from our user study affirm that ChatUniTest delivers substantial value to various stakeholders in the software testing domain. ChatUniTest is available at https://github.com/ZJU-ACES-ISE/ChatUniTest, and the demo video is available at https://www.youtube.com/watch?v=GmfxQUqm2ZQ.
翻译:单元测试是一项必要但通常繁重的任务。为缓解这一挑战,研究者提出了多种自动化单元测试生成工具。其中,基于大语言模型(LLM)的方法近年来备受关注并展现出令人瞩目的成果。然而,基于LLM的工具在生成精确单元测试方面仍存在局限。本文提出ChatUniTest——一种基于LLM的自动化单元测试生成框架。该框架采用自适应焦点上下文机制,将有价值的上下文信息纳入提示中,并遵循"生成-验证-修复"机制来修正生成的单元测试中的错误。我们进一步开发了ChatUniTest Core(实现核心流程的通用库),并辅以ChatUniTest Toolchain(一套无缝集成、增强ChatUniTest功能的工具链)。有效性评估表明,在半数评估项目中ChatUniTest的性能优于TestSpark和EvoSuite,并取得了最高的整体行覆盖率。此外,用户研究的反馈证实,ChatUniTest为软件测试领域的各类利益相关者提供了重要价值。ChatUniTest的代码仓库地址为https://github.com/ZJU-ACES-ISE/ChatUniTest,演示视频位于https://www.youtube.com/watch?v=GmfxQUqm2ZQ。