Skip to main content
QUICK REVIEW

[論文レビュー] Code-Aware Prompting: A study of Coverage Guided Test Generation in Regression Setting using LLM

Gabriel Ryan, Siddhartha Jain|arXiv (Cornell University)|Jan 31, 2024
Machine Learning and Data ClassificationComputer Science被引用数 5
ひとこと要約

SymPrompt, a code-aware multi-stage prompting framework, uses static path constraints and contextual information to guide LLMs in generating higher-coverage regression tests, outperforming baseline prompts and SBST in Python benchmarks and GPT-4.

ABSTRACT

Testing plays a pivotal role in ensuring software quality, yet conventional Search Based Software Testing (SBST) methods often struggle with complex software units, achieving suboptimal test coverage. Recent works using large language models (LLMs) for test generation have focused on improving generation quality through optimizing the test generation context and correcting errors in model outputs, but use fixed prompting strategies that prompt the model to generate tests without additional guidance. As a result LLM-generated testsuites still suffer from low coverage. In this paper, we present SymPrompt, a code-aware prompting strategy for LLMs in test generation. SymPrompt's approach is based on recent work that demonstrates LLMs can solve more complex logical problems when prompted to reason about the problem in a multi-step fashion. We apply this methodology to test generation by deconstructing the testsuite generation process into a multi-stage sequence, each of which is driven by a specific prompt aligned with the execution paths of the method under test, and exposing relevant type and dependency focal context to the model. Our approach enables pretrained LLMs to generate more complete test cases without any additional training. We implement SymPrompt using the TreeSitter parsing framework and evaluate on a benchmark challenging methods from open source Python projects. SymPrompt enhances correct test generations by a factor of 5 and bolsters relative coverage by 26% for CodeGen2. Notably, when applied to GPT-4, SymPrompt improves coverage by over 2x compared to baseline prompting strategies.

研究の動機と目的

  • SBST が複雑な分岐に苦戦する回帰設定で、自動化テスト生成を動機づける。
  • 追加のモデル訓練を必要とせず、コード認識型の多段 prompting 戦略を導入して、LLM によるテスト入力生成を改善する。
  • 静的な AST 分析を活用して経路制約と関連コード文脈を抽出し、LLMs が多様で高いカバレージのテストを生成するよう導く。
  • 複数の LLM に渡る正確性、呼び出し精度、カバレージの向上を定量化するため、Python ベンチマークで SymPrompt を評価する。

提案手法

  • AST走査からの概略的な経路制約を静的に収集して実行経路を表現する。
  • 型定義と外部依存関係を捉えた文脈構築によりテスト生成を土台化する。
  • 個々の実行経路を対象とするテストを要求する、反復的な経路特化プロンプト生成。
  • カバレージを維持しつつ指数的な経路増加を避ける最小経路(基底経路)セットの使用。
  • パース用のTreeSitterとの統合とCodeGen2およびGPT-4プロンプトとの互換性。
  • オープンソースのPythonプロジェクトから897の焦点メソッドを対象に、SBSTベースラインおよびベースラインLLMプロンプトと比較する評価。
Figure 1 . Example test generations from an SBST tool (Pynguin), zero shot LLM (CodeGen2), and SymPrompt prompts for focal method exists_as in the flutils open source Python project. An SBST approach is unable to generate full coverage tests for this method without special configuration because it i
Figure 1 . Example test generations from an SBST tool (Pynguin), zero shot LLM (CodeGen2), and SymPrompt prompts for focal method exists_as in the flutils open source Python project. An SBST approach is unable to generate full coverage tests for this method without special configuration because it i

実験結果

リサーチクエスチョン

  • RQ1RQ1: 回帰テスト生成において、SymPrompt は単純な prompting 手法と比較してテスト性能にどのような影響を与えるか?
  • RQ2RQ2: モデルの学習データに含まれていない可能性のあるプロジェクトでの SymPrompt の性能はどうか?
  • RQ3RQ3: pathConstraint プロンプトと focal context は性能向上にどう寄与するか?
  • RQ4RQ4: GPT-4 のような非常に大きなモデルで SymPrompt は性能を改善するか?

主な発見

  • SymPrompt はベースラインプロンプトに比べてテスト生成性能を著しく改善し、合格テスト生成と正確なテスト生成をそれぞれ約4倍と5倍に増加させる。
  • 経路制約プロンプトは、ベースラインプロンプトに対してラインカバレージを約10%、ブランチカバレージを約4%向上させる。
  • モジュールロード効果(No-Op ベースライン)を考慮すると、SymPrompt は約3倍のカバレージ改善を達成する(概ね15%対5%)。
  • CodeGen2 では相対カバレージを26%向上;GPT-4 ではカバレージを2倍以上にし、約105%の相対改善。
  • SymPrompt は焦点メソッドの呼び出しエラーを減らし、より珍しい経路(例:ブロックデバイス、ソケット)をテストする入力を誘導してカバレージを拡大する。
  • SymPrompt なしのベースラインテスト生成は複雑な分岐を網羅できないことが多いが、SymPrompt は多様な入力にわたるより完全なテストを可能にする。
Figure 2 . Workflow for generating path constraint prompts. The focal method shown in Figure 1(a) is first parsed and its abstract syntax tree is traversed in preorder. In step \raisebox{-.9pt} {1}⃝ , the traversal first visits the first method statement, normalize_path(path) , but does not record a
Figure 2 . Workflow for generating path constraint prompts. The focal method shown in Figure 1(a) is first parsed and its abstract syntax tree is traversed in preorder. In step \raisebox{-.9pt} {1}⃝ , the traversal first visits the first method statement, normalize_path(path) , but does not record a

この論文を読む

Nubintのビューアで原文を開き、読みながら気になる箇所をすぐに質問できます。

Nubintでこの論文を読む

このレビューはAIが論文の原文をもとに作成しました。引用する前に原文をご確認ください。