The invention provides a C language unit test generation method based on a
reference test case, and belongs to the field of
software engineering. Comprising the following steps: constructing a C project symbol index
knowledge base; performing
test case migration association retrieval; and generating a
test case based on the
reference test mode. According to the method, the pairwise resource'application / release 'mode is extracted and forcibly applied from the existing test, so that the problem that memory leakage may be introduced into the generated C language
test case is solved; by injecting the test mode extracted from the real code, the generated test case is highly consistent with the tested item in
data structure initialization, function call agreement and code style, and the
readability and
maintainability of the
test code are improved; the expert knowledge and the generation capability of the large
language model are deeply fused, and the test environment establishment and resource cleaning work are
fully automated, so that the cost and time for compiling a high-quality test for a complex C language project are remarkably reduced.