Skip to content

Type-aware LLM-based Test Generation for Python Programs

Jul 2026 · ACM Transactions on Software Engineering and Methodology · 0 citations · 59 references

TL;DR

Test4Py is presented, a novel framework that enhances type correctness in automated test generation for Python by leveraging the program’s call graph to capture richer contextual information about parameters, and introducing a behavior-based type inference mechanism that accurately infers parameter types and constructs valid test inputs.

Abstract

Automated test generation has been extensively explored, yet generating high-quality tests for Python programs remains particularly challenging. Because of Python’s dynamic typing features, existing approaches, ranging from search-based software testing (SBST) to recent LLM-driven techniques, are often prone to type errors. Hence, existing methods often generate invalid inputs and semantically inconsistent test cases, which ultimately undermine their practical effectiveness. To address these limitations, we present Test4Py, a novel framework that enhances type correctness in automated test generation for Python. Test4Py leverages the program’s call graph to capture richer contextual information about parameters, and introduces a behavior-based type inference mechanism that accurately infers parameter types and constructs valid test inputs. Beyond input construction, Test4Py integrates an iterative repair procedure that progressively refines generated test cases to improve coverage. In an evaluation on 183 real-world Python modules, Test4Py achieved an average line coverage of 83.0% and branch coverage of 70.8%, outperforming state-of-the-art tools by 7.2% and 8.4% in relative gains, respectively.

View source

Similar papers

Jul 2026

JSTestCraft: Addressing Context Deficits in JavaScript Unit Test Generation via Agentic Multi-Level Contextual Analysis

JSTestCraft reconstructs missing context via three enrichment agents: library, structural, and semantic via three enrichment agents, demonstrating that context reconstruction and agentic collaboration enable LLMs to perform more reliable and adaptive testing in dynamic JavaScript environments.

Yi-Yang Liu, Yanjie Zhao, Haoyu Wang · 0 citations
Book Open access Jul 2026

TOGBench: A Developer-Written Multi-variant Dataset and Benchmark Suite for Test Oracle Generation

OE25𝑑𝑒𝑣, a multi-variant dataset curated from developer-written unit tests across 25 open-source Java projects spanning 56 modules, and TOGBench, an end-to-end benchmark suite for TOG, which captures six oracle categories and preserves realistic settings, are introduced.

Tasfia Tasnim, Matthew B. Dwyer, Soneya Binta Hossain · 1 citation
Open access Aug 2026

Improving Bug Detection in LLM-Generated Unit Tests: Revisiting Test-Oracle Reliability Across Modern Large Language Models

This paper presents a formal mathematical model for categorizing the outcome of generated-tests into four classes, a couple of basic metrics: Bug-Revealing Rate (BRR) and Bug-Validating Rate (BVR); and two basic statistical tests to ensure that the results are rigorous.

Zeyad Farooq Lutfi · 0 citations
Book Open access Jul 2026

A Qualitative and Quantitative Exploration of LLM-Based Test Generation Repair Loops

A dataset of LLM-generated broken-to-fixed test pairs is built, where initially failing tests are repaired via a loop under zero-shot, few-shot, and chain-of-thought prompting, and the performance of prompting strategies through repair rate and post-repair coverage is compared.

Jaskeerat Singh · 0 citations
Open access Aug 2026

Property-based testing in Python: empirical insights

These findings provide the largest empirical characterization of PBT in Python to date, highlight developers’ difficulties in adopting the technique, and expose limitations of current tool support.

Isadora de Oliveira, Arthur Lisboa Corgozinho, Henrique Rocha et al. · 0 citations
Book Open access Jul 2026

LLM-based Specification-Driven Test Oracle Enhancement

JavaOracle is proposed, a specification-driven approach that leverages large language models to reason over specifications and systematically enhance test oracles and further automates test case minimization and bug report generation, producing submission-ready reports without manual effort.

Ruifeng Fu, Yingquan Zhao, Meng Wang et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.