The invention discloses a unit test instant automatic updating method based on a large
language model. Comprising the steps of collecting definitions, positions and code snippets of methods and classes related to test updating, removing irrelevant information in the definitions, the positions and the code snippets, and adding defined variables in test classes as supplements to serve as contexts required by the test updating; constructing a structured prompt according to the context information, guiding the large
language model to automatically update the corresponding unit test based on the production code change, and adding required dependencies at the same time; when compiling or testing fails, error context information is collected according to an error report, then error related information is added into a structured prompt, a large
language model is guided to be repaired and optimized, and therefore iterative
verification and improvement are conducted. According to the method, the failure test can be repaired, the
test quality can be enhanced by verifying the newly-added logic, the passing rate and the coverage rate of the
test code are improved, and the method is used for better coping with the outdated test problem caused by the change of the production code.