HITS: High-coverage LLM-based Unit Test Generation via Method Slicing

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Wang, Zejun, Liu, Kaibo, Li, Ge, Jin, Zhi
Format: Preprint
Publié: 2024
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866929467825324032
author Wang, Zejun
Liu, Kaibo
Li, Ge
Jin, Zhi
author_facet Wang, Zejun
Liu, Kaibo
Li, Ge
Jin, Zhi
contents Large language models (LLMs) have behaved well in generating unit tests for Java projects. However, the performance for covering the complex focal methods within the projects is poor. Complex methods comprise many conditions and loops, requiring the test cases to be various enough to cover all lines and branches. However, existing test generation methods with LLMs provide the whole method-to-test to the LLM without assistance on input analysis. The LLM has difficulty inferring the test inputs to cover all conditions, resulting in missing lines and branches. To tackle the problem, we propose decomposing the focal methods into slices and asking the LLM to generate test cases slice by slice. Our method simplifies the analysis scope, making it easier for the LLM to cover more lines and branches in each slice. We build a dataset comprising complex focal methods collected from the projects used by existing state-of-the-art approaches. Our experiment results show that our method significantly outperforms current test case generation methods with LLMs and the typical SBST method Evosuite regarding both line and branch coverage scores.
format Preprint
id arxiv_https___arxiv_org_abs_2408_11324
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle HITS: High-coverage LLM-based Unit Test Generation via Method Slicing
Wang, Zejun
Liu, Kaibo
Li, Ge
Jin, Zhi
Software Engineering
Large language models (LLMs) have behaved well in generating unit tests for Java projects. However, the performance for covering the complex focal methods within the projects is poor. Complex methods comprise many conditions and loops, requiring the test cases to be various enough to cover all lines and branches. However, existing test generation methods with LLMs provide the whole method-to-test to the LLM without assistance on input analysis. The LLM has difficulty inferring the test inputs to cover all conditions, resulting in missing lines and branches. To tackle the problem, we propose decomposing the focal methods into slices and asking the LLM to generate test cases slice by slice. Our method simplifies the analysis scope, making it easier for the LLM to cover more lines and branches in each slice. We build a dataset comprising complex focal methods collected from the projects used by existing state-of-the-art approaches. Our experiment results show that our method significantly outperforms current test case generation methods with LLMs and the typical SBST method Evosuite regarding both line and branch coverage scores.
title HITS: High-coverage LLM-based Unit Test Generation via Method Slicing
topic Software Engineering
url https://arxiv.org/abs/2408.11324