paperbot · PL 论文追踪

全部论文 待读 收藏

P2 CAT-LM Training Language Models on Aligned Code And Tests

CAT-LM:在代码与测试对齐数据上训练语言模型
ASE 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE)2023匹配度 3/10 · 论文研究用LLM进行测试生成,属于LLM在软件工程中的应用,但与用户核心关注的静态分析、形式化验证、浮点程序分析及贝叶斯程序分析无直接交集;且研究目标本身是训练代码LLM,不符合用户偏好'LLM仅作为工具'的方向。引用 87 inbox
Nikitha Rao, Kush Jain, Uri Alon, Claire Le Goues, Vincent J. Hellendoorn
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:提出在代码-测试对齐语料上预训练的2.7B参数模型CAT-LM,通过长上下文与筛选采样生成高覆盖率、风格自然的测试。

测试生成常被忽视:EvoSuite 等工具优化覆盖率但测试难懂,按文件独立训练的代码语言模型又忽略被测代码上下文。本文提出 CAT-LM,一个 2.7B 参数 GPT 风格模型,在 Python/Java 项目语料上训练,采用显式建模代码文件与测试文件映射的预训练信号,并把输入长度扩至 8192 token,以便生成测试时利用代码上下文。评估表明,结合可编译性、覆盖率等过滤采样,CAT-LM 生成的测试在覆盖率上接近开发者手写测试且风格相似;利用代码上下文后,其生成有效测试的比例超过更大的 CodeGen 16B 与 StarCoder,并在测试补全上显著优于专用模型 TeCo。

问题
传统覆盖率驱动测试生成工具产出的测试可读性差,而按文件独立训练的代码语言模型生成测试时无法利用被测代码上下文。
方法
提出 CAT-LM,一个 2.7B 参数 GPT 风格模型,在 Python/Java 项目上以代码-测试文件映射为预训练信号,并将输入上下文扩展至 8192 token。
评估
在真实测试生成与补全任务上,通过可编译性、覆盖率等过滤采样评估,并与 CodeGen 16B、StarCoder 及 TeCo 对比。
原文摘要(Abstract)

Testing is an integral but often neglected part of the software development process. Classical test generation tools such as EvoSuite generate behavioral test suites by optimizing for coverage, but tend to produce tests that are hard to understand. Language models trained on code can generate code that is highly similar to that written by humans, but current models are trained to generate each file separately, as is standard practice in natural language processing, and thus fail to consider the code-under-test context when producing a test file. In this work, we propose the Aligned Code And Tests Language Model (CAT-LM), a GPT-style language model with 2.7 Billion parameters, trained on a corpus of Python and Java projects. We utilize a novel pretraining signal that explicitly considers the mapping between code and test files when available. We also drastically increase the maximum sequence length of inputs to 8,192 tokens, 4x more than typical code generation models, to ensure that the code context is available to the model when generating test code. We analyze its usefulness for realistic applications, showing that sampling with filtering (e.g., by compilability, coverage) allows it to efficiently produce tests that achieve coverage similar to ones written by developers while resembling their writing style. By utilizing the code context, CAT-LM generates more valid tests than even much larger language models trained with more data (CodeGen 16B and StarCoder) and substantially outperforms a recent test-specific model (TeCo) at test completion. Overall, our work highlights the importance of incorporating software-specific insights when training language models for code and paves the way to more powerful automated test generation.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@inproceedings{abs-2310-01602,
  title = {CAT-LM Training Language Models on Aligned Code And Tests},
  author = {Nikitha Rao and Kush Jain and Uri Alon and Claire Le Goues and Vincent J. Hellendoorn},
  booktitle = {ASE},
  year = {2023},
  doi = {10.1109/ase56229.2023.00193}
}