Lune

ASE2023Top-tier venue

CAT-LM Training Language Models on Aligned Code And Tests

Nikitha Rao, Kush Jain, Uri Alon, Claire Le Goues, Vincent J. Hellendoorn

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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

19 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • LLM Test Generation via Iterative Hybrid Program Analysis cites Leveraging Large Language Models for Enhancing the Understandability of Generated Unit Tests
  • LLM Test Generation via Iterative Hybrid Program Analysis cites On learning meaningful assert statements for unit test cases
  • LLM Test Generation via Iterative Hybrid Program Analysis cites HITS: High-coverage LLM-based Unit Test Generation via Method Slicing
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Language Models are Few-Shot Learners
  • InCoder: A Generative Model for Code Infilling and Synthesis cites Language Models are Few-Shot Learners
  • Your Code Secret Belongs to Me: Neural Code Completion Tools Can Memorize Hard-Coded Credentials cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Your Code Secret Belongs to Me: Neural Code Completion Tools Can Memorize Hard-Coded Credentials cites InCoder: A Generative Model for Code Infilling and Synthesis
  • LlamaRestTest: Effective REST API Testing with Small Language Models cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers19

  1. HITS: High-coverage LLM-based Unit Test Generation via Method SlicingZejun Wang, Kaibo Liu, Ge Li, Zhi JinASE 2024 · 29 citations
  2. Your Code Secret Belongs to Me: Neural Code Completion Tools Can Memorize Hard-Coded CredentialsYizhan Huang, Yichen Li, Weibin Wu, Jianping Zhang et al.FSE 2024 · 22 citations
  3. LlamaRestTest: Effective REST API Testing with Small Language ModelsMyeongsoo Kim, Saurabh Sinha, Alessandro OrsoFSE 2025 · 9 citations
  4. Leveraging Large Language Models for Enhancing the Understandability of Generated Unit TestsAmirhossein Deljouyi, Roham Koohestani, Maliheh Izadi, Andy ZaidmanICSE 2025 · 8 citations
  5. LLM Test Generation via Iterative Hybrid Program AnalysisSijia Gu, Noor Nashid, Ali MesbahICSE 2026 · 6 citations

Builds on7

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra et al.NeurIPS 2022 · 5,493 citations
  3. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
  4. InCoder: A Generative Model for Code Infilling and SynthesisDaniel Fried, Armen Aghajanyan, Jessy Lin, Sida Wang et al.ICLR 2023 · 140 citations
  5. On learning meaningful assert statements for unit test casesCody Watson, Michele Tufano, Kevin Moran, Gabriele Bavota et al.ICSE 2020 · 96 citations

Related papers

  1. On the Evaluation of Large Language Models in Unit Test GenerationLin Yang, Chen Yang, Shutao Gao, Weijing Wang et al.ASE 2024 · 42 citations
  2. Evaluating and Improving ChatGPT for Unit Test GenerationZhiqiang Yuan, Mingwei Liu, Shiji Ding, Kaixin Wang et al.FSE 2024 · 89 citations
  3. Code-Aware Prompting: A Study of Coverage-Guided Test Generation in Regression Setting using LLMGabriel Ryan, Siddhartha Jain, Mingyue Shang, Shiqi Wang et al.FSE 2024 · 68 citations
  4. exLong: Generating Exceptional Behavior Tests with Large Language ModelsJiyang Zhang, Yu Liu, Pengyu Nie, Junyi Jessy Li et al.ICSE 2025 · 2 citations
  5. Test Intention Guided LLM-Based Unit Test GenerationZifan Nan, Zhaoqiang Guo, Kui Liu, Xin XiaICSE 2025 · 5 citations
Dusk over the sea between two cliffs drawn in fine vertical lines