Last updated on
MetaのテストコードをLLMで生成する論文のスクラップ
参考記事
First open-source implementation of Meta’s TestGen–LLM - Qodo
- Metaが開発した TestGen-LLMというツール
- 人が生成した既存のテストクラスに対して
- 追加のテストケースを生成することで自動的に改善することを目的にしている
- 生成されたテストコードが特定のフィルター(ビルド可能であるか、信頼性高くパスするか、カバレッジを増加させるかなど)を通過することを検証することで、LLMのハルシネーション(不正確な情報の生成)による問題を排除し、改善が保証されるように設計されている
- このアプローチの核
- LLMが生成したコード(この論文の場合はテストケース)に対して複数の検証フィルターを適用することで、生成されたコードの品質と意図した改善が保証されるように設計されている点
- 具体的なフィルターの例
- 5回連続でパスする
- ビルドが可能か
- カバレッジを増加させるものか
- カバレッジが増えないなら重複とみなして破棄
紹介されているプロンプトの例
- extend_test
- Here is a Kotlin unit test class: {existing_test_class}. Write an extended version of the test class that includes additional tests to cover some extra corner cases
- extend_coverage
- Here is a Kotlin unit test class and the class that it tests: {existing_test_class} {class_under_test}. Write an extended version of the test class that includes additional unit tests that will increase the test coverage of the class under test
- corner_cases
- Here is a Kotlin unit test class and the class that it tests: {existing_test_class} {class_under_test}. Write an extended version of the test class that includes additional unit tests that will cover corner cases missed by the original and will increase the test coverage of the class under test
- statement_to_complete
- Here is a Kotlin class under test {class_under_test} This class under test can be tested with this Kotlin unit test class {existing_test_class}. Here is an extended version of the unit test class that includes additional unit test cases that will cover methods, edge cases, corner cases, and other features of the class under test that were missed by the original unit test class:
RAG
- ユニットテスト生成により多くのコンテキストを加えることで、テストの品質と合格率が向上することを認識したらしい
課題
- 複数のイテレーションを必要とする複雑なコードの生成
- 失敗した(または付加価値のない)テストが生成されるにつれて、同じ不採用テストが後のイテレーションで繰り返し提案されるというパターンがある
- プロンプトに「失敗したテスト」セクションを追加し、そのフィードバックをLLMに提供することで対応