[논문 리뷰] Code-Aware Prompting: A study of Coverage Guided Test Generation in Regression Setting using LLM
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.
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가 복잡한 분기에서 어려움을 겪는 자동 테스트 생성 동기를 부여한다.
- 추가 모델 학습 없이 LLM을 통해 테스트 입력 생성을 개선하기 위한 코드 인식 멀티 스테이지 프롬프팅 전략을 도입한다.
- 정적 AST 분석을 활용하여 경로 제약과 관련된 코드 맥락을 추출하고 LLM이 다양하고 높은 커버리지를 가진 테스트를 생성하도록 안내한다.
- 여러 LLM에서 정확도, 호출 정확성 및 커버리지의 향상을 정량화하기 위해 Python 벤치마크에서 SymPrompt를 평가한다.
제안 방법
- AST 순회를 통한 실행 경로를 표현하기 위한 approximate 경로 제약의 정적 수집.
- 테스트 생성의 기반이 되는 타입 정의 및 외부 의존성을 포착하는 맥락 구성.
- 개별 실행 경로를 목표로 하는 테스트를 요청하는 경로 특정 프롬프트의 반복적 생성.
- 지수적 경로 증가를 피하면서도 커버리지를 유지하기 위한 최소 경로(기본 경로) 집합의 사용.
- CodeGen2 프롬프트와의 호환성 및 파싱을 위한 TreeSitter의 통합.
- SBST 기준선 및 기본 LLM 프롬 prompting과 비교하기 위해 오픈 소스 Python 프로젝트의 897개 주력 메서드에 대한 평가.

실험 결과
연구 질문
- RQ1RQ1: 회귀 테스트 생성에서 단순 프롬프트 방법에 비해 SymPrompt가 테스트 성능에 어떤 영향을 미치는가?
- RQ2RQ2: 모델 학습 데이터에 잠재적으로 보지 못한 프로젝트에서 SymPrompt의 성능은 어떤가?
- RQ3RQ3: 경로 제약 프롬프트와 초점 맥락이 성능 향상에 얼마나 기여하는가?
- RQ4RQ4: GPT-4와 같은 대형 모델에서 SymPrompt가 성능을 향상시키는가?
주요 결과
- SymPrompt는 기본 프롬프트에 비해 테스트 생성 성능을 크게 향상시키며, 합격 테스트 및 올바른 테스트 생성율을 각각 약 4배와 5배 증가시킨다.
- 경로 제약 프롬프트는 기본 프롬프트 대비 라인 커버리지 약 10%, 브랜치 커버리지 약 4% 향상을 이끈다.
- 모듈 로드 효과를 반영한(No-Op baseline) 경우 SymPrompt가 커버리지 향상에서 약 3배 더 큰 효과를 달성한다(약 15% 대 5%).
- CodeGen2에서 SymPrompt의 상대 커버리지가 26% 증가; GPT-4에서 커버리지가 두 배 이상 증가(상대적 향상 약 105%).
- SymPrompt는 초점 메서드 호출 오류를 줄이고 더 덜 일반적인 경로(예: 블록 장치, 소켓)에 대한 테스트 입력을 유도하여 커버리지를 확장한다.
- SymPrompt가 없는 기본 테스트 생성은 복잡한 분기를 충분히 다루지 못하는 경향이 있지만, SymPrompt는 다양한 입력에 대해 보다 완전한 테스트를 가능하게 한다.

이 논문 읽기
누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.
누빈트에서 이 논문 읽기이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.