Prompt Engineering Approaches to Reducing the Costs in LLM-Based Automated Test Case Generation
摘要
Large language models (LLMs) automate test case generation but require lengthy prompts to reach 100% code coverage, increasing token usage and API costs. We compare two prompt engineering strategies: removing docstrings and compressing prompts with LLMLingua-2. Across Python projects using Claude 3.7 Sonnet, Gemini 2.5 Pro Preview, and GPT-4.1. LLMLingua-2 reduce API costs by 6.8% while keeping 100% code coverage. Docstring removal achieved savings only on GPT-4.1. For Claude, the coefficient of variation was 19.5% with docstrings and 32.7% without. This is indicating more stable performance when docstrings is retained. Therefore, these findings reveal that the need for docstrings depends on the model and demonstrate that prompt engineering can deliver predictable cost saving, advancing the deployment of economical LLM-based test case generation.