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.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Prompt Engineering Approaches to Reducing the Costs in LLM-Based Automated Test Case Generation

  • So Onishi,
  • Keisuke Kitamura,
  • Akihito Kohiga,
  • Takahiro Koita

摘要

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.