Abstract:Software testing is one of the most time-consuming stages in the software development process. Potential errors in software can be found efficiently and in a timely manner by automatically executing a large number of test cases, which is an important technology development trend to improve the quality of large and medium-sized software development. Currently more meta-heuristic optimization algorithms have been able to automatically generate test cases, but the test efficiency is low and the overhead is large, so how to make the generated test cases cover as many goals as possible with a small number of test cases is the core technical issues in the generation of automated test cases. This paper proposes a loss function-based automatic generation algorithm for unit test cases (LFGA). During the execution of the genetic algorithm, the subsequent population distribution is changed dynamically to ensure the balance of the overall data distribution according to the path coverage of the test case population. The branch information is introduced to optimize the adaptive cross-mutation operator to automatically generate an effective test case set with as small scale and high coverage as possible. The experimental results show that, compared with the existing automatic test case generation method, the method proposed in this paper can better solve the defects of the traditional model such as initial value dependence, premature convergence, and lagging local optimization ability, and the average coverage rate of generated test cases reaches 95%, which improves search efficiency and data utilization efficiency.