The invention discloses a unit
test code generation method,
system and device and a medium, which are applied to the technical field of
code generation, and comprise the following steps: performing
program structure interface analysis and
abstract syntax tree analysis on a target
engineering code to obtain a structured meta-information set and a
source code syntax structure model; generating a structured context
feature vector based on the structured meta-information set and the
source code grammar structure model, and retrieving a historical
test case sample set from a historical
test case database, wherein the global line coverage rate weighted similarity of the historical
test case sample set and the structured context
feature vector meets a matching condition; after Prompt template filling of different test subtasks is performed based on a historical test case sample set and structured
context data through an Agent agent, different modular test codes are generated by adopting different
test code generation models, and closed-loop
verification is performed after the different modular test codes are integrated into unit test codes. Therefore, the code quality, practicability and adaptability are improved.