Unit testing method and device, electronic device and storage medium
By iteratively processing the statement group of the simulation object and determining the assertion part, the target statement set is defined, which solves the problems of low adaptation of the simulation object and low search efficiency in the existing technology, and achieves higher adaptability and accuracy as well as lower computational overhead.
Patent Information
- Application Number
- CN202211200156.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-29
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-09-29
AI Technical Summary
In the prior art, the behavior settings of the simulation objects are artificial and single, resulting in low adaptability and single adaptability, as well as low search efficiency and low individual accuracy during the iterative update process of the Stub Code.
By determining the current statement group, including multiple statement sets, each statement set contains statement subsets, and the statement subsets include statements that define the behavior of the simulation object and dependent statements, iterative processing is performed, and the target statement set is determined based on the assertion part of the test case to define the simulation object.
The adaptability and accuracy of the simulated objects are improved, the possibility of generating incorrect individuals is reduced, the computational overhead is reduced, and the search efficiency is improved.
Smart Images

Figure CN115587030B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to, but are not limited to, the field of software testing technology, and in particular to a unit testing method and apparatus, an electronic device, and a storage medium. Background Art
[0002] Unit testing involves checking and verifying the smallest testable unit in software. Because some code modules in a test case have dependencies (e.g., external classes, interfaces, etc.) that are difficult to obtain or create, it's necessary to create appropriate mock objects to replace them for unit testing.
[0003] In related technologies, users can manually create mock objects based on actual scenario requirements and use stub code to specify their behavior. However, these manually configured behaviors only adapt the mock object and its behavior to the current scenario, failing to adapt to other scenarios. This leads to problems such as low accuracy and limited adaptability. Furthermore, during the iterative update of the stub code, on the one hand, the search space is too large, resulting in low search efficiency; on the other hand, due to the overly coarse assessment of individual quality, individual accuracy is low and good individuals are easily screened out. Summary of the Invention
[0004] In view of this, embodiments of the present application provide a unit testing method and apparatus, an electronic device, a storage medium, and a computer program product.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] In a first aspect, an embodiment of the present application provides a unit testing method, the method comprising:
[0007] Determine a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement;
[0008] Iteratively processing the current sentence group to obtain the next sentence group;
[0009] Determining a target statement set based on the assertion portion of the first test case and the next statement group, wherein the target statement set is used to define the simulation object;
[0010] The unit test is performed on the first test case based on the simulation object.
[0011] In a second aspect, an embodiment of the present application provides a unit testing device, the device comprising:
[0012] A first determining module is configured to determine a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement;
[0013] An iteration module, configured to iteratively process the current sentence group to obtain a next sentence group;
[0014] A second determining module is configured to determine a target statement set based on the assertion portion of the first test case and the next statement group, wherein the target statement set is used to define the simulation object;
[0015] A testing module is used to perform the unit test on the first test case based on the simulation object.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and the processor implements the steps in the above method when executing the computer program.
[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.
[0018] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program implements the above method when read and executed by a computer.
[0019] In an embodiment of the present application, a current statement group is determined, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; the current statement group is iteratively processed to obtain a next statement group; a target statement set is determined based on the assertion part of the first test case and the next statement group; and the first test case is unit tested based on the simulation object. In this way, firstly, the behavior of the simulation object in different scenarios is defined by using multiple statement sets, which can improve the adaptability of the simulation object; secondly, by defining the behavior statement of the simulation object and its dependent statements in the statement subset, the corresponding behavior statement and its dependent statements can be exchanged at the same time during the iterative processing, thereby reducing the possibility of generating incorrect individuals, thereby not only reducing computational overhead but also improving search efficiency; then, the target statement set of the simulation object is obtained based on the assertion part and the next statement group, which can improve the accuracy and applicability of the simulation object; finally, the simulation object is used for unit testing without relying on the real object in the program module, thereby achieving the separation of the program module and the dependent object, thereby helping to improve software testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1A A schematic diagram of an application scenario of a unit testing method provided in an embodiment of the present application;
[0021] Figure 1B A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application;
[0022] Figure 2 A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application;
[0023] Figure 3A A schematic diagram of the structure of a unit test system provided in an embodiment of the present application;
[0024] Figure 3B A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application;
[0025] Figure 3C A schematic diagram of an implementation flow for generating the next sentence group provided in an embodiment of the present application;
[0026] Figure 4 A schematic diagram of the structure of a unit test device provided in an embodiment of the present application;
[0027] Figure 5 A hardware entity diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions of this application are further elaborated in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0029] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0030] If similar descriptions of "first / second" appear in the application documents, the following explanation is added. In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0031] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0032] In related technologies, users can manually create mock objects based on actual scenario requirements and use stub code to specify the mock object's behavior. However, such manually set behaviors make the mock object and its behavior only adaptable to the current scenario, and not to other scenarios, resulting in low accuracy and limited adaptability. During the iterative update of the stub code, first, the search space is too large due to the use of a zero-based search for the stub code, resulting in low search efficiency. Second, the fitness assessment of individual quality is too coarse, resulting in low individual accuracy and the easy elimination of good individuals. Finally, since only behavioral statements are exchanged during the crossover process, a large number of incorrect offspring are easily generated. At the same time, since the correctness of the offspring is not considered, the computational overhead is greatly increased.
[0033] The present application embodiment provides a kind of unit testing method, first, utilizes multiple statement sets to define the behavior of the simulation object under different scenes, can improve the adaptability of simulation object; Secondly, by defining the behavior statement of simulation object and its dependent statement in statement subset, can exchange corresponding behavior statement and its dependent statement together in iterative process, thereby can reduce the possibility of output incorrect individual, thereby can not only reduce computational overhead, but also improve search efficiency; Then, obtain the target statement set of simulation object based on assertion part and next statement group, can improve the accuracy and applicability of simulation object; Finally, use simulation object to carry out unit testing, without having to rely on the real object in program module, realize the separation of program module and dependent object, thereby contribute to improving software testing efficiency. The unit testing method that the present application embodiment provides can be performed by electronic device, wherein electronic device can be various types of terminals such as notebook computer, tablet computer, desktop computer, set-top box, mobile device (for example, mobile phone, portable music player, personal digital assistant, dedicated messaging device, portable game device), can also be implemented as server. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0034] Figure 1A This is an application scenario diagram of a unit testing method provided in an embodiment of the present application. Figure 1A As shown, the genetic variation process of the population is realized by using a genetic algorithm, including steps S101 to S106, wherein:
[0035] Step S101: randomly generate M individuals as the initial population P(0);
[0036] Step S102: Calculate the fitness of each individual in the population P(t);
[0037] Step S103: Based on the fitness of each individual, a selection operator is applied to the group P(t);
[0038] Here, the purpose of selection is to pass the optimized individuals directly to the next generation or to produce new individuals through pairing and crossover and then pass them on to the next generation.
[0039] Step S104: Apply the crossover operator to the group P(t);
[0040] Here, the crossover operator plays a core role in the genetic algorithm.
[0041] Step S105: Apply the mutation operator to the population P(t) to obtain the next generation population P(t+1);
[0042] Here, the gene values at certain loci of individual strings in the population are changed.
[0043] Step S106: If the termination condition is met, the individual with the maximum fitness obtained in the evolution process is output as the optimal solution and the calculation is terminated.
[0044] Here, the termination conditions may include but are not limited to when the fitness of the optimal individual reaches a given threshold, the fitness of the optimal individual and the fitness of the group no longer increase, or the number of iterations reaches a preset number of generations.
[0045] In unit testing, for a test case (T) that uses a mock object, you can first model T as follows:
[0046] T=<M,S,E,A> ;
[0047] Among them, M represents the simulation object creation part, which is used to create the mock object needed for testing; S represents the stub code part, which is used to specify how the mock object in M responds to its method calls; E represents the test code execution part, which is used to call the functions of the object under test for testing; A represents the test assertion part, which is used to judge the correctness of the test running results.
[0048] During implementation, the test cases can be segmented according to the following segmentation method to obtain the four parts M, S, E, and A mentioned above, namely:
[0049] M: includes the part from the beginning of the test case to the first when(...)then statement;
[0050] S: From the first when(...)then statement to the first reference to the Mock Object;
[0051] E: From the first reference to the Mock Object to the first JUint assertion or Mockito verity(...) code section;
[0052] A: From the first JUint assertion or Mockito verity(…) to the end of the test case.
[0053] Among them, JUnit is a unit testing framework for Java language, and Mockito is a simulation testing framework for Java development.
[0054] For example, the following test case can be divided into four parts according to the above segmentation method, namely: a first part M1, a second part S1, a third part E1 and a fourth part A1.
[0055]
[0056] Then, when the test case depends on the simulation object, a genetic algorithm can be used to search for a target statement set that meets the test assertion from several statement sets that define the simulation object, and use the target statement set to define the simulation object.
[0057] Figure 1B A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application is shown as follows: Figure 1B As shown, the method includes steps S11 to S14, wherein:
[0058] Step S11, determine the current statement group, the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement.
[0059] Here, the current statement group can be the initial statement group or the descendant statement group after iterative processing. The types of statements in the statement set can include but are not limited to statements containing variables, statements containing parameters, statements containing action statements, etc.
[0060] In some implementations, a certain set of statements in the initial statement group can be represented by the following target abstract syntax for the S portion of the test case. The target abstract syntax includes:
[0061] S:=Elem*
[0062] Elem:=VarDef|StubCall
[0063] VarDef:=v←Expr
[0064] Expr:=Literal|Array(v*)|API(v*)|Mock
[0065] StubCall:=<v,m,ArgMatcher*> →Reaction
[0066] ArgMatcher:=Any|Eq(v)
[0067] Reaction:=Return(v)|Throw(v)
[0068] in:
[0069] S: corresponds to the entire Stub Code part, S can be expanded into zero or more Elems.
[0070] Elem: Represents a line of code in the Stub Code. This line of code can define a variable (VarDef) or specify a behavior for a Mock Object (StubCall).
[0071] VarDef: variable definition, which assigns the result of an expression (Expr) to a variable (v).
[0072] StubCall: Specifies a behavior for a Mock Object, which means "when the Mock Object pointed to by the variable v is called with method m and the parameters of the call meet a series of ArgMatcher constraints, execute the behavior specified by React".
[0073] ArgMatcher: Used to match a single parameter of a method call. It contains two forms, namely, Any can match any parameter, and Eq(v) can match a parameter whose value is equal to the variable v.
[0074] Reaction: Indicates the behavior of the method, which includes two forms, namely, Return(v) returns the value of variable v, and Throw(v) throws the exception referred to by variable v.
[0075] For example, for the following Stub Code,
[0076] var sha1=DigestUtils.sha1Hex("bar");
[0077] when(user.getPasswordHash()).thenReturn(sha1);
[0078] when(dao.findUser(eq("foo"))
[0079] .thenThrow(new TimeoutException());
[0080] .thenReturn(user);
[0081] Based on the above target abstract syntax, we can know that sentences 1, 2, 4, and 5 can be expressed as VarDef:=v←Expr, and sentence 3 can be expressed as StubCall:=<v,m,ArgMatcher*> →Reaction is used to represent the Stub Code. Finally, the Stub Code can be represented as:
[0082] v0←"foo"
[0083] v1←new TimeoutException
[0084] <dao,finduser,[Eq(v0)]> →Throw(v1)
[0085] <dao,finduser,[Eq(v0)]> →Return(user)
[0086] v2←″bar″
[0087] v3←DigestUtils.sha1Hex(v2)
[0088]
[0089] At this time, the statement set includes two statement subsets, where statement subset 1 includes {v0←"foo", v1←newTimeoutException,<dao,finduser,[Eq(v0)]> →Throw(v1),<dao,finduser,[Eq(v0)]> →Return(user)}, statement subset 2 includes
[0090] In some embodiments, each statement set in the initial statement group may be the same or different. For example, each statement set in the initial statement group may be the same and not empty. For another example, some statement sets in the initial statement group may be the same and not empty, while other statement sets may be empty.
[0091] The functions of the simulated object may include but are not limited to network requests, databases, input, output, file systems, etc.
[0092] Step S12: Iterate the current sentence group to obtain the next sentence group.
[0093] Here, the iterative processing includes at least a cross-interchange processing. The cross-interchange processing refers to cross-interchanging the first statement subset and the second statement subset. The first statement subset is determined from at least one statement subset in the first statement set. The second statement subset is determined from at least one statement subset in the second statement set. The first statement set and the second statement set are determined from at least two statement sets in the current statement group using a preset selection algorithm. The selection algorithm can be any suitable algorithm that can perform selection. For example, tournament selection method, random, etc. During implementation, those skilled in the art can independently determine the selection algorithm according to actual needs, and the embodiments of the present application are not limited thereto.
[0094] In some embodiments, the first sentence subset can be determined based on preset rules. Preset rules may include, but are not limited to, default, random, custom, user preferences, usage frequency, user operation information, etc. During implementation, those skilled in the art can independently set preset rules based on actual needs, and this embodiment of the application does not limit this.
[0095] For example, the electronic device provides a configuration option through which the user can customize the first subset of sentences. For another example, the first subset of sentences can be determined based on the attribute information of the user's operation on the operation interface, where the operation interface can be a page displayed by the electronic device. The attribute information may include but is not limited to the type of operation, operation distance, speed, position, duration, number of times, etc. During implementation, those skilled in the art can independently set the correspondence between the attribute information of the operation and the first subset of sentences according to actual needs, and the embodiments of the present application are not limited thereto.
[0096] In some embodiments, the first statement subset can be determined based on the type of operation, that is, different types correspond to different first statement subsets. For example, when the operation gesture is a sliding operation, the first statement subset is the third statement subset in the first statement set; when the operation gesture is a multiple-click operation, the first statement subset is the fourth statement subset in the first statement set.
[0097] In some implementations, the first sentence subset can be determined in real time based on the operation distance, i.e., different operation distances correspond to different first sentence subsets. For example, when the sliding distance is within the first distance interval, the first sentence subset is the second sentence subset in the first sentence set; when the sliding distance is within the second distance interval, the first sentence subset is the third sentence subset in the first sentence set.
[0098] In some implementations, the second subset of sentences is determined from the second set of sentences in the same manner as the first subset of sentences is determined from the first set of sentences.
[0099] The number of statement sets in the next statement group is the same as the number of statement sets in the current statement group. For example, if the current statement group includes 10 statement sets, then the next statement group also includes 10 statement sets.
[0100] Step S13: Determine a target statement set based on the assertion portion of the first test case and the next statement group, where the target statement set is used to define the simulation object.
[0101] Here, the target sentence set may be a sentence set in the next sentence group or a sentence set in a new next sentence group, wherein the new next sentence group is a sentence group obtained after performing at least one iterative process on the next sentence group.
[0102] In some embodiments, step S13 includes step S131 and / or step S132, wherein:
[0103] Step S131 : When a statement set that conforms to the assertion part of the first test case exists in the next statement group, the statement set that conforms to the assertion part of the first test case is used as the target statement set.
[0104] Here, the assertion section includes at least assertions. Assertions are a type of first-order logic within a program that expresses and verifies the results expected by the software developer. When the program executes to the assertion point, the corresponding assertion should be true. If the assertion is not true, the program will terminate execution and generate an error message.
[0105] When a certain statement set in the next statement group passes the assertion, the statement set is used as the target statement set.
[0106] Step S132: If there is no statement set in the next statement group that meets the assertion part of the first test case, take the next statement group as the new current statement group, perform the iterative processing on the new current statement group to obtain a new next statement group, and determine the target statement set based on the assertion part of the first test case and the new next statement group.
[0107] Here, if every statement set in the next statement group fails the assertion, the next loop is performed. The next loop includes: taking the next statement group as the new current statement group; iteratively processing the new current statement group to obtain a new next statement group; if there is a statement set in the new next statement group that meets the assertion, the statement set that meets the assertion is used as the target statement set and the loop is terminated; otherwise, the next loop is continued.
[0108] Step S14: Perform the unit test on the first test case based on the simulation object.
[0109] The meaning of the word "unit" in unit testing generally depends on the specific situation. A unit essentially refers to the smallest functional module under test, as defined by humans. For example, in C, a unit refers to a function; in Java, a unit refers to a class; in graphical software, a unit can refer to a window or a menu.
[0110] In some implementations, a simulation object is defined using a target statement set to replace the stub code in the first test case, and the unit test is performed using the first test case after the stub code is replaced.
[0111] In an embodiment of the present application, a current statement group is determined, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavioral statement for defining a simulation object and at least one dependent statement of the behavioral statement; the current statement group is iteratively processed to obtain a next statement group; based on the assertion part of the first test case and the next statement group, a target statement set is determined, wherein the target statement set is used to define the simulation object; and the unit test is performed on the first test case based on the simulation object. In this way, first, by using multiple statement sets to define the behavior of simulation objects in different scenarios, the adaptability of simulation objects can be improved; second, by defining the behavior statements and dependent statements of simulation objects in statement subsets, the corresponding behavior statements and dependent statements can be exchanged at the same time during the iterative processing, thereby reducing the possibility of producing incorrect individuals, which not only reduces the computational overhead but also improves the search efficiency; then, based on the assertion part and the next statement group, the target statement set of the simulation object is obtained, which can improve the accuracy and applicability of the simulation object; finally, using simulation objects for unit testing without relying on real objects in the program module realizes the separation of program modules and dependent objects, which helps to improve software testing efficiency.
[0112] In some embodiments, step S11 includes steps S111 to S113, wherein:
[0113] Step S111: parse the first test case to obtain a stub code portion.
[0114] Here, the first test case can be segmented according to the above segmentation method to obtain four parts: M, S, E, and A.
[0115] Step S112: parse the stub code portion using a preset abstract syntax to generate an initial statement group.
[0116] Here, the abstract syntax can be the above-mentioned target abstract syntax. During implementation, the above-mentioned target abstract syntax is used to parse S in the first test case to obtain a statement set, and the statement set is used as a statement set in the initial statement group. In some embodiments, the initial statement group includes at least two identical statement sets, each statement set includes at least one statement subset, and each statement subset includes a behavioral statement for defining a simulation object and at least one dependent statement of the behavioral statement. For example, the initial statement group includes 10 statement sets, and each statement set is a statement set obtained by parsing S in the first test case.
[0117] Step S113: Use the initial sentence group as the current sentence group.
[0118] In the embodiment of the present application, the first test case is parsed to obtain a stub code portion; the stub code portion is parsed using a preset abstract syntax to generate an initial statement group; and the initial statement group is used as the current statement group. In this way, parsing the stub code portion using a high-level abstract syntax can reduce the search space and computational overhead in subsequent iterative processing.
[0119] Figure 2 A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, the method includes steps S21 to S25, wherein:
[0120] Step S21, determine the current statement group, the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement.
[0121] Here, the above step S21 corresponds to the above step S11. When implementing, reference may be made to the specific implementation of the above step S11.
[0122] Step S22: Perform fitness evaluation processing on each of the sentence sets in the current sentence group to obtain the fitness of each of the sentence sets in the current sentence group.
[0123] Here, the fitness of each statement set may be the same or different. During implementation, the fitness of the statement set may be obtained by using a relevant fitness function. Before performing fitness evaluation on the statement set, a corresponding second test case may be generated based on the statement set, and operation data may be collected during the execution of the second test case. The operation data may include at least one of the following: the total number of statement subsets in S, the number of statement subsets that have been successfully executed in S, the total number of test statements in E, the number of test statements that have been successfully executed in E, the total number of assertion statements in A, the number of statements that meet the assertion statement, the expected value and actual value of each assertion statement, etc.
[0124] In some implementations, a third fitness function corresponding to the statement set may be determined based on the number of statement subsets that have been successfully executed in S, and the fitness of the statement set may be obtained based on the third fitness function.
[0125] Among them, the third fitness function SE(S) characterizes the effectiveness of S. The method of determining the third fitness function may include but is not limited to the number of statement subsets that have been successfully executed, a function with the number of statement subsets that have been successfully executed as an independent variable, the ratio between the number of statement subsets that have been successfully executed and the total number of statement subsets, the ratio after weighting the number of statement subsets that have been successfully executed and the total number of statement subsets, etc. During implementation, those skilled in the art can choose the method of determining the third fitness function according to actual needs, and the embodiments of the present application are not limited thereto.
[0126] In some embodiments, the SE(S) can be expressed by the following formula (1-1):
[0127]
[0128] Among them, used(S) represents the number of statement subsets that have been successfully executed.
[0129] For example, part S includes three statement subsets, and the format of the statement subset that has been successfully executed is two. At this time, according to the above formula (1-1), it can be seen that SE(S) is 0.197.
[0130] In some implementations, the fitness of the statement set may be determined based on the fitness values of the respective parts of the second test case, wherein the fitness value of each part is obtained based on a corresponding fitness function.
[0131] The method of determining the fitness of a statement set may include, but is not limited to, a certain fitness value, the sum / difference / variance / mean square error of some fitness values, the sum / difference / variance / mean square error of some fitness values after weighting, the sum / difference / variance / mean square error of each fitness value, the sum / difference / variance / mean square error of each fitness value after weighting, etc. During implementation, those skilled in the art may independently select the method of determining the fitness of a statement set according to actual needs, and the embodiments of this application are not limited thereto.
[0132] In some implementations, the fitness of the statement set can be obtained by the following formula (1-2):
[0133] fitness(S)=a1·SE(S)+a2·EC(S)+a3·A(S) (1-2);
[0134] Among them, SE(S) represents the fitness value of the S part, EC(S) represents the fitness value of the E part, A(S) represents the fitness value of the A part, and a1~a3 represent the weight values of the corresponding fitness values respectively.
[0135] In some embodiments, a1 to a3 are in increasing order. For example, a1 to a3 can be 1, 2, and 4, respectively.
[0136] For example, assuming SE(S) is 0.197, EC(S) is 0.7, A(S) is 1.058, and a1 to a3 are 1, 2, and 4, respectively, then according to the above formula (1-2), fitness(S) is 5.829.
[0137] It should be understood that the above formula for determining fitness is only used as an example, and during implementation, the fitness function used to determine fitness may be added or deleted.
[0138] In some implementations, a fourth fitness function corresponding to the test portion may be determined based on the number of test statements that have been successfully executed in E, and the fitness value of the test portion may be obtained based on the fourth fitness function.
[0139] Among them, the fourth fitness function EC(S) characterizes the test code coverage. The method of determining the fourth fitness function may include but is not limited to the number of test statements that have been successfully executed, a function with the number of test statements that have been successfully executed as an independent variable, the ratio between the number of test statements that have been successfully executed and the total number of test statements, the ratio after weighting the number of test statements that have been successfully executed and the total number of test statements, etc. During implementation, those skilled in the art can choose the method of determining the fourth fitness function according to actual needs, and the embodiments of the present application are not limited thereto.
[0140] In some embodiments, the EC(S) can be represented by the following formula (1-3):
[0141]
[0142] Among them, |E| represents the total number of test statements, and |{e∈E,e is executed}| represents the number of test statements that are successfully executed.
[0143] For example, the test part includes 10 test statements, of which 7 are successfully executed. At this time, according to the above formula (1-3), EC(S) is 0.7.
[0144] In some embodiments, the first fitness function corresponding to the assertion part can be determined based on the number of assertion statements that have been satisfied in A; the second fitness function corresponding to the assertion part can be determined based on the expected value and actual value of each assertion statement; and the fitness value of the assertion part can be obtained based on the first fitness function and the second fitness function.
[0145] The first fitness function AC(S) represents the test assertion coverage, and the second fitness function AD(S) represents the distance between assertions.
[0146] Methods for determining the fitness value of the assertion portion may include, but are not limited to, the value of the first fitness function, the value of the second fitness function, the sum / difference / product / ratio / square / variance / mean square error between the values of the first fitness function and the second fitness function, and the sum / difference / product / ratio / square / variance / mean square error after weighting the values of the first fitness function and the second fitness function, etc. During implementation, those skilled in the art may independently select a method for determining the fitness value of the assertion portion based on actual needs, and this embodiment of the application does not limit this.
[0147] In some embodiments, A(S) can be expressed by the following formula (1-4):
[0148] A(S)=AC(S)+AD(S) (1-4);
[0149] Wherein, AC(S) represents the first fitness function, and AD(S) represents the second fitness function.
[0150] For example, the value of the first fitness function is 0.6, and the value of the second fitness function is 0.458. At this time, according to the above formula (1-4), A(S) is 1.058.
[0151] Methods for determining the first fitness function may include, but are not limited to, the number of satisfied assertion statements, a function with the number of satisfied assertion statements as an independent variable, the ratio of the number of satisfied assertion statements to the total number of assertion statements, or the weighted ratio of the number of satisfied assertion statements to the total number of assertion statements. During implementation, those skilled in the art may select a method for determining the first fitness function based on actual needs, and this embodiment of the present application does not limit this.
[0152] In some embodiments, AC(S) can be expressed by the following formula (1-5):
[0153]
[0154] Among them, |A| represents the total number of assertion statements, and |{a∈A,a is executed to}| represents the number of test statements that are successfully executed.
[0155] For example, the assertion part includes 5 assertion statements, of which 3 have been satisfied. At this time, according to the above formula (1-5), AC(S) is 0.6.
[0156] Methods for determining the second fitness function may include, but are not limited to, the distance between the expected value and the actual value of any assertion statement, the sum / difference / product / variance / mean square error of the distance between each expected value and the actual value, and the sum / difference / product / variance / mean square error of the distance between each expected value and the actual value after weighting. During implementation, those skilled in the art may select a method for determining the second fitness function based on actual needs, and this embodiment of the present application does not limit this.
[0157] In some embodiments, AD(S) can be expressed by the following formula (1-6):
[0158]
[0159] Where |AE| represents the total number of assertion statements, and d(a.expected,a.actual) represents the distance between the expected value and the actual value of the a-th assertion statement.
[0160] In implementation, the distance can be obtained by any function capable of calculating distance, such as cosine similarity, Euclidean distance, Levenshtein distance, etc. In implementation, those skilled in the art can independently select a function for calculating distance according to implementation requirements, and the present application embodiment does not limit this.
[0161] In some embodiments, d(x, y) can be expressed by the following formula (1-7):
[0162]
[0163] Among them, Lev(x,y) is the edit distance function of the string, and str(x) means recursively serializing a complex object x into a string.
[0164] For example, the assertion part includes two assertion statements, one of which has an expected value of 10 and an actual value of 20, and the other has an expected value of "foo" and an actual value of "fo". In this case, according to the above formula (1-7), AD(S) is That is 0.458.
[0165] Step S23: Based on the fitness of each of the sentence sets in the current sentence group, iteratively process the current sentence group to obtain the next sentence group.
[0166] Here, the iterative processing may include but is not limited to selection processing, cross-exchange processing, mutation processing, etc. Among them, the selection processing includes selecting a partial statement set from the current statement group, and determining the statement set in the next statement group based on the partial statement set. The selection processing method may be to take the statement set whose fitness meets the preset conditions. Among them, the preset conditions may include but are not limited to the highest, set ratio, set value, etc. During implementation, those skilled in the art may independently determine the preset conditions according to actual needs, and the embodiments of this application are not limited. For example, the statement set with the highest fitness of 1% in the current statement group is directly used as the statement set in the next statement group. For another example, the statement set ranked in the top three in fitness in the current statement group is directly used as the statement set in the next statement group. For another example, the statement set ranked in the top two in fitness in the current statement group is used as the parent statement set, and subsequent cross-exchange, mutation, etc. are performed to obtain two statement sets in the next statement group.
[0167] Mutation processing refers to applying mutation methods to statements in a statement set. The mutation method can be determined based on the statement type. Different statement types can correspond to the same or different mutation methods, and each statement type can include at least one mutation method. For example, for a statement containing variables, mutation methods can include, but are not limited to, deleting the variable, replacing the variable's value, and creating a new variable.
[0168] Step S24: Determine a target statement set based on the assertion portion of the first test case and the next statement group.
[0169] Step S25: Perform the unit test on the first test case based on the simulation object.
[0170] Here, the above steps S24 and S25 correspond to the above steps S13 and S14 respectively. When implementing, the specific implementation of the above steps S13 and S14 can be referred to.
[0171] In an embodiment of the present application, a current statement group is determined, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; fitness evaluation processing is performed on each of the statement sets in the current statement group to obtain the fitness of each of the statement sets in the current statement group; based on the fitness of each of the statement sets in the current statement group, the current statement group is iteratively processed to obtain the next statement group; based on the assertion part of the first test case and the next statement group, a target statement set is determined, wherein the target statement set is used to define the simulation object; and the unit test is performed on the first test case based on the simulation object. In this way, by iteratively processing the group based on the fitness of each statement set, the accuracy of individuals in the offspring can be improved, thereby not only reducing computational overhead but also improving search efficiency.
[0172] In some embodiments, step S22 includes steps S221 to S222, wherein:
[0173] Step S221: For each statement set in the current statement group, generate a second test case corresponding to the statement set based on the statement set.
[0174] Here, the second test case includes at least one part. The at least one part may include, but is not limited to, S, E, A, etc. For example, E and A in the first test case are used as E and A of the second test case, respectively, and the statement set is used as S of the second test case.
[0175] Step S222: For each second test case, based on the fitness function corresponding to each part of the second test case, perform the fitness evaluation process on the corresponding part to obtain the fitness value of the corresponding part, and based on the fitness value of each part of the second test case, obtain the fitness of the statement set corresponding to the second test case.
[0176] Here, different parts correspond to different fitness functions. Each part may correspond to at least one fitness function.
[0177] The method of determining the fitness of a statement set may include, but is not limited to, any fitness value, the sum / difference / variance / mean square error of each fitness value, the sum / difference / variance / mean square error of each fitness value after weighting, etc. During implementation, those skilled in the art can independently choose the method of determining the fitness of a statement set according to actual needs, and the embodiments of the present application are not limited thereto. For example, the maximum value of each fitness value is used as the fitness of the statement set. For another example, the sum of each fitness value after weighting is used as the fitness of the statement set.
[0178] In the implementation manner of the present application, the fitness of the statement set is determined based on the fitness value corresponding to each part, which can improve the accuracy of the fitness of the statement set, thereby improving the accuracy of individuals in the offspring.
[0179] In some embodiments, the step S222 of “performing the fitness evaluation process on each part of the second test case based on the fitness function corresponding to the corresponding part” includes steps S241 to S243, wherein:
[0180] Step S241, when the at least one part includes the pile code part, based on the number of the statement subset that has been successfully executed in the statement set in the pile code part, create a fitness function corresponding to the pile code part; Based on the fitness function corresponding to the pile code part, the pile code part is carried out the fitness evaluation process to obtain the fitness value of the pile code part.
[0181] Here, the way to determine the fitness function may include but is not limited to the number of statement subsets that have been successfully executed, a function with the number of statement subsets that have been successfully executed as an independent variable, the ratio between the number of statement subsets that have been successfully executed and the total number of statement subsets, the ratio after weighting the number of statement subsets that have been successfully executed and the total number of statement subsets, etc. During implementation, those skilled in the art can choose to determine the way to the fitness function according to actual needs, and the embodiments of the present application are not limited thereto. For example, the fitness function corresponding to the S part is represented by the above formula (1-1).
[0182] Step S242: When the at least one part includes the test part, create a fitness function corresponding to the test part based on the number of test statements that have been successfully executed in the test part; based on the fitness function corresponding to the test part, perform the fitness evaluation process on the test part to obtain the fitness value of the test part.
[0183] Here, the method of determining the fitness function may include but is not limited to the number of test statements that have been successfully executed, a function with the number of test statements that have been successfully executed as an independent variable, the ratio between the number of test statements that have been successfully executed and the total number of test statements, the ratio after weighting the number of test statements that have been successfully executed and the total number of test statements, etc. During implementation, those skilled in the art can choose the method of determining the fitness function according to actual needs, and the embodiment of the present application is not limited. For example, the fitness function corresponding to the E part is represented by the above formula (1-3).
[0184] Step S243: In the case where the at least one part includes the assertion part, based on the number of assertion statements that have been satisfied in the assertion part, create a first fitness function corresponding to the assertion part; based on the expected value and actual value of each assertion statement in the assertion part, create a second fitness function corresponding to the assertion part; based on the first fitness function and the second fitness function, perform the fitness evaluation process on the test part to obtain the fitness value of the assertion part.
[0185] Here, the way to determine the fitness value of the assertion part may include but is not limited to the value of the first fitness function, the value of the second fitness function, the sum / difference / product / ratio / square / variance / mean square error between the value of the first fitness function and the value of the second fitness function, the sum / difference / product / ratio / square / variance / mean square error after weighting the value of the first fitness function and the value of the second fitness function, etc. During implementation, those skilled in the art can independently choose the way to determine the fitness value of the assertion part according to actual needs, and the embodiment of the present application is not limited. For example, the fitness value of the assertion part is determined by the above formula (1-4).
[0186] Methods for determining the first fitness function may include, but are not limited to, the number of assertion statements that have been satisfied, a function with the number of assertion statements that have been satisfied as an independent variable, the ratio between the number of assertion statements that have been satisfied and the total number of assertion statements, the ratio after weighting the number of assertion statements that have been satisfied and the total number of assertion statements, etc. During implementation, those skilled in the art may choose a method for determining the first fitness function according to actual needs, and the embodiments of the present application are not limited thereto. For example, the first fitness function is represented by the above formula (1-5).
[0187] In some embodiments, the step S243 of “creating a second fitness function corresponding to the assertion part based on the expected value and the actual value of each assertion statement in the assertion part” includes steps S2431 to S2432, wherein:
[0188] Step S2431: For each assertion statement in the assertion part, use a preset distance function to determine a first distance between an expected value and an actual value of the assertion statement.
[0189] Here, the first distance can be obtained by any function that can calculate the distance. For example, cosine similarity, Euclidean distance, Levenshtein distance, etc. During implementation, those skilled in the art can independently select a function for calculating the distance according to implementation requirements, and the present application embodiment does not limit it. For example, the first distance is calculated by the above formula (1-7).
[0190] Step S2432: Based on each first distance, create the second fitness function corresponding to the assertion part.
[0191] Here, the method for determining the second fitness function may include but is not limited to any first distance, the sum / difference / product / variance / mean square error of each first distance, the sum / difference / product / variance / mean square error after weighting each first distance, etc. During implementation, those skilled in the art can choose the method for determining the second fitness function according to actual needs, and the embodiment of the present application is not limited thereto. For example, the second fitness function is represented by the above formula (1-6).
[0192] In the implementation manner of the present application, the fitness value of the corresponding part is determined based on the fitness value corresponding to each part, which can improve the accuracy of the fitness value of each part, thereby improving the accuracy of the fitness of the statement set, and further improving the accuracy of individuals in the offspring.
[0193] In some implementations, the next statement group includes M third statement sets and N fourth statement sets, where M and N are positive integers; and step S23 includes steps S231 to S232, wherein:
[0194] Step S231: M statement sets in the current statement group whose fitness of each statement set meets a preset condition are respectively used as one of the third statement sets in the next statement group.
[0195] Here, the preset conditions may include, but are not limited to, a maximum, a set ratio, a set value, etc. During implementation, those skilled in the art may independently determine the preset conditions based on actual needs, and the present application embodiment does not limit them. For example, the set of statements with the highest fitness of 1% in the current statement group is used as each third statement set.
[0196] Step S232: perform N / 2 iterative processing on the current sentence group. During each iterative processing, obtain two fourth sentence sets in the next sentence group based on the current sentence group.
[0197] Here, the iterative process may include but is not limited to a selection process, a crossover process, a mutation process, and the like.
[0198] In some implementations, the step of "obtaining two fourth sets of sentences in the next sentence group based on the current sentence group" in step S232 includes steps S251 to S254, wherein:
[0199] Step S251: Determine the first statement set and the second statement set from at least one statement set in the current statement group using a preset selection algorithm.
[0200] Here, the selection algorithm can be any suitable algorithm capable of performing selection, such as a tournament selection method, a random selection method, etc. During implementation, those skilled in the art can independently determine the selection algorithm based on actual needs, and the present embodiment does not limit this.
[0201] The first statement set and the second statement set may be the same or different. For example, L statement sets are randomly selected from the current statement population, and a competition selection method is used to determine the first statement set from these L statement sets. The second statement set is determined in the same manner, where L may be a positive integer not less than 2. During implementation, a sampling strategy with replacement sampling may be used, so that the first statement set and the second statement set may be the same.
[0202] Step S252: Perform the cross-exchange process on the first statement subset in the first statement set and the second statement subset in the second statement set to obtain a fifth statement set and a sixth statement set.
[0203] Here, the first subset of sentences can be determined from the first set of sentences based on preset rules. The preset rules may include, but are not limited to, default, random, custom, user preferences, usage frequency, user operation information, etc. During implementation, those skilled in the art can independently set the preset rules based on actual needs, and the embodiments of this application are not limited thereto.
[0204] In some implementations, the second subset of sentences is determined from the second set of sentences in the same manner as the first subset of sentences is determined from the first set of sentences.
[0205] For example, the first statement set includes statement subset 1 and statement subset 2, and the second statement set includes statement subset 3 and statement subset 4, where the first statement subset is statement subset 1 and the second statement subset is statement subset 4. After cross-interchange processing, the fifth statement set includes statement subset 4 and statement subset 2, and the sixth statement set includes statement subset 3 and statement subset 1.
[0206] Step S253: mutate the fifth statement set to obtain a mutated fifth statement set, and use the mutated fifth statement set as the fourth statement set.
[0207] Here, mutation processing refers to applying mutation methods to statements in a statement set. The mutation method can be determined based on the statement type. Different statement types can correspond to the same or different mutation methods, and each statement type can include at least one mutation method. For example, for a statement containing variables, mutation methods can include, but are not limited to, deleting the variable, replacing the variable's value, and creating a new variable.
[0208] Step S254: mutate the sixth statement set to obtain a mutated sixth statement set, and use the mutated sixth statement set as another fourth statement set.
[0209] Here, the process of mutating the sixth statement set is similar to the process of mutating the fifth statement set. When implementing, reference may be made to the specific implementation of the aforementioned step S254.
[0210] In an embodiment of the present application, M sets of statements in the current statement group whose fitness satisfies a preset condition are each selected as one of the third statement sets in the next statement group; the current statement group is iterated N / 2 times, and during each iteration, two fourth statement sets in the next statement group are obtained based on the current statement group. Thus, on the one hand, directly using statement sets that meet the preset conditions as offspring can reduce the possibility of losing the optimal individual; on the other hand, iteratively processing the current statement group to obtain offspring can improve the accuracy of the individuals in the offspring, thereby not only reducing computational overhead but also improving search efficiency.
[0211] In some implementations, the step of “mutating the fifth statement set to obtain a mutated fifth statement set” in step S253 includes steps S261 to S264, wherein:
[0212] Step S261: Determine a target statement from at least one statement in the fifth statement set.
[0213] Here, the number of target sentences can be at least one. Methods for determining the target sentences may include, but are not limited to, default, random, custom, user preferences, usage frequency, user operation information, etc. During implementation, those skilled in the art can independently set the method for determining the target sentences based on actual needs, and the embodiments of this application are not limited thereto. For example, a sentence can be randomly selected from at least one sentence as the target sentence.
[0214] Step S262: Determine a target variation mode from at least one variation mode based on the type of the target sentence.
[0215] Here, each type of statement may include at least one variation mode. Methods for determining the target variation mode may include, but are not limited to, default, random, custom, user preference, usage frequency, user operation information, and the like. During implementation, those skilled in the art may independently determine the target variation mode based on actual needs, and this embodiment of the present application does not limit this. For example, a variation mode may be randomly selected from at least one variation mode as the target variation mode.
[0216] In some embodiments, step S262 includes at least one of steps S2621 to S2623, wherein:
[0217] Step S2621: When the type of the target statement is to contain variables, the target variation method includes at least one of the following: randomly selecting a value from a preset symbol library as the value of a new variable, randomly selecting a value from the symbol library to replace the value of the variable, and deleting the variable.
[0218] Here, each value in the symbol library is generated based on the first test case and the object under test, wherein the object under test may include but is not limited to the class under test, the function under test, and the like.
[0219] During implementation, the first test case and the object under test are parsed according to a preset parsing method to generate a symbol library. The parsing method may include, but is not limited to, preset types, custom types, default types, user preferences, etc. During implementation, those skilled in the art may independently select a parsing method based on actual needs, and this embodiment of the application does not limit this.
[0220] For example, for the following Stub Code,
[0221] var sha1=DigestUtils.sha1Hex("bar");
[0222] when(user.getPasswordHash()).thenReturn(sha1);
[0223] when(dao.findUser(eq("foo"))
[0224] .thenThrow(new TimeoutException());
[0225] .thenReturn(user);
[0226] The word used to construct the return value can be extracted as a value of the symbol library. In this case, the four words "DigestUtils.sha1Hex", "bar", "foo", and "TimeoutException" can be used as part of the symbol library.
[0227] Because existing search solutions all start from scratch, complex values require numerous search iterations. Pre-building a symbol library can provide guidance for subsequent searches, improving search efficiency and facilitating faster search for the correct value, thereby reducing the computational effort involved.
[0228] The mutation methods for variables can include adding, deleting, modifying, etc. For example, randomly selecting a value baz from the symbol library and setting the value baz as the value of the new variable v4. Another example is deleting an unused variable.
[0229] Step S2622: When the target statement type contains parameters, the target variation method includes: randomly selecting a parameter from the fifth statement set to replace the parameter in the target statement.
[0230] For example, change the parameter v2 in the target statement v3←DigestUtils.sha1Hex(v2) to v4.
[0231] Step S2623: When the target statement type includes a behavior statement, the target variation method includes at least one of the following: adding a new behavior statement, deleting the behavior statement, and exchanging the execution order of the behavior statement and another behavior statement in the fifth statement set.
[0232] For example, randomly generate a behavior statement Add the action statement to the fifth statement set.
[0233] For another example, randomly delete an action statement in the fifth statement set.
[0234] It should be understood that the above-mentioned variations of each type of statement are only for example, and in implementation, variations of each type of statement may be added or deleted.
[0235] Step S263: mutate the target sentence using the target mutation method to obtain a mutated target sentence.
[0236] For example, the target mutation method is to swap the execution order of the action statement and another action statement in the fifth statement set. For example, swap the order of the following two statements:
[0237] <dao,finduser,[Eq(v0)]>→Throw(v1)
[0238] <dao,finduser,[Eq(v0)]> →Return(user)
[0239] For example, the target mutation method is to randomly select a value from the symbol library to replace the value of the variable. For example, "fooo" is randomly selected from the symbol library as the value of variable v0, that is, v0←"foo" is replaced with v0←"fooo".
[0240] Step S264: Replace the target statement in the fifth statement set with the mutated target statement to obtain the mutated fifth statement set.
[0241] In the implementation manner of the present application, by adopting corresponding target mutation methods for different types of statements to obtain corresponding statement sets, on the one hand, statement sets for various application scenarios can be generated, thereby improving the applicability of the simulation object; on the other hand, by only adopting highly abstract mutation methods for target statements, the search space for mutation processing can be reduced, thereby reducing the computational complexity of the search.
[0242] Figure 3A A schematic diagram of the structure of a unit test system provided in an embodiment of the present application is shown in FIG. Figure 3A As shown, the system includes an input component 31, a processing component 32 and an output component 33, wherein:
[0243] The input component 31 is used to receive a first test case;
[0244] The processing component 32 is configured to determine, based on a first test case, a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; iteratively process the current statement group to obtain a next statement group; determine a target statement set based on an assertion portion of the first test case and the next statement group; and perform the unit test on the first test case based on the simulation object;
[0245] The output component 33 is used to output the first test case for performing the unit test.
[0246] Here, the iterative process may include but is not limited to a selection process, a crossover process, a mutation process, and the like.
[0247] In some embodiments, the input component 31 is further configured to receive a measured object.
[0248] Here, the object under test may include but is not limited to the class under test, the function under test, etc.
[0249] The processing component 32 is further configured to parse the first test case and the object under test respectively according to a preset parsing method to generate a symbol library.
[0250] Here, the parsing method may include, but is not limited to, preset types, custom types, default types, user preferences, etc. During implementation, those skilled in the art may independently select the parsing method based on actual needs, and the embodiments of this application are not limited thereto. In this way, by pre-building a symbol library, a guide can be provided for subsequent searches, so that the correct value can be searched more quickly, thereby reducing the computational complexity of the search.
[0251] Figure 3B A schematic diagram of the implementation flow of a unit testing method provided in an embodiment of the present application is shown as follows: Figure 3B As shown, the method includes steps S311 to S317, wherein:
[0252] Step S311: parse the input test case to be repaired and divide it into four parts: M, S, E, and A;
[0253] Here, the test cases to be repaired can be segmented according to the above segmentation method.
[0254] Step S312: Parse the input tested class and the test case to be repaired, and build a symbol library;
[0255] Step S313: parse the S part of the test case to be repaired and construct the initial group P0;
[0256] Here, P0 includes at least two identical statement sets. In implementation, the S part can be represented according to the target abstract syntax to obtain a statement set, which is used as a statement set in P0.
[0257] Step S314: n Based on this, the next generation of population P is generated. n+1 ;
[0258] Here, the steps of generating the next generation population include a fitness evaluation process, a selection process, a crossover process, and a mutation process.
[0259] Step S315: Determine P n+1 Is there a target statement set in part A that matches the test case to be repaired? If yes, go to step S317; otherwise, go to step S316;
[0260] Step S316: P n+1 As Pn , return to step S314;
[0261] Step S317: Repair the test case to be repaired using the target statement set, and perform unit testing on the repaired test case.
[0262] Here, the target statement set is used to redefine the mock objects in the test case to be repaired.
[0263] In some embodiments, the processing component 32 is also used to: perform fitness evaluation processing on each of the statement sets in the current statement group to obtain the fitness of each of the statement sets in the current statement group; use the M statement sets whose fitness of each of the statement sets in the current statement group meets preset conditions as one of the third statement sets in the next statement group; perform N / 2 iterative processing on the current statement group, and in each iterative processing, use a preset selection algorithm to determine the first statement set and the second statement set from at least one statement set in the current statement group, perform the cross-exchange processing on the first statement subset in the first statement set and the second statement subset in the second statement set to obtain a fifth statement set and a sixth statement set, perform mutation processing on the fifth statement set to obtain a mutated fifth statement set, and use the mutated fifth statement set as a fourth statement set, perform mutation processing on the sixth statement set to obtain a mutated sixth statement set, and use the mutated sixth statement set as another fourth statement set.
[0264] In some embodiments, the processing component 32 is further used to: determine a target statement from at least one statement in the fifth statement set; when the type of the target statement is to contain variables, the target mutation method includes at least one of the following: randomly selecting a value from a preset symbol library as the value of a new variable, randomly selecting a value from the symbol library to replace the value of the variable, and deleting the variable, wherein each value in the symbol library is generated based on the first test case and the object under test; when the type of the target statement is to contain parameters, the target mutation method includes: randomly selecting a parameter from the fifth statement set to replace the parameter in the target statement; when the type of the target statement is to contain behavior statements, the target mutation method includes at least one of the following: adding a new behavior statement, deleting the behavior statement, and swapping the execution order of the behavior statement with another behavior statement in the fifth statement set; mutating the target statement using the target mutation method to obtain a mutated target statement; replacing the target statement in the fifth statement set with the mutated target statement to obtain the mutated fifth statement set.
[0265] In some embodiments, the processing component 32 is also used to: for each statement set in the current statement group, generate a second test case corresponding to the statement set based on the statement set, and the second test case includes at least one part; for each second test case, based on the fitness function corresponding to each part of the second test case, perform the fitness evaluation processing on the corresponding part to obtain the fitness value of the corresponding part, and based on the fitness value of each part of the second test case, obtain the fitness of the statement set corresponding to the second test case.
[0266] In some embodiments, the processing component 32 is further used for: in the case where the at least one part includes the pile code part, based on the number of the statement subset that has been successfully executed in the statement set in the pile code part, creating a fitness function corresponding to the pile code part; based on the fitness function corresponding to the pile code part, performing the fitness evaluation process on the pile code part to obtain the fitness value of the pile code part; in the case where the at least one part includes the test part, based on the number of the test statements that have been successfully executed in the test part, creating a fitness function corresponding to the test part; based on the fitness function corresponding to the test part, performing the fitness evaluation process on the pile code part to obtain the fitness value of the pile code part; The test part is subjected to the fitness evaluation process to obtain the fitness value of the test part; when the at least one part includes the assertion part, a first fitness function corresponding to the assertion part is created based on the number of assertion statements that have been satisfied in the assertion part; for each assertion statement in the assertion part, a first distance between the expected value and the actual value of the assertion statement is determined using a preset distance function; based on each first distance, a second fitness function corresponding to the assertion part is created; based on the first fitness function and the second fitness function, the test part is subjected to the fitness evaluation process to obtain the fitness value of the assertion part.
[0267] Figure 3C A schematic diagram of a process for generating the next sentence group provided in an embodiment of the present application is shown as follows: Figure 3C As shown, the method includes steps S321 to S327, wherein:
[0268] Step S321: Determine P n The fitness of each sentence set in ;
[0269] Step S322: The set of 1% of sentences with the highest fitness is taken as P n+1 The set of statements in ;
[0270] Step S323: Use tournament selection method to select nSelect two sets of statements from the set as the parent (corresponding to the first set of statements) and the parent (corresponding to the second set of statements);
[0271] Step S324: Cross-exchange the statement subsets in the parent generation and the parent generation to generate two new child generations (corresponding to the fifth statement set and the sixth statement set);
[0272] Step S325: Perform mutation processing on the two new offspring to obtain two mutated offspring (corresponding to the two fourth statement sets mentioned above), and add the obtained two offspring to P n+1 ;
[0273] Step S326: Determine whether the number of iterations reaches the preset value. If so, proceed to step S327; otherwise, proceed to step S323.
[0274] Here, the default value is Where X represents P n The number of statement sets in P n The number of sentences in the set with the highest 1% fitness.
[0275] Step S327: End the current process.
[0276] In an embodiment of the present application, first, multiple statement sets are used to define the behavior of simulation objects in different scenarios, which can improve the adaptability of simulation objects; second, by defining the behavior statements and dependent statements of simulation objects in a statement subset, the corresponding behavior statements and dependent statements can be exchanged together during the iterative processing, thereby reducing the possibility of producing incorrect individuals, thereby not only reducing computational overhead but also improving search efficiency; then, based on the assertion part and the next statement group, the target statement set of the simulation object is obtained, which can improve the accuracy and applicability of the simulation object; finally, the simulation object is used for unit testing without relying on the real objects in the program module, thereby realizing the separation of program modules and dependent objects, which helps to improve software testing efficiency.
[0277] Based on the foregoing embodiments, an embodiment of the present application provides a unit testing device, which includes the units included and the modules included in each unit, and can be implemented by a processor in a computer device; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0278] Figure 4 A schematic diagram of the structure of a unit test device provided in an embodiment of the present application is shown in FIG. Figure 4As shown, the apparatus 40 includes a first determination module 41, an iteration module 42, a second determination module 43 and a testing module 44, wherein:
[0279] The first determining module 41 is configured to determine a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement;
[0280] The iteration module 42 is configured to iteratively process the current statement group to obtain a next statement group; wherein the iterative processing includes cross-exchanging a first statement subset determined from at least one statement subset in the first statement set and a second statement subset determined from at least one statement subset in the second statement set, the first statement set and the second statement set being determined from the at least two statement sets, respectively, and the number of statement sets in the next statement group is the same as the number of statement sets in the current statement group;
[0281] The second determining module 43 is configured to determine a target statement set based on the assertion portion of the first test case and the next statement group, wherein the target statement set is used to define the simulation object;
[0282] The testing module 44 is configured to perform the unit test on the first test case based on the simulation object.
[0283] In some embodiments, the iteration module 42 is further used to: perform fitness evaluation processing on each of the statement sets in the current statement group to obtain the fitness of each of the statement sets in the current statement group; and perform the iterative processing on the current statement group based on the fitness of each of the statement sets in the current statement group to obtain the next statement group.
[0284] In some embodiments, the next statement group includes M third statement sets and N fourth statement sets, where M and N are positive integers; the iteration module 42 is also used to: use the M statement sets in the current statement group whose fitness meets preset conditions as one of the third statement sets in the next statement group; perform N / 2 iterative processing on the current statement group, and in each iterative processing, obtain two of the fourth statement sets in the next statement group based on the current statement group.
[0285] In some embodiments, the iteration module 42 is further used to: determine the first statement set and the second statement set from at least one statement set in the current statement group using a preset selection algorithm; perform the cross-exchange processing on the first statement subset in the first statement set and the second statement subset in the second statement set to obtain a fifth statement set and a sixth statement set; perform mutation processing on the fifth statement set to obtain a mutated fifth statement set, and use the mutated fifth statement set as the fourth statement set; perform mutation processing on the sixth statement set to obtain a mutated sixth statement set, and use the mutated sixth statement set as another fourth statement set.
[0286] In some embodiments, the iteration module 42 is further used to: determine a target statement from at least one statement in the fifth statement set; determine a target variation mode from at least one variation mode based on the type of the target statement; mutate the target statement using the target variation mode to obtain a mutated target statement; and replace the target statement in the fifth statement set with the mutated target statement to obtain the mutated fifth statement set.
[0287] In some embodiments, the iteration module 42 is also used for at least one of the following: when the type of the target statement is to contain variables, the target variation method includes at least one of the following: randomly selecting a value from a preset symbol library as the value of a new variable, randomly selecting a value from the symbol library to replace the value of the variable, and deleting the variable; wherein each value in the symbol library is generated based on the first test case and the object under test; when the type of the target statement is to contain parameters, the target variation method includes: randomly selecting a parameter from the fifth statement set to replace the parameter in the target statement; when the type of the target statement is to contain behavior statements, the target variation method includes at least one of the following: adding a new behavior statement, deleting the behavior statement, and swapping the execution order of the behavior statement with another behavior statement in the fifth statement set.
[0288] In some embodiments, the iteration module 42 is further used to: for each statement set in the current statement group, generate a second test case corresponding to the statement set based on the statement set, wherein the second test case includes at least one part; for each second test case, based on the fitness function corresponding to each part of the second test case, perform the fitness evaluation processing on the corresponding part to obtain the fitness value of the corresponding part, and based on the fitness value of each part of the second test case, obtain the fitness of the statement set corresponding to the second test case.
[0289] In some embodiments, at least one part in the second test case includes at least one of the following: a pile code part, a test part, and an assertion part; the iteration module 42 is further used for at least one of the following: when the at least one part includes the pile code part, based on the number of statement subsets that have been successfully executed in the statement set in the pile code part, creating a fitness function corresponding to the pile code part; based on the fitness function corresponding to the pile code part, performing the fitness evaluation process on the pile code part to obtain the fitness value of the pile code part; when the at least one part includes the test part, based on the number of test subsets that have been successfully executed in the test part Based on the number of test statements, a fitness function corresponding to the test part is created; based on the fitness function corresponding to the test part, the test part is subjected to the fitness evaluation process to obtain the fitness value of the test part; in the case where the at least one part includes the assertion part, a first fitness function corresponding to the assertion part is created based on the number of assertion statements that have been satisfied in the assertion part; based on the expected value and actual value of each assertion statement in the assertion part, a second fitness function corresponding to the assertion part is created; based on the first fitness function and the second fitness function, the test part is subjected to the fitness evaluation process to obtain the fitness value of the assertion part.
[0290] In some embodiments, the iteration module 42 is further used to: determine, for each assertion statement in the assertion part, a first distance between the expected value and the actual value of the assertion statement using a preset distance function; and create the second fitness function corresponding to the assertion part based on each first distance.
[0291] In some embodiments, the second determination module 43 is further used for at least one of the following: when there is a set of statements that conform to the assertion part of the first test case in the next statement group, using the set of statements that conform to the assertion part of the first test case as the target statement set; when there is no set of statements that conform to the assertion part of the first test case in the next statement group, using the next statement group as a new current statement group, performing the iterative processing on the new current statement group to obtain a new next statement group, and determining the target statement set based on the assertion part of the first test case and the new next statement group.
[0292] In some embodiments, the first determination module 41 is further used to: parse the first test case to obtain a stub code portion; use a preset abstract syntax to parse the stub code portion to generate an initial statement group, wherein the initial statement group includes at least two identical statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; and use the initial statement group as the current statement group.
[0293] The description of the above device embodiment is similar to the description of the above method embodiment and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of this application, please refer to the description of the method embodiment of this application for understanding.
[0294] It should be noted that, in the embodiment of the present application, if the above-mentioned spray control method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0295] Correspondingly, an embodiment of the present application provides an electronic device comprising a memory and a processor. The memory is configured to store a computer program executable on the processor. The processor is configured to implement the steps of the method provided in the above embodiment when executing the computer program.
[0296] Correspondingly, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the method provided in the above embodiment are implemented.
[0297] Correspondingly, an embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, implements some or all of the steps in the above method. The computer program product can be implemented specifically by hardware, software, or a combination thereof. In an optional embodiment, the computer program product is embodied as a computer storage medium. In another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0298] It should be noted that Figure 5 This is a hardware entity diagram of an electronic device in an embodiment of the present application, such as Figure 5 As shown, the hardware entity of the electronic device 500 includes: a processor 501, a communication interface 502 and a memory 503, wherein:
[0299] The processor 501 generally controls the overall operations of the electronic device 500 .
[0300] The communication interface 502 enables the electronic device to communicate with other terminals or servers through a network.
[0301] The memory 503 is configured to store instructions and applications executable by the processor 501, and can also cache data to be processed or processed by the processor 501 and various modules in the electronic device 500 (for example, image data, audio data, voice communication data, and video communication data). This can be implemented using flash memory (FLASH) or random access memory (RAM). Data can be transmitted between the processor 501, the communication interface 502, and the memory 503 via a bus 504.
[0302] It should be noted that the descriptions of the above storage medium, computer program product, and device embodiments are similar to the descriptions of the above method embodiments and have similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
[0303] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments.
[0304] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0305] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0306] The units described above as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, the functional units in the various embodiments of the present application may all be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0307] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, and other media that can store program codes.
[0308] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0309] The above is only an implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.
Claims
1. A unit testing method, characterized in that, The method comprises: Determine a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; Iteratively processing the current statement group to obtain a next statement group; wherein the iterative processing includes cross-exchanging a first statement subset determined from at least one statement subset in the first statement set and a second statement subset determined from at least one statement subset in the second statement set, the first statement set and the second statement set being determined from the at least two statement sets, respectively, and the number of statement sets in the next statement group is the same as the number of statement sets in the current statement group; Determining a target statement set based on the assertion portion of the first test case and the next statement group, wherein the target statement set is used to define the simulation object; Performing the unit test on the first test case based on the simulation object specifically includes: A simulation object is defined using the target statement set, the stub code in the first test case is replaced, and the unit test is performed using the first test case after the stub code is replaced.
2. The method according to claim 1, characterized in that The iterative processing of the current sentence group to obtain the next sentence group includes: Performing fitness evaluation processing on each of the sentence sets in the current sentence group to obtain the fitness of each of the sentence sets in the current sentence group; Based on the fitness of each of the sentence sets in the current sentence group, the iterative processing is performed on the current sentence group to obtain the next sentence group.
3. The method according to claim 2, characterized in that The next statement group includes M third statement sets and N fourth statement sets, where M and N are positive integers; The iterative processing of the current sentence group based on the fitness of each sentence set in the current sentence group to obtain the next sentence group includes: M sentence sets in the current sentence group whose fitness of each sentence set meets a preset condition are respectively used as the third sentence set in the next sentence group; The current sentence group is iterated N / 2 times, and in each iterative process, two fourth sentence sets in the next sentence group are obtained based on the current sentence group.
4. The method according to claim 3, characterized in that The obtaining, based on the current sentence group, two fourth sentence sets in the next sentence group includes: Determining the first statement set and the second statement set from at least one statement set in the current statement group using a preset selection algorithm; Performing the cross-exchange process on the first statement subset in the first statement set and the second statement subset in the second statement set to obtain a fifth statement set and a sixth statement set; performing mutation processing on the fifth statement set to obtain a mutated fifth statement set, and using the mutated fifth statement set as the fourth statement set; The sixth statement set is mutated to obtain a mutated sixth statement set, and the mutated sixth statement set is used as another fourth statement set.
5. The method according to claim 4, characterized in that The mutating the fifth statement set to obtain a mutated fifth statement set includes: determining a target sentence from at least one sentence in the fifth sentence set; determining a target variation mode from at least one variation mode based on the type of the target sentence; mutating the target sentence using the target mutation method to obtain a mutated target sentence; The target statement in the fifth statement set is replaced with the mutated target statement to obtain the mutated fifth statement set.
6. The method according to claim 5, characterized in that Determining a target variation mode from at least one variation mode based on the type of the target sentence includes at least one of the following: In the case where the target statement type contains variables, the target mutation method includes at least one of the following: randomly selecting a value from a preset symbol library as the value of a new variable, randomly selecting a value from the symbol library to replace the value of the variable, or deleting the variable; wherein each value in the symbol library is generated based on the first test case and the object under test; In the case where the type of the target sentence is parameter-containing, the target variation method includes: randomly selecting a parameter from the fifth sentence set to replace the parameter in the target sentence; In the case where the target statement type includes a behavior statement, the target variation method includes at least one of the following: adding a new behavior statement, deleting the behavior statement, and exchanging the execution order of the behavior statement and another behavior statement in the fifth statement set.
7. The method according to claim 2, characterized in that The performing the fitness evaluation process on each of the sentence sets in the current sentence group to obtain the fitness of each of the sentence sets in the current sentence group includes: For each statement set in the current statement group, generating a second test case corresponding to the statement set based on the statement set, wherein the second test case includes at least one part; For each second test case, based on the fitness function corresponding to each part of the second test case, the corresponding part is subjected to the fitness evaluation process to obtain the fitness value of the corresponding part, and based on the fitness value of each part of the second test case, the fitness of the statement set corresponding to the second test case is obtained.
8. The method according to claim 7, characterized in that At least one part of the second test case includes at least one of the following: a stub code part, a test part, and an assertion part; The fitness function corresponding to each part of the second test case is used to perform the fitness evaluation process on the corresponding part to obtain the fitness value of the corresponding part, including at least one of the following: In the case where the at least one part includes the pile code part, based on the number of statement subsets that have been successfully executed in the statement set in the pile code part, creating a fitness function corresponding to the pile code part; Based on the fitness function corresponding to the pile code part, the pile code part is subjected to the fitness evaluation process to obtain the fitness value of the pile code part; In a case where the at least one part includes the test part, creating a fitness function corresponding to the test part based on the number of test statements that have been successfully executed in the test part; performing the fitness evaluation process on the test part based on the fitness function corresponding to the test part to obtain a fitness value of the test part; In the case where the at least one part includes the assertion part, a first fitness function corresponding to the assertion part is created based on the number of assertion statements that have been satisfied in the assertion part; a second fitness function corresponding to the assertion part is created based on the expected value and actual value of each assertion statement in the assertion part; and based on the first fitness function and the second fitness function, the fitness evaluation process is performed on the test part to obtain the fitness value of the assertion part.
9. The method according to claim 8, characterized in that The step of creating a second fitness function corresponding to the assertion part based on the expected value and the actual value of each assertion statement in the assertion part includes: For each assertion statement in the assertion part, using a preset distance function, determining a first distance between an expected value and an actual value of the assertion statement; Based on each of the first distances, the second fitness function corresponding to the assertion part is created.
10. The method according to any one of claims 1 to 9, characterized in that The determining of the target statement set based on the assertion portion of the first test case and the next statement group includes at least one of the following: If there is a statement set that meets the assertion part of the first test case in the next statement group, taking the statement set that meets the assertion part of the first test case as the target statement set; In the case that there is no statement set that meets the assertion part of the first test case in the next statement group, the next statement group is used as the new current statement group, and the iterative processing is performed on the new current statement group to obtain a new next statement group. Based on the assertion part of the first test case and the new next statement group, the target statement set is determined.
11. The method according to any one of claims 1 to 9, characterized in that Determining the current sentence group includes: Parsing the first test case to obtain a stub code portion; The stub code portion is parsed using a preset abstract syntax to generate an initial statement group, wherein the initial statement group includes at least two identical statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; The initial sentence group is used as the current sentence group.
12. A unit testing device, characterized in that: The device comprises: A first determining module is configured to determine a current statement group, wherein the current statement group includes at least two statement sets, each of the statement sets includes at least one statement subset, and each of the statement subsets includes a behavior statement for defining a simulation object and at least one dependent statement of the behavior statement; an iterative module, configured to iteratively process the current statement group to obtain a next statement group; wherein the iterative processing includes cross-exchanging a first statement subset determined from at least one statement subset in the first statement set and a second statement subset determined from at least one statement subset in the second statement set, the first statement set and the second statement set being determined from the at least two statement sets, respectively, and the number of statement sets in the next statement group being the same as the number of statement sets in the current statement group; A second determining module is configured to determine a target statement set based on the assertion portion of the first test case and the next statement group, wherein the target statement set is used to define the simulation object; A testing module, configured to perform the unit test on the first test case based on the simulation object, specifically comprising: A simulation object is defined using the target statement set, the stub code in the first test case is replaced, and the unit test is performed using the first test case after the stub code is replaced.
13. An electronic device comprising a processor and a memory, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 11 is implemented.
14. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is executed by a processor, the method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
User behavior simulation unit, test system and test method
CN106021004A
Method and device for determining virtual test dependent object
CN112579440A