An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generation

要約

単体テストは、ソフトウェアの正確性を保証する上で重要な役割を果たします。
ただし、単体テストを手動で作成するのは面倒な作業であるため、自動化の必要性が高まります。
最近、大規模言語モデル (LLM) がこの問題に適用され、既存のテストの例に対する追加のトレーニングまたは少数ショット学習が利用されています。
このペーパーでは、追加のトレーニングや手作業を必要とせずに自動単体テストを生成するための LLM の有効性に関する大規模な実証的評価を示し、ドキュメントから抽出した使用例とともに、テス​​ト対象の関数の署名と実装を LLM に提供します。
また、失敗したテストとエラー メッセージをモデルに再プロンプトすることで、失敗した生成テストの修復も試みます。
私たちのアプローチは、npm パッケージ内のすべての API 関数の単体テストを自動的に生成する JavaScript 用のテスト生成ツールである TestPilot に実装されています。
合計 1,684 個の API 関数を備えた 25 npm パッケージ上の OpenAI の gpt3.5-turbo LLM を使用して TestPilot を評価します。
生成されたテストは、ステートメント カバレッジの中央値 70.2%、ブランチ カバレッジ 52.8% を達成し、ステートメント カバレッジ 51.3% とブランチ カバレッジ 25.6% しか達成していない最近のフィードバック主導型 JavaScript テスト生成手法である Nessie を大きく改善しています。
また、TestPilot で生成されたテストの 92.8% は、既存のテスト (正規化された編集距離で測定) との類似性が 50% 以下であり、正確なコピーは存在しないこともわかりました。
最後に、OpenAI の古い code-cushman-002 LLM とオープン LLM StarCoder という 2 つの追加 LLM を使用して TestPilot を実行します。
全体として、前者では同様の結果 (ステートメント カバレッジの中央値 68.2%) が観察され、後者ではやや悪い結果 (ステートメント カバレッジの中央値 54.0%) が観察されました。これは、アプローチの有効性が LLM の規模とトレーニング セットに影響されることを示唆しています。
ですが、基本的には特定のモデルに依存しません。

要約(オリジナル)

Unit tests play a key role in ensuring the correctness of software. However, manually creating unit tests is a laborious task, motivating the need for automation. Large Language Models (LLMs) have recently been applied to this problem, utilizing additional training or few-shot learning on examples of existing tests. This paper presents a large-scale empirical evaluation on the effectiveness of LLMs for automated unit test generation without additional training or manual effort, providing the LLM with the signature and implementation of the function under test, along with usage examples extracted from documentation. We also attempt to repair failed generated tests by re-prompting the model with the failing test and error message. We implement our approach in TestPilot, a test generation tool for JavaScript that automatically generates unit tests for all API functions in an npm package. We evaluate TestPilot using OpenAI’s gpt3.5-turbo LLM on 25 npm packages with a total of 1,684 API functions. The generated tests achieve a median statement coverage of 70.2% and branch coverage of 52.8%, significantly improving on Nessie, a recent feedback-directed JavaScript test generation technique, which achieves only 51.3% statement coverage and 25.6% branch coverage. We also find that 92.8% of TestPilot’s generated tests have no more than 50% similarity with existing tests (as measured by normalized edit distance), with none of them being exact copies. Finally, we run TestPilot with two additional LLMs, OpenAI’s older code-cushman-002 LLM and the open LLM StarCoder. Overall, we observed similar results with the former (68.2% median statement coverage), and somewhat worse results with the latter (54.0% median statement coverage), suggesting that the effectiveness of the approach is influenced by the size and training set of the LLM, but does not fundamentally depend on the specific model.

arxiv情報

著者 Max Schäfer,Sarah Nadi,Aryaz Eghbali,Frank Tip
発行日 2023-09-06 16:47:07+00:00
arxivサイト arxiv_id(pdf)

提供元, 利用サービス

arxiv.jp, Google

カテゴリー: cs.AI, cs.SE パーマリンク