Automatic testing method and device, electronic equipment and medium
By combining operation code sequence expansion and parameter assignment strategies, the problem of irregular parameter definitions when automatically generating test codes is solved, efficient automated testing is achieved, and the breadth and efficiency of tests are improved.
Patent Information
- Application Number
- CN202411067874.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-12-20
AI Technical Summary
The prior art cannot format and define input parameters when automatically generating test codes, especially the value of parameters cannot be generated based on real-time information during the test process or the values of different parameters are combined.
By combining the operations in the object to be tested, forming an operation code sequence, generating an operation constraint model, and using greedy algorithm to expand the operation code sequence, obtaining parameter value model and parameter constraint model, combining a two-stage parameter coverage generation strategy, The parameters in the test code sequence are assigned and tested, and a full parameter coverage table and test results are generated.
It realizes the mutual influence of systematic coverage of test operations, enriches the diversity of parameter values, improves the breadth and efficiency of tests, lowers the technical threshold, and provides a low-code automatic testing method.
Smart Images

Figure CN119166493A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an automated testing method, device, electronic equipment and medium. Background Art
[0002] Software testing refers to the process of operating a program under regular conditions to discover program errors, measure program quality, and evaluate whether it meets design requirements. Automated testing is a process that converts human-driven test behavior into machine execution, allowing the machine to understand user needs, simulate manual test steps to complete the writing of test scripts, and automatically test the software. However, in the process of automatically generating test code, it is currently impossible to format the definition of input parameters, such as the value of parameters that need to be generated based on real-time information during the test process, or the combination of different parameter values obtained based on constraints between parameters. Summary of the invention
[0003] In order to solve the above technical problems or at least partially solve the above technical problems, an embodiment of the present invention provides an automated testing method, device, electronic device and medium.
[0004] In a first aspect, an embodiment of the present invention provides an automated testing method, comprising:
[0005] Combining operations in the object to be tested in pairs to form operation code sequences, and obtaining an operation code sequence set;
[0006] Generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet;
[0007] According to the operation constraint model and the greedy algorithm, the operation code sequence in the operation code sequence set is expanded to generate a test code sequence;
[0008] Obtaining a parameter value model and a parameter constraint model; the parameter value model defines the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet;
[0009] According to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, the parameters of each operation in the test code sequence are assigned and tested to obtain a full parameter coverage table and test results.
[0010] Optionally, the expanding the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm includes:
[0011] constructing an operation dependency model according to the operation constraint model;
[0012] According to the operation dependency model, the operation code sequences in the operation code sequence set are screened to remove the operation code sequences that do not conform to the operation dependency model;
[0013] According to the operation constraint model and the greedy algorithm, the filtered operation code sequence is expanded.
[0014] Optionally, the operation code sequence includes a first operation and a second operation;
[0015] The step of expanding the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm includes:
[0016] Selecting an operation code sequence from the operation code sequence set as a sequence to be expanded;
[0017] The sequence to be expanded is expanded according to the following process:
[0018] Counting the number of all first operations in the operation code sequence set, taking the first operation with the largest number of times as the first operation, adding the first operation to the sequence to be expanded, and adding the first operation to a preset set;
[0019] Taking all operation code sequences whose first operation in the operation code sequence set is the first operation as candidate operation code sequences, counting the number of all second-order operations in the candidate operation code sequence set, taking the second-order operation with the largest number of operations as the second operation, and adding the second operation to the sequence to be expanded;
[0020] Deleting all operation code sequences in the operation code sequence set whose first operation is an element in the preset set and whose second operation is the second operation;
[0021] Adding the second operation to the preset set;
[0022] According to the operation constraint model, determining whether the sequence to be expanded is expanded;
[0023] When the expansion of the sequence to be expanded is completed, a new sequence to be expanded is determined, and the new sequence to be expanded is expanded.
[0024] Optionally, judging whether the sequence to be expanded is expanded according to the operation constraint model includes:
[0025] Determining, according to the operation constraint model, an operation that is compatible with the end operation of the sequence to be extended;
[0026] Determining whether operations compatible with the end operation have been traversed in the process of extending the sequence to be extended;
[0027] When all operations compatible with the last operation are traversed during the expansion of the sequence to be expanded, it is determined that the expansion of the sequence to be expanded is completed.
[0028] Optionally, obtain a parameter constraint model, including:
[0029] Obtaining description information of input parameters of the object to be tested;
[0030] Generate a parameter dependency relationship according to the description information of the input parameters;
[0031] A parameter constraint model is generated according to the parameter dependency relationship.
[0032] Optionally, assigning values to parameters of each operation in the test code sequence and testing them according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy to obtain a full parameter coverage table and test results includes:
[0033] Determining a combination constraint according to the parameter value model and the parameter constraint model;
[0034] Determine the mandatory parameters and constraint parameters in the test code sequence, wherein the constraint parameters refer to the parameters indicated by the parameter constraint model;
[0035] Determining, according to the combined constraint, optional values of the mandatory parameter and optional values of the constraint parameter;
[0036] Generate a first-stage parameter coverage table according to the optional values of the required parameters and the optional values of the constraint parameters;
[0037] Based on the first-stage parameter coverage table, a plurality of first test cases are obtained, and the object to be tested is tested based on the plurality of first test cases;
[0038] Generate a second-stage parameter coverage table according to the first test case that has been successfully tested and the optional values of the remaining parameters in the test code sequence, wherein the remaining parameters refer to the parameters in the test code sequence other than the required parameters and the constraint parameters, and the second-stage parameter coverage table is a full parameter coverage table;
[0039] Based on the full parameter coverage table, a plurality of second test cases are obtained, and based on the plurality of second test cases, the object to be tested is tested to obtain a test result.
[0040] Optionally, the parameter value model includes a first assignment strategy, a second assignment strategy, a third assignment strategy and a fourth assignment strategy;
[0041] The first assignment strategy indicates that the parameter value of the operation that is most similar to the operation to be assigned among the executed operations is used as the parameter value of the operation to be assigned;
[0042] The second assignment strategy indicates that the values of the parameters with the same names as the parameters of the operation to be assigned in all test cases are used as the parameter values of the operation to be assigned;
[0043] The third assignment strategy indicates that, when the operation to be assigned has been requested to be executed, the parameter value successfully requested in the request execution history is used as the parameter value of the operation to be assigned;
[0044] The fourth assignment strategy indicates randomly generating the parameter value of the operation to be assigned.
[0045] Optionally, the priorities of the first assignment strategy, the second assignment strategy, the third assignment strategy and the fourth assignment strategy decrease in sequence.
[0046] In a second aspect, an embodiment of the present invention provides an automated testing device, comprising:
[0047] A combination module, used for combining operations in the object to be tested in pairs to form an operation code sequence, and obtaining an operation code sequence set;
[0048] An operation constraint generation module, used to generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet;
[0049] A test code generation module, used to expand the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm to generate a test code sequence;
[0050] An acquisition module, used to acquire a parameter value model and a parameter constraint model; the parameter value model defines the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet;
[0051] The automatic testing module is used to assign and test the parameters of each operation in the test code sequence according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, and obtain a full parameter coverage table and test results.
[0052] Optionally, the test code generation module is used to: construct an operation dependency model based on the operation constraint model; filter the operation code sequences in the operation code sequence set based on the operation dependency model to remove operation code sequences that do not conform to the operation dependency model; and expand the filtered operation code sequences based on the operation constraint model and a greedy algorithm.
[0053] Optionally, the operation code sequence includes a first operation and a second operation;
[0054] The test code generation module is used to: select an operation code sequence from the operation code sequence set as a sequence to be expanded; expand the sequence to be expanded according to the following process: count the number of all first operations in the operation code sequence set, take the first operation with the largest number of times as the first operation, add the first operation to the sequence to be expanded, and add the first operation to a preset set; take all operation code sequences in the operation code sequence set whose first operation is the first operation as candidate operation code sequences, count the number of all second operations in the candidate operation code sequence set, take the second operation with the largest number of times as the second operation, and add the second operation to the sequence to be expanded; delete all operation code sequences in the operation code sequence set whose first operation is an element in the preset set and whose second operation is the second operation; add the second operation to the preset set; judge whether the sequence to be expanded is expanded according to the operation constraint model; if the expansion of the sequence to be expanded is completed, determine a new sequence to be expanded, and expand the new sequence to be expanded.
[0055] Optionally, the test code generation module is used to: determine, based on the operation constraint model, an operation that is compatible with the end operation of the sequence to be expanded; determine whether the operations compatible with the end operation have been traversed during the process of expanding the sequence to be expanded; and determine that the expansion of the sequence to be expanded is completed if the operations compatible with the end operation have been traversed during the process of expanding the sequence to be expanded.
[0056] Optionally, the acquisition module is used to: acquire description information of input parameters of the object to be tested; generate parameter dependency relationships according to the description information of the input parameters; and generate a parameter constraint model according to the parameter dependency relationships.
[0057] Optionally, the automated testing module is used to: determine the combined constraints according to the parameter value model and the parameter constraint model; determine the required parameters and the constraint parameters in the test code sequence, wherein the constraint parameters refer to the parameters indicated by the parameter constraint model; determine the optional values of the required parameters and the optional values of the constraint parameters according to the combined constraints; generate a first-stage parameter coverage table according to the optional values of the required parameters and the optional values of the constraint parameters; obtain multiple first test cases based on the first-stage parameter coverage table, and test the object to be tested based on the multiple first test cases; generate a second-stage parameter coverage table according to the first test case that has been successfully tested and the optional values of the remaining parameters in the test code sequence, wherein the remaining parameters refer to the parameters in the test code sequence other than the required parameters and the constraint parameters, and the second-stage parameter coverage table is a full parameter coverage table; obtain multiple second test cases based on the full parameter coverage table, and test the object to be tested based on the multiple second test cases to obtain test results.
[0058] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor is used to implement the automated testing method provided by any embodiment of the present invention when executing the program stored in the memory.
[0059] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the automated testing method provided by any embodiment of the present invention.
[0060] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0061] The automated testing method provided by the embodiment of the present invention combines operations in the object to be tested in pairs to form operation code sequences, and obtains an operation code sequence set; generates an operation constraint model according to preset semantic constraints and resource hierarchy dependencies; the operation constraint model indicates the conditions that each operation needs to meet; according to the operation constraint model and the greedy algorithm, the operation code sequences in the operation code sequence set are expanded to generate a test code sequence; a parameter value model and a parameter constraint model are obtained; the parameter value model includes multiple parameter assignment strategies, each parameter assignment strategy defines the data type and value range for the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet; according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, the parameters of each operation in the test code sequence are assigned and tested to obtain a full parameter coverage table and test results. The method uses a preset semantic constraint model and a resource-level dependency key construction operation constraint model, generates a test code sequence based on the operation constraint model, and systematically covers the mutual influence of test operations; the parameter value model defines a variety of parameter assignment strategies, which define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet. Through the parameter value model and the parameter constraint model, various types of parameters can be formatted and defined, enriching the diversity of parameter values, greatly improving the breadth and efficiency of the test. In addition, the automated testing method provided in this embodiment is a low-code automated testing method, which greatly reduces the technical threshold and improves the testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0063] Figure 1 A schematic diagram of the process of the automated testing method provided by an embodiment of the present invention is shown;
[0064] Figure 2 A schematic diagram of a flow chart of an automated testing method for extending an operation code sequence provided by an embodiment of the present invention is shown;
[0065] Figure 3 A schematic diagram of the process of assigning values to operations using the automated testing method provided by an embodiment of the present invention is shown;
[0066] Figure 4 A schematic diagram of the process flow of the automated testing method operation assignment provided by an embodiment of the present invention is shown;
[0067] Figure 5 A schematic diagram of the structure of an automated testing device provided by an embodiment of the present invention is shown;
[0068] Figure 6A schematic structural diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0069] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0070] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more.
[0071] Figure 1 FIG. 1 is a flow chart of an automated testing method provided by an embodiment of the present invention. Figure 1 As shown, the method includes:
[0072] Step S101: operations in the object to be tested are combined in pairs to form operation code sequences, and an operation code sequence set is obtained.
[0073] The object to be tested may be a program or software to be tested. Operation refers to a running action of the object to be tested, such as logging in a work number, locating a customer, querying a customer, selecting a customer, selecting a number card, etc.
[0074] As an optional example, all operations in the object to be tested are taken as elements px, and all elements px are combined into an operation set P, such as set P = {Post / users, Get / users / {uid}, Post / blogs}. Post represents the request method. users represents the user, and uid represents the user ID. Blogs represents the request path, which can be understood as a Post interface.
[0075] The elements in the set P are combined in pairs to form an operation code sequence, and then the operation code sequence set Q is obtained. For example, the set Q = {(Post / users, Get / users / {uid}), (Post / users, Post / blogs), (Get / users / {uid}, Post / users), (Get / users / {uid}, Post / blogs), (Post / blogs, Post / users), (Post / blogs, Get / users / {uid})}. Optionally, the first operation in the operation code sequence can be recorded as including the first operation, and the other operation can be recorded as the second operation. The first operation in the operation code sequence (Post / users, Get / users / {uid}) is Post / users, and the second operation is Get / users / {uid}.
[0076] In this step, operations are combined in pairs to generate operation code sequences, which can ensure the independence of test cases. In the test, each operation code sequence usually represents an independent test case. If two operation code sequences are merged into a longer sequence, the independence between them may be destroyed, making it impossible to execute or evaluate the effect of each operation code sequence separately. Combining in pairs can ensure that each operation code sequence is combined with all other possible operation code sequences, so as to cover various possible situations to the greatest extent. Moreover, the combination in pairs reduces the number of combinations and reduces the complexity of calculation and storage compared with other combination methods such as permutation combination. This is particularly important for large software systems, because the number of operation code sequences may be very large, and the combination in pairs can reduce the calculation cost while maintaining the effectiveness of the test. In addition, the combination in pairs is more in line with actual needs. In the optional software testing process, different operation code sequences are usually required to be tested independently to verify the correctness and performance of their functions. The combination in pairs is more in line with this demand, which can ensure that each operation code sequence can be fully tested.
[0077] Step S102: Generate an operation constraint model according to preset semantic constraints and resource level dependencies.
[0078] The preset semantic constraint may be, for example, a CURD semantic constraint. CURD refers to create, read, update, and delete in database operations. CURD semantic constraints refer to a set of rules or restrictions on the addition, deletion, modification, and query of data in database operations, which are intended to ensure the legality, validity, and integrity of the data. It is worth noting that different semantic constraints may correspond to different application scenarios.
[0079] Resource hierarchical dependencies refer to the hierarchy and order of use of resources. Resources can include employee ID, mobile phone number, credit card number, etc.
[0080] The operation constraint model involves the conditions that each operation needs to meet. For example, users is the parent node of users / {uid}, and users / {uid} related operations cannot be called when the resource represented by users has not been created, that is, Post / users must always be before Get / users / {uid} in the operation code sequence.
[0081] Step S103: According to the operation constraint model and the greedy algorithm, the operation code sequences in the operation code sequence set are expanded to generate test code sequences.
[0082] Greedy algorithm (also known as greedy algorithm) means that when solving a problem, it always makes the best choice that seems to be the best at the moment. In the greedy algorithm, the process of generating an operation code sequence is an iterative process, and each iteration will try to expand the existing operation code sequence. When it is impossible to continue to expand, the current operation code sequence is considered to be a complete test code sequence and added to the test code sequence set. Then, the algorithm returns to the initial state and tries to generate a new test code sequence. In this step, an operation code sequence is arbitrarily selected from the operation code sequence set as the current sequence, and the current sequence is expanded using the greedy algorithm. When expanding, the operation constraint model is used to select the operation code sequence that can be expanded from the operation code sequence set. Since the operation in the test code series can only appear once, the operation code sequence that can be expanded is limited. When no new operation code sequence that can be expanded is screened out, the operation code sequence is expanded, and the expanded operation code sequence is used as the test code sequence.
[0083] Step S104: Obtain a parameter value model and a parameter constraint model.
[0084] The parameter value model includes a variety of parameter assignment strategies, each of which defines a data type and a value range for a parameter. In an optional embodiment, the parameter value model can be defined according to the following process:
[0085] (1) Determine the parameters of the operation. First, you need to clarify the structure of the operation, including its name, parameters, and other information. For example, for an operation to create a user, Post / users, it may contain parameters such as name, age, etc. Then identify all the parameters required for the operation. For example, you can determine it based on the API documentation or the corresponding instructions for the test. For example, Post / users may require two parameters, name and age.
[0086] (2) Define the parameter value model. Define the data type (such as string, integer, etc.) and possible value range for each parameter. For example, name can be any string, and age should be an integer between 0 and 120. Define specific assignment strategies based on the data type and range of the parameters. For example, for the name parameter, you can define different assignments such as "JohnDoe", "Jane Smith", etc.; for the age parameter, you can set specific values such as 25, 30, 35, etc.
[0087] In an optional embodiment, the parameter value model includes a first assignment strategy (Dynamic assignment strategy), a second assignment strategy (Specification assignment strategy), a third assignment strategy (Success assignment strategy) and a fourth assignment strategy (Random assignment strategy).
[0088] The first assignment strategy indicates that the parameter value of the operation that is most similar to the operation to be assigned among the executed operations is used as the parameter value of the operation to be assigned;
[0089] The second assignment strategy indicates that the values of the parameters with the same name as the parameters of the operation to be assigned in all test cases are used as the parameter values of the operation to be assigned. For example, if the execution result of a test case affects the parameter selection of subsequent tests, the second assignment strategy can be used to adjust the parameter values of subsequent tests according to the results of the previous test. The embodiment of the present invention improves the adaptability and accuracy of the test through the second assignment strategy, because it allows the test case to be dynamically adjusted according to the data during actual operation, thereby better simulating the operation scenarios of real users and the actual operation status of the system.
[0090] The third assignment strategy indicates that if the operation to be assigned has been requested (for example, whether the operation has been requested can be determined based on the status code of the request, the operation record log, etc.), the parameter value successfully requested in the request execution history will be used as the parameter value of the operation to be assigned. If a test case is successfully executed, new variables may be introduced or the values of certain parameters may be changed. For example, after selecting the card number, the business operation of "modifying the user" may be performed, which will introduce the variable of "user".
[0091] If the parameter value of the successful request is obtained through the fourth assignment strategy, the random selection mutation strategy is used to change the parameter value of the successful request. The random selection mutation strategy randomly selects a mutation strategy according to a certain probability, thereby increasing the unpredictability of the parameter value.
[0092] The fourth assignment strategy indicates randomly generating the parameter value of the operation to be assigned.
[0093] Optionally, the priorities of the first assignment strategy, the second assignment strategy, the third assignment strategy, and the fourth assignment strategy are successively reduced. That is, when assigning values to parameters in a test code sequence, the priorities of the selected assignment strategies are: the first assignment strategy> the second assignment strategy> the third assignment strategy> the fourth assignment strategy. The parameter constraint model indicates the conditions that the parameters need to meet. In an optional embodiment, the parameter constraint model can be obtained by the following process:
[0094] Step 1): Get the description information of the input parameters of the object to be tested.
[0095] Optionally, step 2): Generate parameter dependency relationships based on the description information of the input parameters. The parameter dependency relationships are used to describe the order relationship or dependency between parameters.
[0096] Step 3): Generate a parameter constraint model based on parameter dependencies.
[0097] In this embodiment, all code path information and the information of the respective input parameters in the object to be tested can be obtained, and the description file of the input parameters by the developer can also be obtained. According to the code path information, the information of the respective input parameters and the description file of the input parameters by the developer, the description information of the input parameters is obtained. Wherein, the code path refers to the xpath path in the corresponding HTML (Hyper Text Markup Language), that is, the path of the corresponding element of the page, for example: / / *[@id="s_index_off_css"]. Then, according to the description information of the input parameters, it is determined whether there is a dependency relationship between the parameters. If there is a dependency relationship between the parameters, a corresponding constraint model is established. For example, the parameter users_t depends on the age parameter, and the parameter can only be created when the age is greater than 18, then the following constraint is generated: users_t can only be created when age>18.
[0098] Step S105: According to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, the parameters of each operation in the test code sequence are assigned and tested to obtain a full parameter coverage table and test results.
[0099] Among them, the two-stage parameter coverage table generation strategy is divided into two stages to generate a full parameter coverage table. The first stage generates a coverage table for important parameters (such as required parameters, parameters involving constraints), and the second stage generates a coverage table for the remaining parameters. The parameter coverage table is a set of use cases for combinatorial testing, which ensures the comprehensiveness of the test by systematically covering all possible combinations of multiple parameters. The embodiment of the present invention can ensure that all possible values of each parameter are taken into account by generating a coverage table containing all necessary test cases, thereby improving the efficiency and accuracy of the test.
[0100] The automated testing method provided by the embodiment of the present invention uses a preset semantic constraint model and a resource hierarchy dependency key construction operation constraint model, generates a test code sequence based on the operation constraint model, and systematically covers the mutual influence of test operations; the parameter value model defines a variety of parameter assignment strategies, which define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet. Through the parameter value model and the parameter constraint model, various types of parameters can be formatted and defined, enriching the diversity of parameter values and greatly improving the breadth and efficiency of the test.
[0101] In an optional embodiment, before expanding the operation code sequence, the method further includes:
[0102] According to the operation constraint model, construct the operation dependency model;
[0103] According to the operation dependency model, the operation code sequences in the operation code sequence set are screened to remove the operation code sequences that do not conform to the operation dependency model;
[0104] According to the operation constraint model and greedy algorithm, the filtered operation code sequence is expanded.
[0105] The operation dependency model and the operation constraint model are related but different concepts. The operation dependency model focuses on describing the order relationship or dependency between operations, while the operation constraint model more broadly involves the preconditions of operations, parameter value constraints, etc. The following uses the examples of creating a new customer and querying customer information to illustrate the process of building an operation dependency model. Among them, the two operations of creating a new customer and querying customer information involve two resources: users ( / users) and user details ( / users / {uid}).
[0106] (1) Identify resources and operations: users (create, read, update, delete), user details (read, update).
[0107] (2) Define operation constraints: User creation (Post / users) must precede obtaining user details (Get / users / {uid}), i.e., Post / users→Get / users / {uid}.
[0108] (3) Build an operation dependency model: Use a diagram or table to clarify the operation sequence of each resource, such as lifecycle management from creation to deletion.
[0109] For example, the operation constraint relationship is: Post / users→Get / users / {uid}; the corresponding operation dependency relationship is: create the user first, then get the information;
[0110] Operation constraint relationship: Get / users / {uid}→Update / users / {uid}; corresponding operation dependency relationship: get information first, then update information
[0111] Operation constraint relationship: Update / users / {uid}→Delete / users / {uid}; corresponding operation dependency relationship: try to update first, then delete.
[0112] Then, according to the operation dependency, all operation code sequences that do not conform to the operation dependency model are removed from the operation code sequence set. For example, (Get / users / {uid}, Post / users) in the operation code sequence set Q is removed.
[0113] Figure 2 FIG. 1 is a flow chart showing an automated testing method for extending an operation code sequence according to an embodiment of the present invention. Figure 2 As shown in FIG. 1 , the process of expanding the operation code sequence includes:
[0114] Step S201: Select an operation code sequence from the operation code sequence set as a sequence to be expanded.
[0115] Step S202: Count the number of all first operations in the operation code sequence set, take the first operation with the most number of times as the first operation, add the first operation to the current sequence, and add the first operation to the preset set. If there are multiple first operations with the most number of times, randomly select one as the first operation. As an example, if the number of first operations counted is: Post / users 2 times, Get / users / {uid} 1 time, Post / blogs 2 times. Then add Post / users to the sequence to be expanded.
[0116] Step S203: Take the operation code sequences whose first operations in the operation code sequence set are the first operation as candidate operation code sequences, count the number of all the second operations in the candidate operation code sequence set, take the second operation with the largest number of times as the second operation, and add the second operation to the current sequence.
[0117] Step S204: Delete all operation code sequences in the operation code sequence set whose first operation is an element in the preset set and whose second operation is a second operation. The elements in the preset set include not only the first operation added to the preset set in the current iteration round, but also the first operation and the second operation added to the preset set in the previous iteration round.
[0118] Step S205: Add the second operation to the preset set.
[0119] Step S206: According to the operation constraint model, determine whether the sequence to be expanded is completed. Whether the sequence to be expanded can continue to be expanded mainly depends on whether there are other operations that meet the operation constraint model and are not included in the sequence to be expanded. If there are such operations, the sequence to be expanded can continue to be expanded; if not, the sequence to be expanded has been expanded. In the case that the sequence to be expanded can continue to be expanded, return to step S202 to determine a new first operation and a new second operation.
[0120] Step S207: when the sequence to be expanded is expanded, a new sequence to be expanded is determined to expand the new sequence to be expanded.
[0121] In an optional embodiment, the process of judging whether the sequence to be expanded is expanded is completed according to the operation constraint model includes:
[0122] According to the operation constraint model, determine the operation compatible with the last operation of the sequence to be expanded. The last operation refers to the last operation in the sequence to be expanded. The operation compatible with the last operation includes: an operation with constraints on the last operation, and the operation meets the constraints of the operation constraint model, and / or an operation without a dependency or constraint relationship with the last operation.
[0123] Determines whether operations compatible with the last operation have been traversed during the process of expanding the sequence to be expanded.
[0124] When operations compatible with the last operation are traversed during the expansion of the sequence to be expanded, it is determined that the expansion of the sequence to be expanded is completed.
[0125] In this embodiment, when a test code sequence set is obtained, the operations of the test code sequences in the test code sequence set are assigned values and a test is requested.
[0126] Figure 3 The following is a schematic diagram showing the flow of assigning values to operations using the automated testing method provided by an embodiment of the present invention. Figure 3 As shown, the method includes:
[0127] Step S301: test code sequence selection: select a test code sequence from a test code sequence set, and delete the selected test code sequence from the test code sequence set.
[0128] Step S302: Operation assignment: assign values to the operations in the test code sequence in sequence and define parameter values.
[0129] Step S303: determine whether the operation assignment covers all test code sequences in the test code sequence set. If so, complete the generation of the full parameter coverage table. If not, return to the test code sequence selection step.
[0130] Figure 4 A schematic diagram of the process flow of the automated testing method operation assignment provided by an embodiment of the present invention is shown.
[0131] like Figure 4 As shown, the parameter assignment process includes:
[0132] Step S401: Determine a combined constraint according to the parameter value model and the parameter constraint model. This step combines the parameter assignment strategy of the parameter value model with the constraints in the parameter constraint model to determine the combined constraint.
[0133] As optional examples, the combination constraints may include, but are not limited to: numerical range constraints, mandatory parameter existence constraints, parameter dependency constraints, combination constraints excluding specific values, and conditional trigger constraints.
[0134] Among them, the value range constraint specifies that the parameter value must be within a certain range. For example, the user's age must be between 0 and 120. When assigning a value to the age parameter, a value that fits this range is automatically generated, such as randomly selecting an age of 35, 52, or 100.
[0135] The required parameter existence constraint indicates that certain parameters (such as required parameters) must exist or have specific values. For example, in the create user operation, the user name (name) is a required item. In the parameter assignment, the required parameter existence constraint is used to ensure that each test case contains the name parameter and assigns it a suitable value.
[0136] The parameter dependency constraint indicates that the value of one parameter depends on the value of another parameter. For example, if the user selects the "Annual Payment" option, the "Credit Card Information" must be provided. When generating a test case, when the "Annual Payment" option is selected, the "Credit Card Information" parameter is automatically added and assigned a value according to the parameter dependency constraint.
[0137] The combination constraint of excluding specific values indicates that some combinations of parameter values may be excluded by business rules. For example, the user cannot select the two options "immediate delivery" and "custom product" at the same time. During the test case generation process, this disallowed combination is automatically avoided according to the combination constraint of excluding specific values.
[0138] Conditional trigger constraints indicate that the existence or specific values of certain parameters may trigger additional logic or requirements for other parameters. For example, if the "order amount" exceeds a certain value, the "tax registration number" needs to be provided. When generating test cases, set the conditional judgment logic. When the "order amount" exceeds the preset value, the conditional trigger constraint automatically adds and fills in the "tax registration number" parameter.
[0139] Step S402: Determine the mandatory parameters and constraint parameters in the test code sequence. Constraint parameters refer to constraint parameters, that is, parameters indicated in the parameter constraint model.
[0140] Optionally, you can identify the required parameters based on the test requirements document. For example, if the first step of the test scenario is to log in to the system with your work ID, then your work ID and password are required parameters.
[0141] Step S403: According to the combined constraint, the optional values of the required parameters and the optional values of the constraint parameters are listed.
[0142] Step S404: Generate a first-stage parameter coverage table according to the optional values of the required parameters and the optional values of the constraint parameters.
[0143] Step S405: Based on the first-stage parameter coverage table, a plurality of first test cases are obtained, and the object to be tested is tested based on the plurality of first test cases. For example, the parameter values in the first-stage parameter coverage table are respectively substituted into the test code sequence to obtain a plurality of first test cases.
[0144] Step S406: Generate a second-stage parameter coverage table based on the first test case that has been successfully tested and the optional values of the remaining parameters in the test code sequence, wherein the remaining parameters refer to the parameters in the test code sequence other than the required parameters and the constraint parameters, and the second-stage parameter coverage table is a full parameter coverage table. For example, the first test case that has been successfully tested is taken as an abstract parameter, and the optional values of the abstract parameter and the remaining parameters are listed to generate a second-stage parameter coverage table. The second-stage parameter coverage table covers all parameters in the test agent sequence.
[0145] Step S407: Based on the full parameter coverage table, a plurality of second test cases are obtained, and the object to be tested is tested based on the plurality of second test cases to obtain a test result.
[0146] The automated testing method of the embodiment of the present invention assigns values to the parameters of each operation in the test code sequence based on a parameter value model, a parameter constraint model and a two-stage parameter coverage generation strategy, thereby enriching the diversity of the assignment and greatly improving the breadth and efficiency of the test.
[0147] Figure 5 FIG. 1 is a schematic diagram showing the structure of an automated testing device provided by an embodiment of the present invention. Figure 5 As shown, the automated testing device 500 includes:
[0148] A combination module 501 is used to combine the operations in the object to be tested in pairs to form an operation code sequence, and obtain an operation code sequence set;
[0149] The operation constraint generation module 502 is used to generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet;
[0150] A test code generation module 503, configured to expand the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm to generate a test code sequence;
[0151] The acquisition module 504 is used to acquire a parameter value model and a parameter constraint model; the parameter value model includes a plurality of parameter assignment strategies, the parameter assignment strategies define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet;
[0152] The automatic testing module 505 is used to assign values to and test the parameters of each operation in the test code sequence according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, and obtain a full parameter coverage table and test results.
[0153] Optionally, the test code generation module is used to: construct an operation dependency model based on the operation constraint model; filter the operation code sequences in the operation code sequence set based on the operation dependency model to remove operation code sequences that do not conform to the operation dependency model; and expand the filtered operation code sequences based on the operation constraint model and a greedy algorithm.
[0154] Optionally, the operation code sequence includes a first operation and a second operation;
[0155] The test code generation module is used to: select an operation code sequence from the operation code sequence set as a sequence to be expanded; expand the sequence to be expanded according to the following process: count the number of all first operations in the operation code sequence set, take the first operation with the largest number of times as the first operation, add the first operation to the sequence to be expanded, and add the first operation to a preset set; take all operation code sequences in the operation code sequence set whose first operation is the first operation as candidate operation code sequences, count the number of all second operations in the candidate operation code sequence set, take the second operation with the largest number of times as the second operation, and add the second operation to the sequence to be expanded; delete all operation code sequences in the operation code sequence set whose first operation is an element in the preset set and whose second operation is the second operation; add the second operation to the preset set; judge whether the sequence to be expanded is expanded according to the operation constraint model; if the expansion of the sequence to be expanded is completed, determine a new sequence to be expanded, and expand the new sequence to be expanded.
[0156] Optionally, the test code generation module is used to: determine, based on the operation constraint model, an operation that is compatible with the end operation of the sequence to be expanded; determine whether the operations compatible with the end operation have been traversed during the process of expanding the sequence to be expanded; and determine that the expansion of the sequence to be expanded is completed if the operations compatible with the end operation have been traversed during the process of expanding the sequence to be expanded.
[0157] Optionally, the acquisition module is used to: acquire description information of input parameters of the object to be tested; generate parameter dependency relationships according to the description information of the input parameters; and generate a parameter constraint model according to the parameter dependency relationships.
[0158] Optionally, the automated testing module is used to: determine the combined constraints according to the parameter value model and the parameter constraint model; determine the required parameters and the constraint parameters in the test code sequence, wherein the constraint parameters refer to the parameters indicated by the parameter constraint model; determine the optional values of the required parameters and the optional values of the constraint parameters according to the combined constraints; generate a first-stage parameter coverage table according to the optional values of the required parameters and the optional values of the constraint parameters; obtain multiple first test cases based on the first-stage parameter coverage table, and test the object to be tested based on the multiple first test cases; generate a second-stage parameter coverage table according to the first test case that has been successfully tested and the optional values of the remaining parameters in the test code sequence, wherein the remaining parameters refer to the parameters in the test code sequence other than the required parameters and the constraint parameters, and the second-stage parameter coverage table is a full parameter coverage table; obtain multiple second test cases based on the full parameter coverage table, and test the object to be tested based on the multiple second test cases to obtain test results.
[0159] The above device can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.
[0160] Figure 6 FIG. 1 is a schematic diagram showing the structure of an electronic device according to an embodiment of the present invention. Figure 6 As shown, the electronic device includes:
[0161] Processor 601, communication interface 602, memory 603 and communication bus 604, wherein processor 601, communication interface 602, memory 603 communicate with each other via communication bus 604.
[0162] Memory 603, used for storing computer programs;
[0163] The processor 601 is used to execute the program stored in the memory 603 to implement the following steps:
[0164] Combining operations in the object to be tested in pairs to form operation code sequences, and obtaining an operation code sequence set;
[0165] Generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet;
[0166] According to the operation constraint model and the greedy algorithm, the operation code sequence in the operation code sequence set is expanded to generate a test code sequence;
[0167] Obtaining a parameter value model and a parameter constraint model; the parameter value model includes a plurality of parameter assignment strategies, the parameter assignment strategies define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to satisfy;
[0168] According to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, the parameters of each operation in the test code sequence are assigned and tested to obtain a full parameter coverage table and test results.
[0169] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0170] The communication interface is used for communication between the above terminal and other devices.
[0171] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0172] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0173] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed on a computer, the computer executes the automated testing method described in any one of the above embodiments.
[0174] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes the automated testing method described in any one of the above embodiments.
[0175] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0176] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0177] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0178] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. An automated testing method, characterized in that: include: Combining operations in the object to be tested in pairs to form operation code sequences, and obtaining an operation code sequence set; Generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet; According to the operation constraint model and the greedy algorithm, the operation code sequence in the operation code sequence set is expanded to generate a test code sequence; Obtaining a parameter value model and a parameter constraint model; the parameter value model includes a plurality of parameter assignment strategies, the parameter assignment strategies define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to satisfy; According to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, the parameters of each operation in the test code sequence are assigned and tested to obtain a full parameter coverage table and test results.
2. The method according to claim 1, characterized in that The step of expanding the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm includes: constructing an operation dependency model according to the operation constraint model; According to the operation dependency model, the operation code sequences in the operation code sequence set are screened to remove the operation code sequences that do not conform to the operation dependency model; According to the operation constraint model and the greedy algorithm, the filtered operation code sequence is expanded.
3. The method according to claim 1 or 2, characterized in that: The operation code sequence includes a first operation and a second operation; The step of expanding the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm includes: Selecting an operation code sequence from the operation code sequence set as a sequence to be expanded; The sequence to be expanded is expanded according to the following process: Counting the number of all first operations in the operation code sequence set, taking the first operation with the largest number of times as the first operation, adding the first operation to the sequence to be expanded, and adding the first operation to a preset set; Taking all operation code sequences whose first operation in the operation code sequence set is the first operation as candidate operation code sequences, counting the number of all second-order operations in the candidate operation code sequence set, taking the second-order operation with the largest number of operations as the second operation, and adding the second operation to the sequence to be expanded; Deleting all operation code sequences in the operation code sequence set whose first operation is an element in the preset set and whose second operation is the second operation; Adding the second operation to the preset set; According to the operation constraint model, determining whether the sequence to be expanded is expanded; When the expansion of the sequence to be expanded is completed, a new sequence to be expanded is determined, and the new sequence to be expanded is expanded.
4. The method according to claim 3, characterized in that Judging whether the sequence to be expanded is expanded according to the operation constraint model includes: Determining, according to the operation constraint model, an operation that is compatible with the end operation of the sequence to be extended; Determining whether operations compatible with the end operation have been traversed in the process of extending the sequence to be extended; When all operations compatible with the last operation are traversed during the expansion of the sequence to be expanded, it is determined that the expansion of the sequence to be expanded is completed.
5. The method according to claim 1, characterized in that: Get parameter constraint model, including: Obtaining description information of input parameters of the object to be tested; Generate a parameter dependency relationship according to the description information of the input parameters; A parameter constraint model is generated according to the parameter dependency relationship.
6. The method according to claim 1, characterized in that The method of assigning values to the parameters of each operation in the test code sequence and testing them according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy to obtain a full parameter coverage table and test results includes: Determining a combination constraint according to the parameter value model and the parameter constraint model; Determine the mandatory parameters and constraint parameters in the test code sequence, wherein the constraint parameters refer to the parameters indicated by the parameter constraint model; Determining, according to the combined constraint, optional values of the mandatory parameter and optional values of the constraint parameter; Generate a first-stage parameter coverage table according to the optional values of the required parameters and the optional values of the constraint parameters; Based on the first-stage parameter coverage table, a plurality of first test cases are obtained, and the object to be tested is tested based on the plurality of first test cases; Generate a second-stage parameter coverage table according to the first test case that has been successfully tested and the optional values of the remaining parameters in the test code sequence, wherein the remaining parameters refer to the parameters in the test code sequence other than the required parameters and the constraint parameters, and the second-stage parameter coverage table is a full parameter coverage table; Based on the full parameter coverage table, a plurality of second test cases are obtained, and based on the plurality of second test cases, the object to be tested is tested to obtain a test result.
7. The method according to claim 6, characterized in that The parameter value model includes a first assignment strategy, a second assignment strategy, a third assignment strategy and a fourth assignment strategy; The first assignment strategy indicates that the parameter value of the operation that is most similar to the operation to be assigned among the executed operations is used as the parameter value of the operation to be assigned; The second assignment strategy indicates that the values of the parameters with the same names as the parameters of the operation to be assigned in all test cases are used as the parameter values of the operation to be assigned; The third assignment strategy indicates that, when the operation to be assigned has been requested to be executed, the parameter value successfully requested in the request execution history is used as the parameter value of the operation to be assigned; The fourth assignment strategy indicates randomly generating the parameter value of the operation to be assigned.
8. The method according to claim 7, characterized in that The priorities of the first assignment strategy, the second assignment strategy, the third assignment strategy and the fourth assignment strategy decrease in sequence.
9. An automated testing device, characterized in that: include: A combination module, used for combining operations in the object to be tested in pairs to form an operation code sequence, and obtaining an operation code sequence set; An operation constraint generation module, used to generate an operation constraint model according to preset semantic constraints and resource level dependencies; the operation constraint model indicates the conditions that each operation needs to meet; A test code generation module, used to expand the operation code sequence in the operation code sequence set according to the operation constraint model and the greedy algorithm to generate a test code sequence; An acquisition module, used to acquire a parameter value model and a parameter constraint model; the parameter value model includes a plurality of parameter assignment strategies, the parameter assignment strategies define the data type and value range of the parameter, and the parameter constraint model indicates the conditions that the parameter needs to meet; The automatic testing module is used to assign and test the parameters of each operation in the test code sequence according to the parameter value model, the parameter constraint model and the two-stage parameter coverage generation strategy, and obtain a full parameter coverage table and test results.
10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method according to any one of claims 1 to 8 when executing a program stored in a memory.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Scientific research activity management and application platform supporting multidisciplinary sharing
CN120013466A
