Supply chain transaction business software test case automatic generation method, medium and system
By analyzing the software source code and transaction contract information, combining genetic algorithms and program instrumentation technology, the commodity supply chain software test cases are automatically generated, which solves the problems of low efficiency and high cost caused by relying on manpower in the existing technology, and achieves rapid, accurate and automated test case generation.
Patent Information
- Application Number
- CN202510196096.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2045-02-21
AI Technical Summary
The generation of existing commodity supply chain software test cases depends on manpower, resulting in low testing efficiency, high cost, and difficulty in ensuring the comprehensiveness and accuracy of test cases.
By analyzing the source code of the software to be tested and commodity supply chain transaction contract information, combining genetic algorithms and program insertion technology, test cases are automatically generated to achieve rapid, accurate and automated generation of test cases.
It significantly improves the efficiency and accuracy of software testing, reduces manual intervention, reduces testing costs, and ensures comprehensiveness and accuracy of test cases.
Smart Images

Figure CN119690853B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a method, medium and system for automatically generating test cases for supply chain transaction business software. Background Art
[0002] As the business models of various industries in the commodity supply chain become increasingly diversified, the scale and complexity of computer software systems have rapidly expanded, which undoubtedly brings unprecedented challenges to ensuring software quality. Given that software development is essentially a process that is highly dependent on human intellectual activities, perfection is difficult to achieve, and software defects may cause significant losses if they are not detected in time.
[0003] In the vast field of software testing, the selection and generation of test cases plays a pivotal role and occupies the core part of the testing work. This process covers multiple links from determining the function to be tested, deeply analyzing the input data set, defining its value range, to predicting and parsing the corresponding output data. The core concept of test case design is to expose potential errors to the maximum extent with the smallest set of test cases. If this process can be automated, it will significantly shorten the software development cycle and reduce development costs.
[0004] However, the current generation of commodity supply chain software test cases mainly relies on manpower, and requires testers to not only have a deep business understanding of the commodity supply chain across industries, but also have superb professional skills. This high reliance on manual labor has led to a lack of clear direction in the testing process, low testing efficiency, high software costs, and difficulty in effectively ensuring software quality. Although existing software testing tools support the automatic generation of test data to a certain extent, in actual operation, testers still need to conduct in-depth research on each module of the application under test and manually assign appropriate test data. This process is not only time-consuming and labor-intensive, but may also result in incomplete data coverage or redundancy. In addition, some tools use random algorithms to generate a large amount of test data. Although this method can improve data diversity, it also introduces a large amount of invalid or redundant data, making it difficult to accurately and efficiently verify module functions. Summary of the invention
[0005] The embodiment of the present invention provides a method for automatically generating test cases for supply chain transaction business software, which is applied in the testing of bulk commodity supply chain transaction business scenarios and can realize the automatic generation of actual bulk commodity supply chain transaction business scenario software test cases.
[0006] The method for automatically generating test cases for supply chain transaction business software includes:
[0007] Step 1, analyzing the acquired source code of the software to be tested to obtain the program control flow chart, industry and function of the software to be tested;
[0008] Step 2: Analyze the acquired commodity supply chain transaction contract information, generate test cases, and judge the test cases. If applicable, jump to step 9; if not, go to step 4.
[0009] Step 3, obtaining a program branch path set according to the program control flow chart obtained in step 1 and setting all branch paths as target paths;
[0010] Step 4, inserting the program according to each predicate condition in the target path in step 3 and formulating a preset fitness function value;
[0011] Step 5, setting genetic algorithm parameters to generate an initial test data set, wherein the initial test data refers to test cases generated by the genetic algorithm;
[0012] Step 6, using the test case generated in step 5 to execute the source code after the stub in step 4, obtain the target value of the generated test case, calculate the fitness value corresponding to the generated test case according to the target value, and then perform the selection operation in the genetic algorithm to obtain the first test case set;
[0013] Step 7, using a mutation operation in a genetic algorithm on the test cases in the first test case set to obtain a second test case set, performing a selection operation on new test cases in the second test case set to screen out new test cases whose fitness values are greater than a preset fitness value, thereby obtaining a third test case set;
[0014] Step 8, repeating steps 6 and 7 until a final test case set is obtained, wherein the test case set includes new test cases whose fitness values are greater than a preset fitness value among the new test cases generated each time, and the test cases in the first test case set;
[0015] Step 9, testing the software to be tested with the test cases in the final test case set to obtain test results; identifying the erroneous test results from the test results, extracting the suspected abnormal test cases corresponding to the erroneous test results, and identifying the suspected abnormal test cases to obtain abnormal identification results;
[0016] Step 10, use the test cases in the final test case set to test the software to be tested and obtain the test results; realize automatic association between test cases and code block information, accurate to the function level and code block level, accurately mark the association between test cases and code functions, and code test coverage, and at the same time identify the running code to determine the validity of the code.
[0017] Furthermore, step 2 includes the following process:
[0018] Step 21, obtaining commodity supply chain transaction contract information through OCR recognition;
[0019] Step 22, using the acquired contract information to obtain the corresponding scenario business and values, automatically write them into the test case;
[0020] Step 23, using the functions and industries of the software to be tested obtained in step 1 to perform a global search in the database, to obtain test cases and program flow charts of software with the same industry as the software to be tested and corresponding functions in the business scenario;
[0021] Step 24, determine whether the program flow chart of the software to be tested is the same as the program flow chart of software with similar functions and the same industry as the software to be tested. If they are the same, it is determined to be available, and the test cases of software with similar functions and the same industry as the software to be tested are used as test cases of the software to be tested and added to the final test case set for testing. If they are not the same, it is determined to be unavailable and proceeds to step 4.
[0022] Furthermore, step 4 includes the following process:
[0023] Step 41, by analyzing the source code of the program to be tested, finding the position of the predicate condition in the source code of the program to be tested;
[0024] Step 42, perform program insertion at the location and set a preset fitness value.
[0025] Furthermore, step 5 includes the following process:
[0026] Step 51, setting basic parameters of the genetic algorithm;
[0027] Step 52: Generate an initial test data set using the genetic algorithm.
[0028] Furthermore, the basic parameters of the genetic algorithm include population size, number of algorithm termination iterations, crossover probability, and mutation probability.
[0029] Furthermore, the setting range of the population size is 20 to 100, the range of the algorithm termination iteration number is 100 to 500, the range of the crossover probability is 0.4 to 0.9, and the range of the mutation probability is 0.0001 to 0.1.
[0030] Further, step 6 includes the following process:
[0031] Step 61, using the generated test case to execute the instrumented source code to obtain several target values of the generated test case;
[0032] Step 62, sorting the target values corresponding to each generated test case according to the size of the target value;
[0033] Step 63, obtaining the position information of each target value;
[0034] Step 64, calculating the fitness value corresponding to the test case;
[0035] Step 65, randomly selecting a generated test case to determine whether the fitness value of the generated test case is greater than a preset fitness value, if greater than the preset fitness value, outputting the test case and storing the test case;
[0036] Step 66, if it is not greater than the preset fitness value, then delete the test case;
[0037] Step 67, determining the stored test case as an element in the first test case set;
[0038] Step 68, matching the generated test cases with fitness values greater than the preset values with the software test cases obtained by the hill climbing algorithm and having the same industry and the same functions as the software to be tested and corresponding to the business scenario;
[0039] Step 69: exclude the unmatched generated test cases and determine the remaining test cases as the first test case set.
[0040] Furthermore, in step 9, when the suspected abnormal test case is identified and the abnormal identification result is obtained, it can be specifically:
[0041] The suspected abnormal test case is compared with the test cases of the same industry as the software to be tested and the corresponding functions of the business scenario to obtain a matching degree; if the matching degree is higher than the preset matching degree threshold, the suspected abnormal test case is determined to be a normal test case; if the matching degree is lower than the preset matching degree threshold, it is manually determined whether the test code corresponding to the suspected abnormal test case is an abnormal code; if it is an abnormal code, the abnormal code is handled exceptionally; if it is a normal code, the suspected abnormal test case is determined to be an abnormal test case, and the abnormal test case is deleted.
[0042] A computer-readable storage medium stores program instructions, which are used to implement the above method when executed.
[0043] A supply chain transaction business software test case automatic generation system includes the above-mentioned computer-readable storage medium.
[0044] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:
[0045] 1. The test cases of the software to be tested can be quickly obtained from multiple dimensions through the selection and mutation operations of genetic algorithms, combining the industry and function of the software to be tested, the branch type of the program branch of the software to be tested, the node type that generates the branch, etc. There is no need to rely on manual review of the code over and over again to find possible problems with the software as before.
[0046] 2. Technical personnel no longer need to have high requirements for actual transaction business. Accurate test cases can be automatically generated, effectively avoiding incomplete understanding of actual business scenarios and incomplete test case coverage caused by code reading. The powerful computing power of artificial intelligence can be directly relied on to quickly obtain test cases for the software to be tested, saving a lot of time and manpower, and greatly improving the efficiency of software detection.
[0047] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0048] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0050] Figure 1 The present invention is a flowchart of a method for automatically generating test cases for supply chain transaction business software disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0052] With the development of commodity supply chain transactions, there are more design industries, complex business models, and high complexity of software projects. The market has high requirements for the stability and reliability of software quality. Testing work is of great significance in software products. The original test case design technology can no longer meet our requirements for quality and efficiency.
[0053] In this regard, the present invention intelligently identifies actual business information, automatically generates test cases, tracks code execution, relies on relevant algorithms to predict and filter test cases, and reduces human resource investment and improves efficiency under complex modes or business logic. It has high market value and application promotion. It is currently only used for internal R&D test platforms, and will be recommended after subsequent products are improved to serve relevant demand units.
[0054] Specifically, Figure 1 A flow chart of a method for automatically generating test cases for supply chain transaction business software disclosed in an embodiment of the present invention is shown, which includes the following steps:
[0055] Step 1: Analyze the acquired source code of the software to be tested to obtain the program control flow chart, industry and function of the software to be tested.
[0056] include:
[0057] Step 11, obtaining the source code of the software to be tested;
[0058] Step 12, obtaining a program control flow chart through visustin software according to the obtained source code of the software to be tested;
[0059] Step 13, analyze the source code to obtain the algorithm logic of the source code, and combine the Python script to obtain the industry and function of the software to be tested.
[0060] Among them, using Python script to obtain the industry and function of the software to be tested adopts the existing technology, and its specific structure and principle are not repeated here.
[0061] Step 2: Analyze the acquired commodity supply chain transaction contract information, generate test cases, and judge the test cases. If available, jump to step 9; if not, go to step 4.
[0062] include:
[0063] Step 21, obtaining commodity supply chain transaction contract information through OCR recognition;
[0064] Step 22, using the acquired contract information to use a Python script to obtain the corresponding scenario business and values and automatically write them into the test case;
[0065] Step 23, using the functions and industries of the software to be tested obtained in step 1 to perform a global search in the database, to obtain test cases and program flow charts of software with the same industry as the software to be tested and corresponding functions in the business scenario;
[0066] According to the industry and function of the software to be tested obtained in step 1, a global search is performed in the database using a hill climbing algorithm to obtain software with the same industry and similar functions as the software to be tested;
[0067] For example, the industry and function of the software can be set as the initial state of the hill climbing algorithm, and the data in the database can be compared according to the set initial state to determine whether the software recorded in the database is in the same industry and has similar functions to the software to be tested. The software in the same industry and with similar functions to the software to be tested can be output to obtain software with similar functions and in the same industry as the software to be tested. The test cases of the software with similar functions and in the same industry as the software to be tested can be extracted to obtain test cases and program control charts for software with similar functions and in the same industry as the software to be tested.
[0068] It should be noted that the hill climbing algorithm is a commonly used global search algorithm. The hill climbing algorithm adopts a heuristic search method and is an improved search algorithm based on the depth-first search algorithm.
[0069] Step 24, determine whether the program flow chart of the software to be tested is the same as the program flow chart of software with similar functions and the same industry as the software to be tested. If they are the same, it is determined to be available, and the test cases of software with similar functions and the same industry as the software to be tested are used as test cases of the software to be tested and added to the final test case set for testing. If they are not the same, it is determined to be unavailable and proceeds to step 4.
[0070] Step 3, obtain a program branch path set according to the program control flow chart obtained in step 1 and set all branch paths as target paths.
[0071] A program control flow chart (also called a flowchart or control flow graph) is a graphical representation method for describing the control flow in a program. It uses standard graphical symbols to represent different elements in a program, such as sequential execution, selection (conditional branching), loops, etc.
[0072] Program branching is a core concept in programming, which allows a program to choose different execution paths according to certain conditions during execution. This mechanism enables the program to handle different inputs or states and perform different operations accordingly.
[0073] Step 4: According to the predicate conditions in the target path in step 3, the program is plugged and a preset fitness function value is formulated.
[0074] include:
[0075] Step 41, by analyzing the source code of the program to be tested, finding the position of the predicate condition in the source code of the program to be tested;
[0076] Step 42, perform program instrumentation at this position and set a preset fitness value.
[0077] Among them, the general form of the predicate condition is: E1 op E2, where E1 and E2 are arithmetic expressions, and the relational operator op ∈ {<, <=, >, >=, ==, !=}.
[0078] For example, in the statement "if(a < b)...", the predicate condition is a < b, and then perform instrumentation operations on the line before and after this statement;
[0079] The following takes the triangle classification function fragment as an example for instrumentation processing:
[0080] f1 = c - (a + b); / / Instrumentation 1
[0081] if(a + b > c) / / Predicate condition
[0082] {
[0083] f2 = min(abs(a - b), abs(b - c)); / / Instrumentation 2
[0084] Program instrumentation refers to inserting some probes into the program on the basis of ensuring the original logical integrity of the program under test. Through these probes (also known as "profilers"), the present invention adopts a non-invasive instrumentation technology to parse the application when the probe is started, perform instrumentation on the framework entry class with the ability to transmit use case meta-information, automatically parse the instrumentation positions of business classes through bytecode technology, restore the bytecode code through application decompilation, and visually present the executed and unexecuted code. Essentially, a probe is a code segment for information collection, and its purpose is to obtain the function call information of the program, make the logical structure of the program clearer, facilitate modularization of the program, so as to better obtain branch functions. Each predicate condition can be converted into an equivalent form: F rel 0, where F is the branch function.
[0085] When the condition of the branch predicate is E1 > E2 or E1 >= E2, the branch function of this branch is E2 - E1; when the branch predicate condition is E1 < E2 or E1 <= E2, the branch function of this branch is E1 - E2; when the branch predicate condition is E1 == E2, the branch function of this branch is abs(E1 - E2); if the branch predicate condition is E1 != E2, the branch function of this branch is -abs(E1 - E2).
[0086] The fitness function refers to the standard used to distinguish the quality of individuals in a population according to the objective function, so it is also called the evaluation function. The fitness function used in the present invention is:
[0087]
[0088] Among them, fit(x) represents the fitness value of the program to be tested, and f(x i ) is the branch function value after instrumenting each branch. When the condition of the branch predicate is E1>E2 or E1>=E2, the branch function of this branch is E2-E1. When the branch predicate condition is E1<E2 or E1<=E2, the branch function of this branch is E1-E2. When the branch predicate condition is E1=E2, the branch function of this branch is abs(E1-E2). If the branch predicate condition is E1!=E2, the branch function of this branch is -abs(E1-E2).
[0089] To reduce the error between the fitness value calculated by the above formula and the true fitness value, the following formula is used to calculate the fitness of the program to be tested:
[0090] F(x) = xsin[10×π×f(x i )]+2
[0091] The maximum value F(x) max of F(x) is determined as the fitness value of the program to be tested.
[0092] The following formula is used to calculate the weighted average of the fitness values calculated by the two fitness value formulas to obtain the best fitness value.
[0093] F = [(F(x) max ×f 2 )+(fit(x)×f 1 )] / 2
[0094] Among them, f 1 and f 2 respectively represent the weights of the fitness values obtained by the first fitness value calculation formula and the second fitness value calculation formula. The magnitudes of f 1 and f 2 can be determined according to the accuracy of the results obtained by the fitness value calculation formula. The higher the accuracy, the greater the corresponding weight. However, it always remains that f 1 +f 2 =1. F represents the best fitness value.
[0095] In addition, by continuously adding different fitness value calculation formulas, the more different fitness value calculation formulas are added, the smaller the error between the best fitness value obtained after the final weighted average and the true fitness value. In the present invention, the finally obtained best fitness value will be set as the preset fitness value of the genetic algorithm.
[0096] Step 5: Set the genetic algorithm parameters to generate an initial test data set, where the initial test data refers to the test cases generated by the genetic algorithm.
[0097] Set the basic parameters of the genetic algorithm. After the basic parameters of the genetic algorithm are set, the genetic algorithm is used to generate an initial test data set. The initial test data refers to the test cases generated by the genetic algorithm. The basic parameters of the genetic algorithm include population size, number of algorithm termination iterations, crossover probability, and mutation probability.
[0098] in,
[0099] The general setting range of population size is 20 to 100. If the population size is set too large, the algorithm will not converge due to the large amount of data. If the population is too small, abnormal data will be easily generated.
[0100] The range of the algorithm termination iteration number is generally set at 100 to 500. The present invention can be set according to its own needs. If you want to get the result quickly, you can set the iteration number to 100. If you want to get more comprehensive results, you can set the iteration number to 500.
[0101] The purpose of crossover and mutation is to generate new test data, and the probabilities are generally set to 0.4-0.9 and 0.0001-0.1. If the probabilities of crossover and mutation are set too large, the existing favorable patterns will be destroyed and the best results may be missed; if they are set too small, the diversity of test data will be insufficient and the best results cannot be obtained.
[0102] Step 6, use the test case generated in step 5 to execute the source code after the stub in step 4, obtain the target value of the generated test case, calculate the fitness value corresponding to the generated test case according to the target value, and then perform the selection operation in the genetic algorithm to obtain the first test case set.
[0103] The specific implementation of the selection operation is:
[0104] Use the generated test case to execute the instrumented source code, obtain several target values (ObjV) of the generated test case, sort the several target values (ObjV) corresponding to each generated test case according to the size of the target value to obtain the position information Position of each target value, and use the following formula to calculate the fitness value corresponding to the test case.
[0105]
[0106] Wherein, sp=0 or sp=1 indicates whether the branch function is linear or nonlinear; Nind indicates the length of the generated test case; μ indicates the branch type of the branch function, wherein the branch type includes ordinary branches and complex branches, and the branch type is determined according to the node that generates the branch. When the node that generates the branch is a node that can nest complex logic, such as a case node or an if-else node, the impact on subsequent branches lasts for a long time due to the ability to nest complex logic. Therefore, the branch type of the branch function generated by these nodes is a complex branch; and when the node that generates the branch is a node with relatively simple logic, such as a try-catch node, since multiple layers of branches are usually not nested, the impact on the branch function is generally short. Therefore, the branch type of the branch function generated by these nodes is an ordinary branch. Different μ values are set for different types of branches. Generally speaking, the μ value of a complex branch is higher than the μ value of an ordinary branch. The P value is used to characterize the appearance time of the branch node that generates the branch function in the overall test program. When the appearance time is earlier, the impact on the overall test program is greater, so the corresponding P value will be higher. The P value can be determined according to the following formula:
[0107]
[0108] Among them, S i Indicates the order in which the branch node that generates the branch function appears in the same type of nodes. For example, if the branch node that generates the branch function is a common branch node and it is the 11th common branch node that appears in the program to be tested, then S i =11; S m is the total number of nodes in the program to be tested that are of the same node type as the branch node that generates the branch function. For example, if the branch node generated for the branch function is an ordinary node and there are 100 ordinary branch nodes in the program to be tested, then S i Determined to be 100; S j is the order in which the branch node that generates the branch function appears in the entire program to be tested. For example, if the branch node that generates the branch function is a common branch node and is the 13th branch node that appears in the program to be tested, then S j =13; S 0 is the total number of nodes in the program to be tested. For example, if there are 120 branch nodes in the program to be tested, then S 0is 120; α and β are the weights corresponding to the type of node branch that generates the function branch and the weight corresponding to another type of node branch, respectively. When the node branch type that generates the function branch is an ordinary branch, considering that the number of ordinary branches is large and the impact is small, the value of α is smaller than the value of β; and when the node branch type that generates the function branch is a complex branch, considering that the number of complex branches is small and the impact is large, the value of α is greater than the value of β; α and β are 1.
[0109] A generated test case is randomly selected to determine whether the fitness value of the generated test case is greater than the preset fitness value. If it is greater than the preset fitness value, the test case is output and stored; if it is not greater than the preset fitness value, the test case is deleted. The stored test case is determined as an element in the first test case set. The probability of each test case being selected in the generated test is:
[0110] P S =fix(x)∑fix(x)
[0111] It can be concluded from the probability calculation formula that the larger the fitness value of the test case is, the higher the possibility of being selected. Compared with the previous method of comparing the fitness values of the generated test cases with the preset fitness values one by one, the selection efficiency is greatly improved.
[0112] The generated test cases with fitness values greater than the preset values are matched with the software test cases obtained by the hill climbing algorithm that are the same as the industry of the software to be tested and the same functions as the corresponding business scenarios, and the unmatched generated test cases are excluded, and the remaining test cases are determined as the first test case set. Among them, the generated test cases are matched with the software test cases with the same industry and the same functions as the corresponding business scenarios of the software to be tested, which means that the functions corresponding to the corresponding software and the industries and fields in which the software is applied are similar, which means that the generated test cases match the software test cases with the functions and industries of the software to be tested, and vice versa, which means that the generated test cases do not match the software test cases with the functions and industries of the software to be tested.
[0113] In another embodiment, through static code analysis, all branch statements in the program are marked, their code locations are recorded, and their code block structures are analyzed to determine whether they are complex logic branches, and a first test case set is obtained according to relevant selection operations:
[0114] The specific selection operations are as follows:
[0115] Step 6.1 uses the deep reinforcement learning policy network to generate the initialization test case. The reward function is as follows: R(s,a)=w1*N_covered+w2*N_new, where N_covered is the number of newly covered code lines after executing action a, and N_new is the number of newly triggered branch paths.
[0116] Step 6.2 abstractly interprets the source code and obtains the reachable path information for optimizing coverage calculation:
[0117] reachable(p)=symbolic_exec(p)∧unsat(neg_constraint(p)), where symbolic_exec performs symbolic execution to obtain path constraints, neg_constraint negates the constraints, and unsat detects unsatisfiability.
[0118] Step 6.3 performs execution evaluation on the test cases, obtains coverage information, calculates fitness, and sorts by fitness.
[0119] Step 6.4 uses a multi-objective genetic algorithm for optimization iteration. The genetic operations include:
[0120]
[0121] The trade-off between coverage and number of use cases. Roulette wheel selection, uniform crossover, and random mutation.
[0122] Step 6.5 Use knowledge graph technology to match similar software:
[0123] A combination of angle cosine similarity and Tonkas-Jaccard similarity to obtain relevant use cases.
[0124] Step 6.6 Train the test oracle based on historical operation data:
[0125] oracle(x)={1,if P(outlier(x)|h)>δ0,otherwise
[0126] Where h is the anomaly detection model trained with historical operation data.
[0127] Step 6.7: Perform case annotation and active learning on the generated cases to improve the filtering effect. Output the first test case set.
[0128] Step 7, using the mutation operation in the genetic algorithm on the test cases in the first test case set to obtain a second test case set, performing a selection operation on the new test cases in the second test case set to screen out new test cases whose fitness values are greater than a preset fitness value, thereby obtaining a third test case set.
[0129] The mutation operation refers to inverting the encoded random fragment of the test data retained after the selection operation to obtain new test data, for example, a BUG test is mutated into a functional test.
[0130] Step 8, repeating steps 6 and 7 until a final test case set is obtained, the test case set including new test cases whose fitness values are greater than a preset fitness value among the new test cases generated each time, and the test cases in the first test case set.
[0131] Step 9, test the software to be tested with the test cases in the final test case set to obtain test results; identify the erroneous test results from the test results, and extract the suspected abnormal test cases corresponding to the erroneous test results, identify the suspected abnormal test cases, and obtain abnormal identification results.
[0132] When the suspected abnormal test case is judged and the abnormal judgment result is obtained, it can be specifically:
[0133] The suspected abnormal test case is compared with the test cases of the same industry as the software to be tested and the corresponding functions of the business scenario to obtain a matching degree; if the matching degree is higher than the preset matching degree threshold, the suspected abnormal test case is determined to be a normal test case; if the matching degree is lower than the preset matching degree threshold, it is manually determined whether the test code corresponding to the suspected abnormal test case is an abnormal code; if it is an abnormal code, the abnormal code is handled exceptionally; if it is a normal code, the suspected abnormal test case is determined to be an abnormal test case, and the abnormal test case is deleted.
[0134] Step 10, use the test cases in the final test case set to test the software to be tested and obtain the test results; realize automatic association between test cases and code block information, accurate to the function level and code block level, accurately mark the association between test cases and code functions, and code test coverage, and at the same time identify the running code to determine the validity of the code.
[0135] A computer-readable storage medium stores program instructions, which are used to implement the above method when executed.
[0136] A supply chain transaction business software test case automatic generation system includes the above-mentioned computer-readable storage medium.
[0137] Through the above method, the present invention can combine the industry and function of the software to be tested, the branch type of the program branch of the software to be tested, the node type of the branch generated, etc. from multiple dimensions through the selection and mutation operations of the genetic algorithm to quickly obtain the test case of the software to be tested. It is no longer necessary to rely on manual review of the code over and over again as before to find possible problems with the software, and it is no longer necessary for technical personnel to have high requirements for actual transaction business. Accurate test cases can be automatically generated, which effectively avoids the situation where manual understanding of actual business scenarios is incomplete and test case coverage is incomplete due to code reading. The test cases of the software to be tested can be quickly obtained by directly relying on the powerful computing power of artificial intelligence, which saves a lot of time and manpower and greatly improves the efficiency of software detection.
[0138] It should be understood that the specific order or hierarchy of steps in the disclosed process is an example of an exemplary method. Based on design preferences, it should be understood that the specific order or hierarchy of steps in the process can be rearranged without departing from the scope of protection of the present disclosure. The attached method claims present the elements of the various steps in an exemplary order and are not intended to be limited to the specific order or hierarchy described.
[0139] In the above detailed description, various features are grouped together in a single embodiment to simplify the disclosure. This method of disclosure should not be interpreted as reflecting an intention that the embodiments of the claimed subject matter require more features than are clearly stated in each claim. On the contrary, as reflected in the appended claims, the invention is in a state of having less than all the features of the disclosed individual embodiments. Therefore, the appended claims are hereby expressly incorporated into the detailed description, with each claim standing on its own as a separate preferred embodiment of the invention.
[0140] Those skilled in the art will also appreciate that the various illustrative logic blocks, modules, circuits, and algorithmic steps described in conjunction with the embodiments herein can all be implemented as electronic hardware, computer software, or a combination thereof. In order to clearly illustrate the interchangeability between hardware and software, various illustrative components, blocks, modules, circuits, and steps are generally described above around their functions. Whether such functions are implemented as hardware or software depends on specific applications and the design constraints imposed on the entire system. A skilled person can implement the described functions in an alternative manner for each specific application, but such implementation decisions should not be interpreted as departing from the scope of protection of the present disclosure.
[0141] The steps of the method or algorithm described in conjunction with the embodiments herein may be directly embodied as hardware, a software module executed by a processor, or a combination thereof. The software module may be located in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a mobile disk, a CD-ROM, or any other form of storage medium well known in the art. An exemplary storage medium is connected to the processor so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium may also be an integral part of the processor. The processor and the storage medium may be located in an ASIC. The ASIC may be located in a user terminal. Of course, the processor and the storage medium may also be present in a user terminal as discrete components.
[0142] For software implementation, the techniques described in this application can be implemented with modules (e.g., procedures, functions, etc.) that perform the functions described in this application. These software codes can be stored in a memory unit and executed by a processor. The memory unit can be implemented within the processor or outside the processor. In the latter case, it is coupled to the processor in a communication manner via various means, which are well known in the art.
[0143] The above description includes examples of one or more embodiments. Of course, it is impossible to describe all possible combinations of components or methods for the purpose of describing the above embodiments, but it should be recognized by those skilled in the art that the various embodiments may be further combined and arranged. Therefore, the embodiments described herein are intended to cover all such changes, modifications and variations that fall within the scope of protection of the appended claims. In addition, with respect to the term "comprising" used in the specification or claims, the word is covered in a manner similar to the term "including", just as "including," is explained as a transitional word in the claims. In addition, any term "or" used in the specification of the claims is intended to mean "non-exclusive or".
Claims
1. A method for automatically generating test cases for supply chain transaction business software, characterized in that: include: Step 1, analyzing the acquired source code of the software to be tested to obtain the program control flow chart, industry and function of the software to be tested; Step 2: Analyze the acquired commodity supply chain transaction contract information, generate test cases, and judge the test cases. If applicable, jump to step 9; if not, go to step 4. Step 3, obtaining a program branch path set according to the program control flow chart obtained in step 1 and setting all branch paths as target paths; Step 4, inserting the program according to each predicate condition in the target path in step 3 and formulating a preset fitness function value; Step 5, setting genetic algorithm parameters to generate an initial test data set, wherein the initial test data refers to test cases generated by the genetic algorithm; Step 6, using the test case generated in step 5 to execute the source code after the stub in step 4, obtain the target value of the generated test case, calculate the fitness value corresponding to the generated test case according to the target value, and then perform the selection operation in the genetic algorithm to obtain the first test case set; Step 6 includes the following process: Step 61, using the generated test case to execute the instrumented source code to obtain several target values of the generated test case; Step 62, sorting the target values corresponding to each generated test case according to the size of the target value; Step 63, obtaining the position information of each target value; Step 64, calculating the fitness value corresponding to the test case; Step 65, randomly selecting a generated test case to determine whether the fitness value of the generated test case is greater than a preset fitness value, if greater than the preset fitness value, outputting the test case and storing the test case; Step 66, if it is not greater than the preset fitness value, then delete the test case; Step 67, determining the stored test case as an element in the first test case set; Step 68, matching the generated test cases with fitness values greater than the preset values with the software test cases obtained by the hill climbing algorithm and having the same industry and the same functions as the software to be tested and corresponding to the business scenario; Step 69, excluding the unmatched generated test cases, and determining the remaining test cases as the first test case set; Step 7, using a mutation operation in a genetic algorithm on the test cases in the first test case set to obtain a second test case set, performing a selection operation on new test cases in the second test case set to screen out new test cases whose fitness values are greater than a preset fitness value, thereby obtaining a third test case set; Step 8, repeating steps 6 and 7 until a final test case set is obtained, wherein the test case set includes new test cases whose fitness values are greater than a preset fitness value among the new test cases generated each time, and the test cases in the first test case set; Step 9, testing the software to be tested with the test cases in the final test case set to obtain test results; identifying the erroneous test results from the test results, extracting the suspected abnormal test cases corresponding to the erroneous test results, and identifying the suspected abnormal test cases to obtain abnormal identification results; In step 9, when the suspected abnormal test case is judged and the abnormal judgment result is obtained, it can be specifically: The suspected abnormal test case is compared with the test cases of the same industry as the software to be tested and the corresponding functions of the business scenario to obtain a matching degree; if the matching degree is higher than the preset matching degree threshold, the suspected abnormal test case is determined to be a normal test case; if the matching degree is lower than the preset matching degree threshold, it is manually determined whether the test code corresponding to the suspected abnormal test case is an abnormal code; if it is an abnormal code, the abnormal code is handled exceptionally; if it is a normal code, the suspected abnormal test case is determined to be an abnormal test case, and the abnormal test case is deleted.
2. The method according to claim 1, characterized in that Step 2 includes the following processes: Step 21, obtaining commodity supply chain transaction contract information through OCR recognition; Step 22, using the acquired contract information to obtain the corresponding scenario business and values, automatically write them into the test case; Step 23, using the functions and industries of the software to be tested obtained in step 1 to perform a global search in the database, to obtain test cases and program flow charts of software with the same industry as the software to be tested and corresponding functions in the business scenario; Step 24, determine whether the program flow chart of the software to be tested is the same as the program flow chart of software with similar functions and the same industry as the software to be tested. If they are the same, it is determined to be available, and the test cases of software with similar functions and the same industry as the software to be tested are used as test cases of the software to be tested and added to the final test case set for testing. If they are not the same, it is determined to be unavailable and proceeds to step 4.
3. The method according to claim 1, characterized in that Step 4 includes the following process: Step 41, by analyzing the source code of the program to be tested, finding the position of the predicate condition in the source code of the program to be tested; Step 42, perform program insertion at the location and set a preset fitness value.
4. The method according to claim 1, characterized in that Step 5 includes the following process: Step 51, setting basic parameters of the genetic algorithm; Step 52: Generate an initial test data set using the genetic algorithm.
5. The method according to claim 4, characterized in that The basic parameters of genetic algorithms include population size, number of algorithm termination iterations, crossover probability, and mutation probability.
6. The method according to claim 5, characterized in that The setting range of population size is 20 to 100, the range of algorithm termination iterations is 100 to 500, the range of crossover probability is 0.4 to 0.9, and the range of mutation probability is 0.0001 to 0.
1.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, and the program instructions are used to implement the method according to any one of claims 1 to 6 when executed.
8. Supply chain transaction business software test case automatic generation system, characterized by: Includes the computer-readable storage medium of claim 7.
Citation Information
Patent Citations
Software test data set amplification method based on beetle antennae search
CN111666221A
Test case generation method and system, terminal equipment and storage medium
CN113672503A