LLM-based Unit Test Generation via Property Retrieval
Automated unit test generation has been widely studied, with Large Language Models (LLMs) recently showing significant potential. Moreover, in the context of unit test generation, these tools prioritize high code coverage, often at the expense of practical usability, correctness, and maintainability...
Gespeichert in:
Hauptverfasser: | , , , , , |
---|---|
Format: | Artikel |
Sprache: | eng |
Schlagworte: | |
Online-Zugang: | Volltext bestellen |
Tags: |
Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
|
container_end_page | |
---|---|
container_issue | |
container_start_page | |
container_title | |
container_volume | |
creator | Zhang, Zhe Liu, Xingyu Lin, Yuanzhang Gao, Xiang Sun, Hailong Yuan, Yuan |
description | Automated unit test generation has been widely studied, with Large Language
Models (LLMs) recently showing significant potential. Moreover, in the context
of unit test generation, these tools prioritize high code coverage, often at
the expense of practical usability, correctness, and maintainability. In
response, we propose Property-Based Retrieval Augmentation, a novel mechanism
that extends LLM-based Retrieval-Augmented Generation (RAG) beyond basic
vector, text similarity, and graph-based methods. Our approach considers
task-specific context and introduces a tailored property retrieval mechanism.
Specifically, in the unit test generation task, we account for the unique
structure of unit tests by dividing the test generation process into Given,
When, and Then phases. When generating tests for a focal method, we not only
retrieve general context for the code under test but also consider
task-specific context such as pre-existing tests of other methods, which can
provide valuable insights for any of the Given, When, and Then phases. This
forms property relationships between focal method and other methods, thereby
expanding the scope of retrieval beyond traditional RAG. We implement this
approach in a tool called APT, which sequentially performs preprocessing,
property retrieval, and unit test generation, using an iterative strategy where
newly generated tests guide the creation of subsequent ones. We evaluated APT
on 12 open-source projects with 1515 methods, and the results demonstrate that
APT consistently outperforms existing tools in terms of correctness,
completeness, and maintainability of the generated tests. Moreover, we
introduce a novel code-context-aware retrieval mechanism for LLMs beyond
general context, offering valuable insights and potential applications for
other code-related tasks. |
doi_str_mv | 10.48550/arxiv.2410.13542 |
format | Article |
fullrecord | <record><control><sourceid>arxiv_GOX</sourceid><recordid>TN_cdi_arxiv_primary_2410_13542</recordid><sourceformat>XML</sourceformat><sourcesystem>PC</sourcesystem><sourcerecordid>2410_13542</sourcerecordid><originalsourceid>FETCH-arxiv_primary_2410_135423</originalsourceid><addsrcrecordid>eNpjYJA0NNAzsTA1NdBPLKrILNMzMgEKGBqbmhhxMpj6-PjqJiUWp6YohOZlliiEpBaXKLin5qUWJZZk5ucplGUmKgQU5RekFpVUKgSllhRlppYl5vAwsKYl5hSn8kJpbgZ5N9cQZw9dsAXxBUWZuYlFlfEgi-LBFhkTVgEAHC4yGw</addsrcrecordid><sourcetype>Open Access Repository</sourcetype><iscdi>true</iscdi><recordtype>article</recordtype></control><display><type>article</type><title>LLM-based Unit Test Generation via Property Retrieval</title><source>arXiv.org</source><creator>Zhang, Zhe ; Liu, Xingyu ; Lin, Yuanzhang ; Gao, Xiang ; Sun, Hailong ; Yuan, Yuan</creator><creatorcontrib>Zhang, Zhe ; Liu, Xingyu ; Lin, Yuanzhang ; Gao, Xiang ; Sun, Hailong ; Yuan, Yuan</creatorcontrib><description>Automated unit test generation has been widely studied, with Large Language
Models (LLMs) recently showing significant potential. Moreover, in the context
of unit test generation, these tools prioritize high code coverage, often at
the expense of practical usability, correctness, and maintainability. In
response, we propose Property-Based Retrieval Augmentation, a novel mechanism
that extends LLM-based Retrieval-Augmented Generation (RAG) beyond basic
vector, text similarity, and graph-based methods. Our approach considers
task-specific context and introduces a tailored property retrieval mechanism.
Specifically, in the unit test generation task, we account for the unique
structure of unit tests by dividing the test generation process into Given,
When, and Then phases. When generating tests for a focal method, we not only
retrieve general context for the code under test but also consider
task-specific context such as pre-existing tests of other methods, which can
provide valuable insights for any of the Given, When, and Then phases. This
forms property relationships between focal method and other methods, thereby
expanding the scope of retrieval beyond traditional RAG. We implement this
approach in a tool called APT, which sequentially performs preprocessing,
property retrieval, and unit test generation, using an iterative strategy where
newly generated tests guide the creation of subsequent ones. We evaluated APT
on 12 open-source projects with 1515 methods, and the results demonstrate that
APT consistently outperforms existing tools in terms of correctness,
completeness, and maintainability of the generated tests. Moreover, we
introduce a novel code-context-aware retrieval mechanism for LLMs beyond
general context, offering valuable insights and potential applications for
other code-related tasks.</description><identifier>DOI: 10.48550/arxiv.2410.13542</identifier><language>eng</language><subject>Computer Science - Software Engineering</subject><creationdate>2024-10</creationdate><rights>http://arxiv.org/licenses/nonexclusive-distrib/1.0</rights><oa>free_for_read</oa><woscitedreferencessubscribed>false</woscitedreferencessubscribed></display><links><openurl>$$Topenurl_article</openurl><openurlfulltext>$$Topenurlfull_article</openurlfulltext><thumbnail>$$Tsyndetics_thumb_exl</thumbnail><link.rule.ids>228,230,776,881</link.rule.ids><linktorsrc>$$Uhttps://arxiv.org/abs/2410.13542$$EView_record_in_Cornell_University$$FView_record_in_$$GCornell_University$$Hfree_for_read</linktorsrc><backlink>$$Uhttps://doi.org/10.48550/arXiv.2410.13542$$DView paper in arXiv$$Hfree_for_read</backlink></links><search><creatorcontrib>Zhang, Zhe</creatorcontrib><creatorcontrib>Liu, Xingyu</creatorcontrib><creatorcontrib>Lin, Yuanzhang</creatorcontrib><creatorcontrib>Gao, Xiang</creatorcontrib><creatorcontrib>Sun, Hailong</creatorcontrib><creatorcontrib>Yuan, Yuan</creatorcontrib><title>LLM-based Unit Test Generation via Property Retrieval</title><description>Automated unit test generation has been widely studied, with Large Language
Models (LLMs) recently showing significant potential. Moreover, in the context
of unit test generation, these tools prioritize high code coverage, often at
the expense of practical usability, correctness, and maintainability. In
response, we propose Property-Based Retrieval Augmentation, a novel mechanism
that extends LLM-based Retrieval-Augmented Generation (RAG) beyond basic
vector, text similarity, and graph-based methods. Our approach considers
task-specific context and introduces a tailored property retrieval mechanism.
Specifically, in the unit test generation task, we account for the unique
structure of unit tests by dividing the test generation process into Given,
When, and Then phases. When generating tests for a focal method, we not only
retrieve general context for the code under test but also consider
task-specific context such as pre-existing tests of other methods, which can
provide valuable insights for any of the Given, When, and Then phases. This
forms property relationships between focal method and other methods, thereby
expanding the scope of retrieval beyond traditional RAG. We implement this
approach in a tool called APT, which sequentially performs preprocessing,
property retrieval, and unit test generation, using an iterative strategy where
newly generated tests guide the creation of subsequent ones. We evaluated APT
on 12 open-source projects with 1515 methods, and the results demonstrate that
APT consistently outperforms existing tools in terms of correctness,
completeness, and maintainability of the generated tests. Moreover, we
introduce a novel code-context-aware retrieval mechanism for LLMs beyond
general context, offering valuable insights and potential applications for
other code-related tasks.</description><subject>Computer Science - Software Engineering</subject><fulltext>true</fulltext><rsrctype>article</rsrctype><creationdate>2024</creationdate><recordtype>article</recordtype><sourceid>GOX</sourceid><recordid>eNpjYJA0NNAzsTA1NdBPLKrILNMzMgEKGBqbmhhxMpj6-PjqJiUWp6YohOZlliiEpBaXKLin5qUWJZZk5ucplGUmKgQU5RekFpVUKgSllhRlppYl5vAwsKYl5hSn8kJpbgZ5N9cQZw9dsAXxBUWZuYlFlfEgi-LBFhkTVgEAHC4yGw</recordid><startdate>20241017</startdate><enddate>20241017</enddate><creator>Zhang, Zhe</creator><creator>Liu, Xingyu</creator><creator>Lin, Yuanzhang</creator><creator>Gao, Xiang</creator><creator>Sun, Hailong</creator><creator>Yuan, Yuan</creator><scope>AKY</scope><scope>GOX</scope></search><sort><creationdate>20241017</creationdate><title>LLM-based Unit Test Generation via Property Retrieval</title><author>Zhang, Zhe ; Liu, Xingyu ; Lin, Yuanzhang ; Gao, Xiang ; Sun, Hailong ; Yuan, Yuan</author></sort><facets><frbrtype>5</frbrtype><frbrgroupid>cdi_FETCH-arxiv_primary_2410_135423</frbrgroupid><rsrctype>articles</rsrctype><prefilter>articles</prefilter><language>eng</language><creationdate>2024</creationdate><topic>Computer Science - Software Engineering</topic><toplevel>online_resources</toplevel><creatorcontrib>Zhang, Zhe</creatorcontrib><creatorcontrib>Liu, Xingyu</creatorcontrib><creatorcontrib>Lin, Yuanzhang</creatorcontrib><creatorcontrib>Gao, Xiang</creatorcontrib><creatorcontrib>Sun, Hailong</creatorcontrib><creatorcontrib>Yuan, Yuan</creatorcontrib><collection>arXiv Computer Science</collection><collection>arXiv.org</collection></facets><delivery><delcategory>Remote Search Resource</delcategory><fulltext>fulltext_linktorsrc</fulltext></delivery><addata><au>Zhang, Zhe</au><au>Liu, Xingyu</au><au>Lin, Yuanzhang</au><au>Gao, Xiang</au><au>Sun, Hailong</au><au>Yuan, Yuan</au><format>journal</format><genre>article</genre><ristype>JOUR</ristype><atitle>LLM-based Unit Test Generation via Property Retrieval</atitle><date>2024-10-17</date><risdate>2024</risdate><abstract>Automated unit test generation has been widely studied, with Large Language
Models (LLMs) recently showing significant potential. Moreover, in the context
of unit test generation, these tools prioritize high code coverage, often at
the expense of practical usability, correctness, and maintainability. In
response, we propose Property-Based Retrieval Augmentation, a novel mechanism
that extends LLM-based Retrieval-Augmented Generation (RAG) beyond basic
vector, text similarity, and graph-based methods. Our approach considers
task-specific context and introduces a tailored property retrieval mechanism.
Specifically, in the unit test generation task, we account for the unique
structure of unit tests by dividing the test generation process into Given,
When, and Then phases. When generating tests for a focal method, we not only
retrieve general context for the code under test but also consider
task-specific context such as pre-existing tests of other methods, which can
provide valuable insights for any of the Given, When, and Then phases. This
forms property relationships between focal method and other methods, thereby
expanding the scope of retrieval beyond traditional RAG. We implement this
approach in a tool called APT, which sequentially performs preprocessing,
property retrieval, and unit test generation, using an iterative strategy where
newly generated tests guide the creation of subsequent ones. We evaluated APT
on 12 open-source projects with 1515 methods, and the results demonstrate that
APT consistently outperforms existing tools in terms of correctness,
completeness, and maintainability of the generated tests. Moreover, we
introduce a novel code-context-aware retrieval mechanism for LLMs beyond
general context, offering valuable insights and potential applications for
other code-related tasks.</abstract><doi>10.48550/arxiv.2410.13542</doi><oa>free_for_read</oa></addata></record> |
fulltext | fulltext_linktorsrc |
identifier | DOI: 10.48550/arxiv.2410.13542 |
ispartof | |
issn | |
language | eng |
recordid | cdi_arxiv_primary_2410_13542 |
source | arXiv.org |
subjects | Computer Science - Software Engineering |
title | LLM-based Unit Test Generation via Property Retrieval |
url | https://sfx.bib-bvb.de/sfx_tum?ctx_ver=Z39.88-2004&ctx_enc=info:ofi/enc:UTF-8&ctx_tim=2025-01-27T18%3A12%3A22IST&url_ver=Z39.88-2004&url_ctx_fmt=infofi/fmt:kev:mtx:ctx&rfr_id=info:sid/primo.exlibrisgroup.com:primo3-Article-arxiv_GOX&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&rft.genre=article&rft.atitle=LLM-based%20Unit%20Test%20Generation%20via%20Property%20Retrieval&rft.au=Zhang,%20Zhe&rft.date=2024-10-17&rft_id=info:doi/10.48550/arxiv.2410.13542&rft_dat=%3Carxiv_GOX%3E2410_13542%3C/arxiv_GOX%3E%3Curl%3E%3C/url%3E&disable_directlink=true&sfx.directlink=off&sfx.report_link=0&rft_id=info:oai/&rft_id=info:pmid/&rfr_iscdi=true |