Updating method and device of test case
By analyzing the explanation information of API changes, the API calls in the test cases are automatically updated, which solves the problem of code changes causing test cases to fail, and improves testing efficiency and accuracy.
Patent Information
- Application Number
- CN202510299162.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-06-27
AI Technical Summary
When the application program interface (API) changes in the code, existing test cases are prone to failure, resulting in the need to manually understand the changes logic of API functions and manually modify the test cases. The process is cumbersome, prone to errors and high cost.
By obtaining the explanation information of API changes, determining the input parameters and output parameters relationship between the first API and the second API, automatically update the API calls in the test case, and automatically update the test case.
There is no need to manually understand the API changes logic, automatically update test cases, improve testing efficiency, reduce manual errors, and reduce costs.
Smart Images

Figure CN120216371A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method and device for updating test cases. Background Art
[0002] Currently, for the functional testing of application programming interfaces (APIs) in code, generally, developers design the content of the APIs in the code, and testers test the functions of the APIs based on test cases. When developers modify the APIs in the code, since the types of API input and output fields, data representation methods, calculation formulas, etc. change, the existing test cases may become invalid. However, if the invalid existing test cases are simply discarded and new test cases are designed for the functions of the new APIs, the existing achievements will be wasted, and duplicate and redundant design work will be caused, resulting in low efficiency. Therefore, testers need to manually understand the change logic of the API functions and then manually modify those test cases affected by the code changes until the tests pass, and this process is error-prone, time-consuming, and costly.
[0003] Therefore, when the code is modified, how to automatically update the test cases still needs further research. Summary of the Invention
[0004] Embodiments of the present invention provide a method and device for updating test cases. When the code is modified, according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API, the first API in the statements affected by the change of the first API is modified to the second API, without the need for manual understanding of the change logic and re-writing of test cases, realizing the automatic update of test cases and improving the test efficiency.
[0005] In a first aspect, embodiments of the present invention provide a method for updating test cases. The method includes: obtaining description information for modifying the first application programming interface (API) in the code to the second API; determining, according to the description information, the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API; determining at least one statement affected by the change of the first API in the test cases of the code; and modifying the first API in the at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0006] Using the above method, when the code is modified, it causes the original test cases to fail. At this time, by obtaining the description information of modifying the first application programming interface (API) in the code to the second API, and analyzing according to the obtained description information, the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API are obtained. The relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API accurately describe the conversion rules between the first API and the second API. By deeply analyzing the semantics of the code, rather than simply string matching and replacement, the code in the test cases affected by the change of the first API is automatically updated. The updated test cases are not only correct in syntax and semantics, but also conform to the syntax of the modified API and can pass the compilation, enabling the new test cases to be consistent with the original test logic and improving the efficiency of automatic update of the test cases.
[0007] In an alternative embodiment, according to the description information, determining the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API includes: performing symbolic execution on the description information to obtain the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0008] Using the above method, by performing symbolic execution on the obtained modification description of modifying the first API to the second API, the relationship between the output parameters of the first API and the output parameters of the first API, and the relationship between the output parameters of the first API and the output parameters of the second API can be obtained. The relationship between the output parameters of the first API and the output parameters of the first API, and the relationship between the output parameters of the first API and the output parameters of the second API accurately describe how to obtain the input parameters of the second API from the input parameters of the first API, and the conversion logic between the output parameters of the first API and the output parameters of the second API, providing key information for the subsequent update of the test case code.
[0009] In an alternative embodiment, the at least one statement includes a first statement, and the first statement is an assignment statement; according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API, modifying the first API in the at least one statement to the second API includes: obtaining the input parameter values of the first API in the first statement and the return value of the first statement; according to the relationship between the input parameters of the first API and the input parameters of the second API, and the input parameter values of the first API in the first statement, obtaining the input parameter values of the second API; according to the relationship between the output parameters of the first API and the output parameters of the second API, and the return value of the first statement, obtaining a new return value; according to the input parameter values of the second API and the new return value, modifying the first API in the first statement to the second API.
[0010] Using the above method, first analyze the first statement in the statement affected by the first API in the original test case to obtain the code logic of the first statement. Since the first statement is an assignment statement, obtain the input parameter values of the first API in the first statement and the return value of the first statement. The above information not only includes the location of the code affected by the first API in the test case, but also includes the semantics of the statement. Combining the above information with the relationship between the output parameters of the first API and the output parameters of the first API, and the relationship between the output parameters of the first API and the output parameters of the second API, the modified test logic can be obtained, that is, the input parameter values of the second API and the new return value. According to the input parameter values of the second API and the new return value, modify the first API in the first statement to the second API. The modified test case generated in this way is not only syntactically correct, but also semantically correct, and the semantics of the modified test code is consistent with the original test code.
[0011] In an alternative embodiment, the relationship between the input parameters of the first API and the input parameters of the second API is that the input parameters of the first API and the input parameters of the second API satisfy a first functional relationship; according to the relationship between the input parameters of the first API and the input parameters of the second API, and the input parameter values of the first API in the first statement, obtaining the input parameter values of the second API includes: obtaining the input parameter values of the second API according to the input parameter values of the first API in the first statement and the first functional relationship.
[0012] By adopting the above method, through in-depth analysis of the semantics in the code, it is possible to automatically infer the values of the input parameters of the second API in the affected test cases, thereby improving the correctness of code modification.
[0013] In an alternative embodiment, the relationship between the output parameter of the first API and the output parameter of the second API is that the output parameter of the first API and the output parameter of the second API satisfy a second functional relationship; obtaining a new return value according to the relationship between the output parameter of the first API and the output parameter of the second API and the return value of the first statement includes: obtaining a new return value according to the output parameter of the first API in the return value of the first statement and the second functional relationship.
[0014] By adopting the above method, through in-depth analysis of the semantics in the code, it is possible to automatically infer the new return value in the affected test cases, thereby improving the correctness of code modification.
[0015] In an alternative embodiment, modifying the first API in the first statement to the second API according to the value of the input parameter of the second API and the new return value includes: modifying the return value in the first statement to the new return value; substituting the value of the input parameter of the second API into the input parameter of the second API to obtain the second API, and modifying the output parameter of the second API in the new return value to the second API.
[0016] In an alternative embodiment, the at least one statement includes a second statement, and the second statement is an assertion statement; modifying the first API in the at least one statement to the second API according to the relationship between the input parameter of the first API and the input parameter of the second API and the relationship between the output parameter of the first API and the output parameter of the second API includes: obtaining the value of the input parameter of the first API in the second statement and the assertion logic of the second statement; obtaining the value of the input parameter of the second API according to the relationship between the input parameter of the first API and the input parameter of the second API and the value of the input parameter of the first API in the second statement; obtaining a new assertion logic according to the relationship between the output parameter of the first API and the output parameter of the second API and the assertion logic of the second statement; and modifying the first API in the second statement to the second API according to the value of the input parameter of the second API and the new assertion logic.
[0017] Using the above method, first analyze the second statement in the statements affected by the first API in the original test case to obtain the code logic of the second statement. Since the second statement is an assignment statement, obtain the input parameter values of the first API in the second statement and the assertion logic of the second statement. The above information not only includes the location of the code affected by the first API in the test case, but also includes the semantics of the statement. Combining the above information with the relationship between the output parameters of the first API and the output parameters of the first API, and the relationship between the output parameters of the first API and the output parameters of the second API, the modified test logic can be obtained, that is, the input parameter values of the second API and the new test logic. Modify the first API in the second statement to the second API according to the input parameter values of the second API and the new test logic. The generated modified test case is not only syntactically correct, but also semantically correct. The semantics of the modified test code is consistent with the original test code.
[0018] In an alternative embodiment, modifying the first API in the second statement to the second API according to the input parameter values of the second API and the new assertion logic includes: modifying the assertion logic in the second statement to a new assertion logic; substituting the input parameter values of the second API into the input parameters of the second API to obtain the second API, and modifying the return value of the second API in the new assertion logic to the second API.
[0019] In a second aspect, an embodiment of the present invention provides a test case update device, which includes:
[0020] An acquisition unit, configured to acquire description information for modifying a first application programming interface (API) in code to a second API;
[0021] A determination unit, configured to determine, according to the description information, the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API; determine at least one statement affected by the change of the first API in the test case of the code;
[0022] A processing unit, configured to modify the first API in the at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0023] In an alternative embodiment, the determining unit is specifically configured to perform symbolic execution on the description information to obtain the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0024] In an alternative embodiment, the at least one statement includes a first statement, and the first statement is an assignment statement; the processing unit is specifically configured to obtain the input parameter value of the first API in the first statement and the return value of the first statement; according to the relationship between the input parameters of the first API and the input parameters of the second API, and the input parameter value of the first API in the first statement, obtain the input parameter value of the second API; according to the relationship between the output parameters of the first API and the output parameters of the second API, and the return value of the first statement, obtain a new return value; according to the input parameter value of the second API and the new return value, modify the first API in the first statement to the second API.
[0025] In an alternative embodiment, the relationship between the input parameters of the first API and the input parameters of the second API is that the input parameters of the first API and the input parameters of the second API satisfy a first functional relationship; the processing unit is configured to obtain the input parameter value of the second API according to the input parameter value of the first API in the first statement and the first functional relationship.
[0026] In an alternative embodiment, the relationship between the output parameters of the first API and the output parameters of the second API is that the output parameters of the first API and the output parameters of the second API satisfy a second functional relationship; the processing unit is configured to obtain a new return value according to the output parameter of the first API in the return value of the first statement and the second functional relationship.
[0027] In an alternative embodiment, the processing unit is configured to modify the return value in the first statement to the new return value; substitute the input parameter value of the second API into the input parameters of the second API to obtain the second API, and modify the output parameter of the second API in the new return value to the second API.
[0028] In an alternative embodiment, the at least one statement includes a second statement, and the second statement is an assertion statement; specifically, the processing unit is configured to obtain the input parameter values of the first API in the second statement and the assertion logic of the second statement; according to the relationship between the input parameters of the first API and the input parameters of the second API, and the input parameter values of the first API in the second statement, obtain the input parameter values of the second API; according to the relationship between the output parameters of the first API and the output parameters of the second API, and the assertion logic of the second statement, obtain a new assertion logic; and according to the input parameter values of the second API and the new assertion logic, modify the first API in the second statement to the second API.
[0029] In an alternative embodiment, the processing unit is configured to modify the assertion logic in the second statement to a new assertion logic; substitute the input parameter values of the second API into the input parameters of the second API to obtain the second API, and modify the return value of the second API in the new assertion logic to the second API.
[0030] In a third aspect, an embodiment of the present invention provides a test case update device, including: a memory for storing a computer program; a processor for, when executing the computer program stored on the memory, performing the method described in the first aspect above according to the obtained program.
[0031] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored. When a computer reads and executes the computer program, the method described in the first aspect above is executed.
[0032] In a fifth aspect, an embodiment of the present invention provides a computer program product. When a computer reads and executes the computer program product, the method described in the first aspect above is executed. Description of the Drawings
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0034] Figure 1 It is a schematic diagram of a system architecture provided by an embodiment of the present application;
[0035] Figure 2The flowchart corresponding to a test case update method provided by an embodiment of this application;
[0036] Figure 3 The flowchart corresponding to a test case update method provided by an embodiment of this application;
[0037] Figure 4 The flowchart corresponding to a test case update method provided by an embodiment of this application;
[0038] Figure 5 Another flowchart corresponding to the test case update method provided by an embodiment of this application;
[0039] Figure 6 The structural schematic diagram of a test case update device provided by an embodiment of this application;
[0040] Figure 7 The structural schematic diagram of a test case update device provided by an embodiment of this application. Detailed implementation manners
[0041] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention. In the embodiments of the present invention, "a plurality of" means two or more. The terms "first", "second", etc. are only used for the purpose of distinguishing descriptions, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0042] Before introducing and explaining the embodiments of this application, relevant terms involved in this application are first explained.
[0043] An integrated development environment (IDE) is an application program used to assist programmers in developing software code efficiently, and usually includes functions such as code editing, automatic building, and testing.
[0044] An API is a computing interface used to define the interaction protocol between multiple software or software components.
[0045] A domain specific language (DSL) refers to a language designed for a specific application domain.
[0046] Symbolic execution is a program analysis technique that uses abstract symbols instead of concrete values as program input variables to obtain the abstract output results of each path.
[0047] When the content such as the types of input and output fields of APIs in the code, data representation methods, calculation formulas, etc. is changed, it may cause the existing test cases to fail. At this time, testers need to manually understand the change logic of the software function and then manually modify those existing test cases affected by the code change until the test passes, and this process is error-prone and time-consuming.
[0048] Currently, the affected test cases can be modified through the batch refactoring function in existing software development tools. The specific steps are as follows:
[0049] Step 1: The user selects the type of refactoring action to be executed through menu selection, shortcut keys, etc., triggering the specified refactoring function window.
[0050] Step 2: The user fills in the information related to the refactoring action content in the refactoring function window, such as: the name of the new variable when renaming a variable, the target type when modifying the type.
[0051] Step 3: The IDE traverses the content of all code files in the project, matches each one with the information provided by the user above, and searches for all code locations affected by the refactoring action that need to be modified.
[0052] Step 4: The IDE batch replaces the above positions with the content after the required modification according to the information filled in by the user to obtain the modified code.
[0053] For example, the IDE tool can be IntelliJ IDEA. IntelliJ IDEA is a popular commercial IDE often used for developing Java code. When the user executes inlining a variable, first select the relevant assignment statement to be inlined, and then trigger the IDE to perform the refactoring action of inlining the variable through the "Refactor>Inline Variable" function in the right-click menu. The IDE will search for other references to the variable in the project code according to the target variable on the left side of the assignment statement selected by the user and replace these references with the expression on the right side of the assignment statement selected by the user.
[0054] However, when using existing IDEs to update test cases, the existing IDE batch replacement function focuses on simple string matching and replacement at the syntax level, fails to perform in-depth analysis of the code semantics, ignores the correctness of the semantics, and cannot provide correctness guarantee for more complex code. There are also the following problems:
[0055] Problem 1: The refactoring functions supported by existing IDE tools are very limited. When there are related refactoring actions not supported by the IDE, users need to manually check the code line by line to find all the affected code locations and modify the code manually. This work is not only extremely labor-intensive but also very error-prone. For example, in the following scenario of refactoring the data representation format: If there is an API in the code that returns a string containing 3 numbers separated by commas. Now it is required to change the return value of this API from a comma-separated string to a space-separated string. Since the return value type remains a string, which does not meet the refactoring action of changing the return value type in the IDE, the batch refactoring function of the IDE cannot be used. At this time, users need to check the code line by line to find all the affected code locations and modify the code manually.
[0056] Problem 2: Existing IDE tools usually only support simple literal replacement and do not support modifications that require a deeper understanding of the code semantics. For example, in the scenario of refactoring the input and output field types: If there is a field named value in the Java code, and its type is Integer. After changing the type of this field to Float, a compilation error may occur due to type mismatch at the places where the value field is referenced in the test cases. At this time, the test cases need to be updated accordingly, and the places where the field is referenced need to be appropriately adjusted to match the Float type while keeping the behavior of the test cases consistent with the previous ones. However, if the batch refactoring function of existing mainstream IDEs is used, taking IntelliJ IDEA as an example, using the "Refactor>Type Migration>Class Hierarchy" function in its right-click menu may not correctly reference the new value field, resulting in a type error and unable to compile. If the "Refactor>Type Migration>AllPlaces" function in its right-click menu is used, it may modify other variables with the same name value, causing the behavior of the test cases to change unexpectedly and causing damage. Obviously, both of these modifications are incorrect. It can be seen that the batch refactoring functions of these IDEs may make inaccurate, imperfect, and ungrammatical modifications to the code, and cannot guarantee the correctness of the modified code.
[0057] Based on this, an embodiment of the present application provides a method for updating test cases. According to the description information of modifying the first API to the second API in the code, the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API are determined. According to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API, the first API in the statements related to the first API in the test cases is modified to the second API. In this way, when the content such as the input and output field types and data representation formats of the API in the code changes, there is no need to manually understand the API modification logic to manually modify the test cases, realizing the automatic update of the test cases.
[0058] Figure 1 This is a schematic diagram of a system architecture provided by an embodiment of the present application. As Figure 1 shown, this system architecture includes a terminal device 101 and a server 102. Among them, the terminal device 101 can be a device such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The target application client can be installed in the terminal device 101, such as the clients of code compilation applications, code modification applications, code testing applications, etc. Users can modify, compile, and test the code on the client installed with the target application. The server 102 is used to provide background services for the client of the target application (such as a code modification application) in the terminal device 101. For example, the server 102 can be the background server of the above target application (such as a code modification application). The server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing 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 Network (CDN), and big data and artificial intelligence platforms. The terminal 101 and the server 102 can communicate with each other through a network. The network can be a wired network or a wireless network, and the present application does not make a limitation.
[0059] It should be noted that Figure 1 The above is only an example. In fact, the number of the terminal device 101 and the server 102 is not limited and is not specifically limited in the embodiment of the present application.
[0060] Next, the method provided by the present application will be described in detail with specific embodiments.
[0061] Figure 2The figure is a flowchart corresponding to a method for updating test cases provided by an embodiment of the present application. This method can be executed by a test case update device (hereinafter referred to as the update device), which can be any one of the servers in the figure, or can also be an independently deployed device, and no specific limitation is made. For example Figure 2 As shown, the method includes:
[0062] Step 210, the update device obtains the description information for modifying the first API in the code to the second API.
[0063] Exemplarily, a developer modifies the first API in the project code to the second API, and the update device obtains the description information for modifying the first API in the code to the second API, and the description information can be provided by the developer who makes changes to the code.
[0064] Exemplarily, the description information can be used to describe the changes between the input and output of the first API and the second API. The description information may include the function interface information of the first API and the second API and the association information of the first API and the second API. Among them, the function interface information of the first API and the second API includes at least one of the following: the name of the first API, the name of the input parameter of the first API, the name of the output parameter of the first API, the name of the second API, the name of the input parameter of the second API, and the name of the output parameter of the second API. The association information of the first API and the second API can be described by code on how to use the input parameter in the first API to obtain the input parameter of the second API, and how to use the output parameter of the first API to obtain the output parameter of the second API.
[0065] For example, the modification description can be the modification description of changing API A1 to API A2 , or can also be the modification description of changing API B1 to API B2 , or can also be the modification description of changing API C1 to API C2 The specific details are as follows:
[0066] (1) The modification description of changing API A1 to API A2
[0067] Among them, Table 1 is an example of the function interface information of API A1 and API A2 in the modification description of changing API A1 to API A2 , as shown in Table 1:
[0068] Table 1: Example of modification description
[0069] API API Name API Input Parameter Name API Output Parameter Name <![CDATA[API A1 > colorFactory1 r, g, b, a1 o1 <![CDATA[API A2 > colorFactory2 h, s, l, a2 o2
[0070] API A1 and API A1 The associated information of API includes Code 1 and Code 2
[0071] API in the modification description A1 and API A1 The Code 1 in the associated information of API is as follows:
[0072]
[0073]
[0074] The above Code 1 implements the function rgb2hsl, that is, how to convert the input parameters r, g, b, a1 of colorFactory1 into the input parameters h, s, l, a2 of colorFactory2.
[0075] API in the modification description A1 and API A1 The Code 2 in the associated information of API:
[0076] o1 == o2
[0077] o1 == o2 means that when API A1 (i.e., colorFactory1) is modified to API A2 (i.e., colorFactory2), the output parameters remain unchanged.
[0078] (2) The modification description for modifying API B1 to API B2 is as follows
[0079] Among them, Table 2 is an example of the function interface information of API B1 modified to API B2 in the modification description, and API B1 and API B2 is shown in Table 2 as follows:
[0080] Table 2: Modification description example
[0081] API API Name API Input Parameter Name API Output Parameter Name <![CDATA[API B1 > toHwbString1 c1 o3 <![CDATA[API B2 > toHwbString2 c2 o4
[0082] API B1 and API B2 The associated information includes Code 3 and Code 4
[0083] API in the modification description B1 and API B2 The Code 3 in the associated information of API:
[0084] c1 == c2
[0085] c1 == c2 means that when the API B1 (i.e., toHwbString1) is modified to the API B2 (i.e., toHwbString2), the input parameters remain unchanged.
[0086] The relevant information about the APIs in the modification description B1 and the API B2 The code 4 in the associated information is as follows:
[0087]
[0088] The first line of code in code 4 describes how to obtain the output parameter of the API B1 from the output parameter of the API B2 The second line of code describes how to obtain the output parameter of the API B2 from the output parameter of the API B1 and the output parameter of the API
[0089] (3) The modification description for modifying the API C1 to the API C2 is as follows
[0090] Among them, Table 3 is an example of the function interface information of the APIs in the modification description for modifying the API C1 to the API C2 as shown in Table 3: C1 and the API C2 is as follows:
[0091] Table 3: Example of Modification Description
[0092] API API Name API Input Parameter Name API Output Parameter Name <![CDATA[API C1 > getAlpha1 c3 o5 <![CDATA[API C2 > getAlpha2 c4 o6
[0093] The associated information of the API C1 and the API C2 includes code 5 and code 6
[0094] The code 5 in the associated information of the APIs in the modification description C1 and the API C2 is as follows:
[0095] c3 == c4
[0096] c3 == c4 means that when the API C1 (i.e., getAlpha1) is modified to the API C2 (i.e., getAlpha2), the input parameters remain unchanged.
[0097] The relevant information about the API C1and API C2 The code 6 in the associated information is as follows:
[0098]
[0099] The first sentence of code 6 describes how to obtain the output parameter of API C1 from the output parameter of API C2 The second sentence of code 6 describes how to obtain the output parameter of API C2 from the output parameter of API C1
[0100] Step 220, the update device determines the relationship between the input parameter of the first API and the input parameter of the second API, and the relationship between the output parameter of the first API and the output parameter of the second API according to the description information.
[0101] Optionally, the update device may perform symbolic execution on the code in the description information to obtain the relationship between the input parameter of the first API and the input parameter of the second API, and the relationship between the output parameter of the first API and the output parameter of the second API.
[0102] Optionally, the relationship between the input parameter of the first API and the input parameter of the second API may be that the input parameter of the first API and the input parameter of the second API satisfy a first functional relationship, such as a first calculation formula for obtaining the input parameter of the second API using the input parameter of the first API. The relationship between the output parameter of the first API and the output parameter of the second API may be that the output parameter of the first API and the output parameter of the second API satisfy a second functional relationship, such as a second calculation formula for obtaining the output parameter of the second API using the output parameter of the first API and / or a third calculation formula for obtaining the output parameter of the first API using the output parameter of the second API.
[0103] For example, perform symbolic execution on code 1 (i.e., the associated information of API A1 modified to API A2 ) in the above modification description to obtain the relationship between the input parameter of API C1 and the input parameter of API C2 . The specific steps are as follows: Modify API A1 to API A1 A1 to API A2 In the modification instructions, the input parameters r, g, b, and a1 of the function rgb2hsl are set as abstract symbols, such as r = r0, g = g0, b = b0, a1 = a0. Substitute r = r0, g = g0, b = b0, a1 = a0 into the statements in the function rgb2hsl one by one for analysis. Since the first four statements assign the variables r, g, b, and a the values of "r / 255.0", "g / 255.0", "b / 255.0", and "a / 255.0" respectively, substituting the input parameters into these expressions, the calculation formulas for these variables are The next statement assigns the variable c_max the value of "max(r, g, b)". Substitute the variables r, g, b, and a0 obtained above into the expression, and the calculation formula for the variable c_max is After simplification, we get Substitute the variables r, g, b, and a0 obtained above into the expression, and we get The next statement is "c = c_max - c_min". Substitute c_max and c_min into the above expression to get
[0104] Since the next statement is a conditional branch statement, analyze each branch one by one. Since the constraint condition of the first branch is "c == 0", that is, max(r0, g0, b0) = min(r0, g0, b0), in this branch, h is assigned the value of 0 (when max(r0, g0, b0) = min(r0, g0, b0), h = 0). When the first branch condition is not satisfied (that is, max(r0, g0, b0) ≠ min(r0, g0, b0)), since the constraint condition for the second branch to be executed is "c_max == r", substituting it in we get max(r0, g0, b0) = r0. After this branch is executed, h is assigned the value of "(g - b) / c + 6 * (g < b)". Substitute the calculation formulas for the above variables g, b, and c into this expression, and the calculation formula for the h variable corresponding to this branch is After simplification, we get Perform similar processing for the remaining two branches. After analyzing the four conditional branches according to the above steps, the calculation formulas for the h variable under each branch are obtained. Table IV is shown as Table IV:
[0105] Table IV: Examples of calculation formulas for h under different conditional branches
[0106]
[0107] At this time, the next statement is "h = int(round(h * 60))", which assigns h the value of int(round(h * 60)). Substitute the h in Table 4 into the four branches respectively and simplify to obtain the corresponding h, as shown in Table 5:
[0108] Table 5: Examples of calculation formulas for h under different conditional branches
[0109]
[0110]
[0111] At this time, the API A2 's output parameter h is calculated from the input parameters of the API A1 . Perform symbolic execution on the remaining code according to the above steps to obtain the relationship between the input parameters of the API A1 and the input parameters of the API A2 . The relationship is as shown in calculation formula (1):
[0112]
[0113] Perform symbolic execution on code 2 in the above modification description of modifying the API A1 to API A2 to obtain the relationship between the output parameters of the API A1 and the output parameters of the API A1 , that is, o1 = o2.
[0114] Optionally, the relationship between the output parameters of the first API and the output parameters of the second API may include the monotonic property and injective property that the output parameters of the first API satisfy the second functional relationship. Assume that the second functional relationship is expressed as a calculation formula for converting the output parameters of the first API to the output parameters of the second API. At this time, if the output value A of the first API before conversion is less than the output value B of the first API, substituting the output value A of the first API into the second functional relationship gives a new output value A', and substituting the output value B of the first API into the second functional relationship gives a new output value B'. If the new output values satisfy A' < B' or A' > B', it means that the second functional relationship is monotonically increasing or decreasing; if the output value A of the first API before conversion is not equal to the output value B of the first API, and the new output values satisfy A' ≠ B', then the second functional relationship has the injective property. For example, perform symbolic execution on code 6 in the modification description of modifying the API C1 to API C2 to obtain the relationship between the output parameters of the API C1 and the output parameters of the API C2 , as shown in formula (2):
[0115]
[0116] o5 = round(255·o6)
[0117] It can be seen that and o5 = round(255·o6) are monotonically increasing and injective. Therefore, the API C1 output parameter and the API C2 conversion formula of the output parameter have the properties of monotonic increase and injectivity.
[0118] Step 230, the updating device determines at least one statement affected by the change of the first API in the test case of the code.
[0119] Exemplarily, the updating device can traverse the code of the original test case according to the name of the first API in the modification description, and judge one by one whether the first API is called. If it is called, the position of the call statement is recorded. For example, Table VI is an example of the original test case, as shown in Table VI:
[0120] Table VI: Example of the original test case
[0121]
[0122]
[0123] Statement L1 "let c = colorFactory1(0,255,0,255);" calls the API on the right side of the assignment A1 , API A1 with the name colorFactory1. Therefore, the code range affected by the change of colorFactory1 includes L1. Statement L2 "assertEqual(c.toHwbString1(),"hwb(120deg,0%,0%,100%)");" calls the API B1 , API B1 with the name toHwbString1. Therefore, the code range affected by the change of toHwbString1 includes L2. Statement L3 "assertTrue(c.getAlpha1() >= 0 && c.getAlpha1() <= 255);" calls the API C1 , API C1 with the name getAlpha1. Therefore, the code range affected by the change of getAlpha1 includes L3. Statement L4 "int a = c.getAlpha1() >> 8;" calls the API on the right side of the assignment C1, API C1 is named getAlpha1. Therefore, the code scope affected by the change of getAlpha1 includes L4 in addition to L3. The statement L5 "assertTrue(a == 0);" does not call any first API, so L5 is not affected and does not need to be modified. It can be seen that API C1 affects not only L3 but also L4. Among them, L3 is an assertion statement and L4 is an assignment statement. Since the semantics of the two statements are different, further analysis is required to improve the accuracy of automatic update of test cases. It should be noted that the number of codes and the involved APIs in the above original test cases are only examples.
[0124] Step 240, the update device modifies the first API in at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0125] The at least one statement determined by the update device according to the first API name includes an assignment statement and / or an assertion statement. The following will be described separately for different situations.
[0126] (1) The at least one statement includes a first statement, and the first statement is an assignment statement.
[0127] The update device modifies the first API in at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API. Figure 3 is the flowchart corresponding to the test case update method provided by the embodiment of the present application. As Figure 3 shown, the specific steps are as follows:
[0128] Step 2411, the update device obtains the input parameter value of the first API in the first statement and the return value of the first statement.
[0129] Exemplarily, the update device determines whether the first statement is an assignment statement. If the first statement is an assignment statement, the update device obtains the input parameter value of the first API in the first statement and the return value of the first statement. Taking the statements L1 and L4 involved in Table 6 above as an example, the statements L1 and L4 in Table 6 are assignment statements, and L1 and L4 are analyzed and described respectively. Table 7 is an example of the input parameters and return values of the first statement. As shown in Table 7, for the statement L1 "Color c = colorFactory1(0, 255, 0, 255)", the input parameters of L1 are r = 0, g = 255, b = 0, a1 = 255 at this time. Since the API name at this time is colorFactory1 corresponding to the API in Table 1A1 , therefore, the return value of statement L1 is o1. For statement L4 "int a = c.getAlpha1() >> 8", at this time the input parameter of L4 is c3 = c, and the return value of statement L4 is the result of arithmetic right shift by 8 bits of the output parameter o5 of getAlpha1 in Table 3 (i.e., ).
[0130] Table VII is an example of the input parameters and return values of the first statement
[0131]
[0132] By using the above steps, at least one statement affected by the change of the first API is analyzed, and information such as input parameters and return values in the original code is obtained, which helps the automatic update of subsequent test cases.
[0133] Step 2412, the updating device obtains the input parameter value of the second API according to the relationship between the input parameter of the first API and the input parameter of the second API, and the input parameter value of the first API in the first statement.
[0134] Exemplarily, the input parameter of the first API and the input parameter of the second API satisfy the first functional relationship. The updating device obtains the modified input parameter value (i.e., the input parameter value of the second API) according to the input parameter value of the first API in the first statement and the first functional relationship. The updating device can substitute the input parameter value of the first API in the first statement into the first functional relationship, and the output of the first functional relationship is the input parameter value of the second API. For example, Table VIII is an example of the modified input parameter value of the first statement. As shown in Table VIII, for statement L1, the first API is colorFactory1, the input parameter values are r = 0, g = 255, b = 0, a1 = 255, and the corresponding first functional relationship is formula (1). Substituting r = 0, g = 255, b = 0, a1 = 255 into formula (1) gives h = 120, s = 1.0, l = 0.5, a2 = 1.0 (i.e., the input parameter value of the second API of L1). For statement L4, the first API is getAlpha1, the input parameter value is c3 = c, and the corresponding first functional relationship is o4 = c3. Substituting c3 = c into the first functional relationship gives c4 = c (i.e., the input parameter value of the second API of L4).
[0135] Table VIII: Example of the modified input parameter value of the first statement
[0136]
[0137] Step 2413: The updating device obtains a new return value according to the relationship between the output parameters of the first API and the output parameters of the second API, and the return value of the first statement;
[0138] Exemplarily, the output parameters of the first API and the output parameters of the second API satisfy a second functional relationship. The updating device obtains a new return value according to the output parameters of the first API in the return value of the first statement and the second functional relationship. Among them, the second functional relationship can be a functional relationship for converting the output parameters of the second API into the output parameters of the first API. For example, a = f1(b), where b is the output parameter of the second API and a is the output parameter of the first API. The updating device can modify the output parameters of the first API in the first statement to the second functional relationship to obtain a new return value that includes the output parameters of the second API. For example, Table IX is an example of the new return value of the first statement. As shown in Table IX, for statement L1, the first API is colorFactory1 and the return value is o1. At this time, the corresponding second functional relationship is o1 = o2. Substituting o1 = o2 into the return value o1, the new return value o2 (i.e., the new return value of L1) is obtained. For statement L4, the first API is getAlpha1 and the return value is The corresponding second functional relationship is o5 = round(255·o6) in formula (2). Substituting o5 = round(255·o6) into the return value for o5, the new return value (i.e., the new return value of L4) is obtained.
[0139] Table IX: Example of the new return value of the first statement
[0140]
[0141] Step 2414: The updating device modifies the first API in the first statement to the second API according to the input parameter value of the second API and the new return value.
[0142] Exemplarily, after the update device modifies the return value in the first statement to a new return value, it substitutes the input parameter values of the second API into the input parameters of the second API to obtain the second API, and modifies the output parameter of the second API in the new return value to the second API. For example, Table X shows examples before and after the modification of the assignment statement in the original test case. As shown in Table X, for the modification of the statement L1 "Color c = colorFactory1(0, 255, 0, 255)", the new return value o2 corresponding to colorFactory1 in Table IX is used to replace the return value part "colorFactory1(0, 255, 0, 255)" in L1, resulting in the intermediate result "Color c = o2". The modified parameter values obtained in Table VIII (i.e., the input parameter values corresponding to the second API) h = 120, s = 1.0, l = 0.5, a2 = 1.0 are substituted into the input parameters of the second API to obtain colorFactory2(120, 1.0, 0.5, 1.0). The output parameter o2 of the second API in "Color c = o2" is modified to colorFactory2(120, 1.0, 0.5, 1.0) to obtain the result after the modification of statement L1. The modified statement of L1 is "Color c = colorFactory2(120, 1.0, 0.5, 1.0)". For the modification of the statement L4 "int a = c.getAlpha1() >> 8", the new return value corresponding to getAlpha1 in Table IX is used to replace the return value part "c.getAlpha1() >> 8" in statement L4, resulting in the intermediate result "int a = int(round(255·o6)) / 256". The modified parameter values obtained in Table VIII (the input parameter values of the second API) c4 = c are substituted into the input parameters of the second API to obtain c.getAlpha2(). The output parameter o6 of the second API in "int a = int(round(255·o6)) / 256" is modified to c.getAlpha2() to obtain the result after the modification of statement L4. The modified statement of L4 is "int a = int(round(255·c.getAlpha2())) / 256".
[0143] Table X: Examples before and after the modification of the assignment statement
[0144]
[0145] (2) At least one statement includes a second statement, and the second statement is an assignment statement.
[0146] The updating device modifies the first API in at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API. Figure 4 is the flowchart corresponding to the test case updating method provided in the embodiments of this application, as Figure 4 shown, the specific steps are as follows:
[0147] Step 2421, the updating device obtains the input parameter values of the first API in the second statement and the assertion logic of the second statement.
[0148] Exemplarily, the updating device determines whether the second statement is an assertion statement. If the second statement is an assertion statement, the updating device obtains the input parameter values of the first API in the second statement and the assertion logic of the second statement. Taking the statements L2 and L3 involved in Table VI above as an example, L2 and L3 in Table VI are assertion statements, and the statements L2 and L3 are respectively analyzed and explained. Table XI is an example of the output parameters and assertion logic of the second statement. As shown in Table XI, for the statement L2 "assertEqual(c.toHwbString1(), \"hwb(120deg,0%,0%,100%)\")", the first API involved in the statement L2 is toHwbString1, the input parameter for calling toHwbString1 is c1 = c, and the return value of c.toHwbString1 is o3. Since the statement L2 is an assertion statement, the first parameter in the assertion statement is the call to toHwbString1, and the second parameter is the string constant \"hwb(120deg,0%,0%,100%)\". Therefore, the assertion logic of this statement is to determine that \"o3 is equal to \"hwb(120deg,0%,0%,100%) \". For the statement L3 \"assertTrue(c.getAlpha1() >= 0 && c.getAlpha1() <= 255)\", the first API involved in the statement L3 is getAlpha1, the input parameter for calling getAlpha1 is c3 = c, and the return value of c.getAlpha1 is o5. The statement L3 is an assertion statement. Since the assertion has only one boolean expression as a parameter, the assertion logic of L3 is to determine that \"o5 >= 0 && o5 <= 255 is true\", and further simplified to get \"0 ≤ o5 ≤ 255\".
[0149] Table XI is an example of the input parameters and assertion logic of the second statement
[0150]
[0151] Step 2422: The updating device obtains the input parameter values of the second API based on the relationship between the input parameter values of the first API and the second API, and the input parameter values of the first API in the second statement.
[0152] Exemplarily, the input parameters of the first API and the input parameters of the second API satisfy a first functional relationship. The updating device obtains the modified input parameter values (i.e., the input parameter values of the second API) based on the input parameter values of the first API in the second statement and the first functional relationship. The updating device can substitute the input parameter values of the first API in the second statement into the first functional relationship, and the output of the first functional relationship is the input parameter values of the second API. For example, Table XII is an example of the input parameter values after the modification of the second statement. As shown in Table XII, for statement L2, the first API is toHwbString1, and the input parameter value is c1 = c. According to the relationship between the input parameters of toHwbString1 and toHwbString2: c2 = c1, substituting c1 = c into c1 in c2 = c1, we get c2 = c (i.e., the input parameter values of the second API in L2). For statement L3, at this time the first API is getAlpha1, and the input parameter value is c3 = c. According to the relationship between the input parameters of getAlpha1 and getAlpha2: c4 = c3, substituting c3 = c into c3 in c4 = c3, we get c4 = c (i.e., the input parameter values of the second API in L3).
[0153] Table XII: Example of the input parameter values after the modification of the second statement
[0154]
[0155] Step 2423: The updating device obtains a new assertion logic based on the relationship between the output parameters of the first API and the output parameters of the second API, and the assertion logic of the second statement.
[0156] Exemplarily, the output parameter of the first API and the output parameter of the second API satisfy a third functional relationship. The updating device obtains a new assertion logic based on the output parameter of the first API in the assertion logic of the second statement and the third functional relationship. Among them, the third functional relationship can be a functional relationship that converts the output parameter of the first API into the output parameter of the second API. For example, a′ = f2(b′), where b' is the output parameter of the first API and a' is the output parameter of the second API. The updating device can substitute the value in the assertion statement of the second statement into the third functional relationship to obtain a new assertion logic. For example, Table XIII is an example of the new assertion logic of the second statement. As shown in Table XIII, for statement L2, the first API is toHwbString 1, and the assertion logic is that o3 is equal to "hwb(120deg,0%,0%,100%)". At this time, the corresponding third functional relationship is o4 = o3.split(",")[:-1].join("") + " / " + o3.split(",")[-1]. Substitute "hwb(120deg,0%,0%,100%)" into o3 in the third functional relationship, and the right side of the equal sign simplifies to "hwb(120deg 0%0% / 100%)". At this time, the new assertion logic is that o4 is equal to "hwb(120deg 0%0% / 100%)". For statement L3, the first API is getAlpha, and the assertion logic is 0 ≤ o5 ≤ 255. At this time, the corresponding third functional relationship is Substitute "0" and "255" into o5 in the third functional relationship to obtain new results "0" and "1". Since has the property of monotonically increasing, there is no need to change the comparison direction in the original assertion logic. Since has the property of injection, when the return value of the first API is not equal to the original expected result, the new return value is also not equal to the new expected result. Therefore, the new assertion logic of statement L3 is 0 ≤ o6 ≤ 1.
[0157] Table XIII: Example of the new assertion logic of the second statement
[0158]
[0159] Step 2424, the updating device modifies the first API in the second statement to the second API according to the input parameter value of the second API and the new assertion logic.
[0160] Exemplarily, the update device modifies the assertion logic in the second statement to new assertion logic, substitutes the input parameter values of the second API into the input parameters of the second API to obtain the second AIP, and modifies the output parameter of the second API in the new assertion logic to the second API. For example, Table XIV shows examples of the assertion statements in the original test case before and after modification. As shown in Table XIV, for the modification of statement L2 "assertEqual(c.toHwbString1(), \"hwb(120deg,0%,0%,100%)\")", the new assertion logic in Table XIII is used to replace the original assertion logic in L2, resulting in an intermediate result of "assertTrue(o4 == \"hwb(120deg 0%0% / 100%)\")". The modified input parameter value "c2 = c" obtained from Table XII is substituted into the second API (toHwbString) to obtain c.toHwbString2(), and c.toHwbString2() is used to replace the output parameter of the second API in the intermediate result, resulting in the modified result of L2. The modified statement of L2 is "assertTrue(c.toHwbString2() == \"hwb(120deg 0%0% / 100%)\")". For the modification of statement L3 "assertTrue(c.getAlpha1() >= 0 && c.getAlpha1() <= 255)", the new assertion logic in Table XIII is used to replace the original assertion logic in L3, resulting in an intermediate result of "assertTrue(o6 >= 0.0 && o6 <= 1.0)". The input parameter value "c4 = c" obtained from Table XII is substituted into the second API (getAlpha2) to obtain c.getAlpha2(), and c.getAlpha2() is used to replace the output parameter of the second API in the intermediate result, resulting in the modified result of statement L3. The modified statement of L3 is "assertTrue(c.getAlpha2() >= 0.0 && c.getAlpha2() <= 1.0)".
[0161] Table XIV shows examples of the assertion statements in the original test case before and after modification
[0162]
[0163] Using the above method, when the code is modified, the original test cases become invalid. At this time, by obtaining the description information of modifying the first application programming interface (API) in the code to the second API, and analyzing according to the obtained description information, the relationships between the input parameters of the first API and the second API, and between the output parameters of the first API and the second API are obtained. The relationships between the input parameters of the first API and the second API, and between the output parameters of the first API and the second API accurately describe the conversion rules between the first API and the second API. By deeply analyzing the semantics of the code, rather than simply performing string matching and replacement, the code in the test cases affected by the change of the first API is automatically updated. The updated test cases are not only correct in syntax and semantics, but also conform to the syntax of the modified API and can pass compilation. The new test cases can be consistent with the original test logic, improving the efficiency of automatic update of test cases. In addition, the solution provided in this application can effectively address the problem of test case update caused by code modification, improve the test efficiency and quality, without the need for manual understanding of the modification logic and rewriting of test cases, realizing the automatic update of test cases and saving human resources.
[0164] Figure 5 Another flowchart corresponding to the test case update method provided by the embodiment of this application is shown as Figure 5 shown, and this process includes:
[0165] S1, the update device obtains the modification description of modifying the first API in the code to the second API.
[0166] S2, the update device performs symbolic execution on the code in the modification description to obtain the relationship between the first API and the second API. Among them, the relationship between the first API and the second API includes at least one of the following: the calculation formula for expressing the second API using the first API, and the calculation formula for expressing the first API using the second API.
[0167] S3, the update device traverses the first API in the original test case code.
[0168] S4, the update device performs static analysis on the original test case code and locates at least one statement affected by the change of the first API in the original test case code.
[0169] S5, the update device analyzes the original test logic such as assertion logic, input parameters, and return values in at least one statement affected by the first API.
[0170] S6, the update device calculates the modified test logic according to the relationship between the first API and the second API obtained from the modification description and the original test logic.
[0171] In S7, the updating device modifies the statements in the test case code affected by the first API to obtain modified test statements.
[0172] In S8, the updating device repeatedly executes S4 - S7 for other modified APIs involved in the original test case to obtain modified test statements corresponding to each modified API, and uses the modified tests to replace the corresponding statements in the original test case to obtain new test case code.
[0173] Based on the same inventive concept, an embodiment of the present invention further provides an updating device 6000 for test cases. Figure 6 It is a schematic diagram of the updating device for test cases provided by the embodiment of the present invention, as Figure 6 shown, the device includes:
[0174] An obtaining unit 601, configured to obtain description information for modifying a first application programming interface (API) in the code to a second API.
[0175] A determining unit 602, configured to determine the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API according to the description information; and determine at least one statement affected by the change of the first API in the test case of the code.
[0176] A processing unit 603, configured to modify the first API in the at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0177] In an optional implementation manner, the determining unit 602 is specifically configured to perform symbolic execution on the description information to obtain the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
[0178] In an alternative embodiment, the at least one statement includes a first statement, and the first statement is an assignment statement; specifically, the processing unit 603 is configured to obtain the input parameter values of the first API in the first statement and the return value of the first statement; obtain the input parameter values of the second API according to the relationship between the input parameters of the first API and the input parameters of the second API and the input parameter values of the first API in the first statement; obtain a new return value according to the relationship between the output parameters of the first API and the output parameters of the second API and the return value of the first statement; and modify the first API in the first statement to the second API according to the input parameter values of the second API and the new return value.
[0179] In an alternative embodiment, the relationship between the input parameters of the first API and the input parameters of the second API is that the input parameters of the first API and the input parameters of the second API satisfy a first functional relationship; the processing unit 603 is configured to obtain the input parameter values of the second API according to the input parameter values of the first API in the first statement and the first functional relationship.
[0180] In an alternative embodiment, the relationship between the output parameters of the first API and the output parameters of the second API is that the output parameters of the first API and the output parameters of the second API satisfy a second functional relationship; the processing unit 603 is configured to obtain a new return value according to the output parameters of the first API in the return value of the first statement and the second functional relationship.
[0181] In an alternative embodiment, the processing unit 603 is configured to modify the return value in the first statement to the new return value; substitute the input parameter values of the second API into the input parameters of the second API to obtain the second API, and modify the output parameters of the second API in the new return value to the second API.
[0182] In an alternative embodiment, the at least one statement includes a second statement, and the second statement is an assertion statement; specifically, the processing unit 603 is configured to obtain the input parameter values of the first API in the second statement and the assertion logic of the second statement; obtain the input parameter values of the second API according to the relationship between the input parameters of the first API and the input parameters of the second API and the input parameter values of the first API in the second statement; obtain a new assertion logic according to the relationship between the output parameters of the first API and the output parameters of the second API and the assertion logic of the second statement; and modify the first API in the second statement to the second API according to the input parameter values of the second API and the new assertion logic.
[0183] In an alternative embodiment, the processing unit 603 is configured to modify the assertion logic in the second statement to a new assertion logic; substitute the input parameter values of the second API into the input parameters of the second API to obtain the second API, and modify the return value of the second API in the new assertion logic to the second API.
[0184] Based on the same concept, an embodiment of the present application further provides a structural schematic diagram of a test case update device, as Figure 7 shown. The device 7000 includes at least one processor 701 and a memory 702 connected to the at least one processor 701. In the embodiment of the present application, the specific connection medium between the processor 701 and the memory 702 is not limited. Figure 7 Taking the connection between the processor 701 and the memory 702 through a bus as an example. The bus can be divided into an address bus, a data bus, a control bus, etc. In the embodiment of the present application, the memory 702 stores instructions executable by the at least one processor 701, and the at least one processor 701 can implement the steps of the above test case update method by executing the instructions stored in the memory 702.
[0185] Among them, the processor 701 is the control center of the computer device. It can connect various parts of the computer device through various interfaces and circuits. By running or executing the instructions stored in the memory 702 and invoking the data stored in the memory 702, resource settings can be performed. Optionally, the processor 701 may include one or more processing units. The processor 701 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 701. In some embodiments, the processor 701 and the memory 702 may be implemented on the same chip. In some embodiments, they may also be separately implemented on independent chips.
[0186] The processor 701 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application specific integrated circuit (ASIC), a field programmable gate array, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application may be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
[0187] The memory 702 serves as a non-volatile computer-readable storage medium and can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The memory 702 can include at least one type of storage medium. For example, it can include flash memory, hard disks, multimedia cards, card-type memories, random access memory (RAM), static random access memory (SRAM), programmable read only memory (PROM), read only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic memories, magnetic disks, optical disks, and so on. The memory 702 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 702 in the embodiments of the present application can also be a circuit or any other device capable of implementing a storage function for storing program instructions and / or data.
[0188] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium. The computer program product includes: computer program code, which when run on a computer, causes the computer to execute the update method of any of the test cases discussed above. Since the principle of the above computer-readable storage medium for solving the problem is similar to that of the update method of the test case, the implementation of the above computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be elaborated.
[0189] Based on the same inventive concept, an embodiment of the present application also provides a computer program product. The computer program product includes: computer program code, which when run on a computer, causes the computer to execute the update method of any of the test cases discussed above. Since the principle of the above computer program product for solving the problem is similar to that of the update method of the test case, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be elaborated.
[0190] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.
[0191] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to the application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0192] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0193] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or multiple blocks.
[0194] Obviously, those skilled in the art can make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these changes and modifications.
Claims
1. A method for updating a test case, characterized in that: The method comprises: Obtaining description information for modifying a first application program interface API in the code to a second API; Determine, according to the description information, a relationship between an input parameter of the first API and an input parameter of the second API, and a relationship between an output parameter of the first API and an output parameter of the second API; Determining, in a test case of the code, at least one statement affected by the first API change; The first API in the at least one statement is modified to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
2. The method according to claim 1, characterized in that Determining, according to the description information, a relationship between an input parameter of the first API and an input parameter of the second API, and a relationship between an output parameter of the first API and an output parameter of the second API, including: Symbolic execution is performed on the description information to obtain a relationship between input parameters of the first API and input parameters of the second API, and a relationship between output parameters of the first API and output parameters of the second API.
3. The method according to claim 1, characterized in that The at least one statement includes a first statement, wherein the first statement is an assignment statement; According to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API, modifying the first API in the at least one statement to the second API includes: Obtaining input parameter values of the first API in the first statement and a return value of the first statement; Obtaining input parameter values of the second API according to a relationship between input parameters of the first API and input parameters of the second API and input parameter values of the first API in the first statement; Obtaining a new return value according to the relationship between the output parameters of the first API and the output parameters of the second API and the return value of the first statement; According to the input parameter values of the second API and the new return value, the first API in the first statement is modified to the second API.
4. The method according to claim 3, characterized in that The relationship between the input parameters of the first API and the input parameters of the second API is: the input parameters of the first API and the input parameters of the second API satisfy a first functional relationship; Obtaining the input parameter value of the second API according to the relationship between the input parameter of the first API and the input parameter of the second API and the input parameter value of the first API in the first statement, including: According to the input parameter values of the first API in the first statement and the first functional relationship, the input parameter values of the second API are obtained.
5. The method according to claim 3, characterized in that: The relationship between the output parameter of the first API and the output parameter of the second API is: the output parameter of the first API and the output parameter of the second API satisfy a second functional relationship; Obtaining a new return value according to the relationship between the output parameter of the first API and the output parameter of the second API and the return value of the first statement, including: A new return value is obtained according to the output parameter of the first API in the return value of the first statement and the second function relationship.
6. The method according to claim 3, characterized in that According to the input parameter value of the second API and the new return value, modifying the first API in the first statement to the second API includes: Modify the return value in the first statement to the new return value; Substitute the input parameter value of the second API into the input parameter of the second API to obtain the second API, and modify the output parameter of the second API in the new return value to the second API.
7. The method according to claim 1, characterized in that The at least one statement includes a second statement, the second statement being an assertion statement; According to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API, modifying the first API in the at least one statement to the second API includes: Obtaining input parameter values of the first API and assertion logic of the second statement in the second statement; Obtaining input parameter values of the second API according to a relationship between input parameters of the first API and input parameters of the second API and input parameter values of the first API in the second statement; Obtaining new assertion logic according to the relationship between the output parameters of the first API and the output parameters of the second API and the assertion logic of the second statement; According to the input parameter value of the second API and the new assertion logic, the first API in the second statement is modified to the second API.
8. The method according to claim 7, characterized in that According to the input parameter value of the second API and the new assertion logic, modifying the first API in the second statement to the second API includes: Modify the assertion logic in the second statement to a new assertion logic; Substitute the input parameter value of the second API into the input parameter of the second API to obtain the second API, and modify the return value of the second API in the new assertion logic to the second API.
9. A test case updating device, characterized in that: The device comprises: An acquisition unit, used for acquiring description information for modifying a first application program interface API in a code into a second API; a determining unit, configured to determine, according to the description information, a relationship between an input parameter of the first API and an input parameter of the second API, and a relationship between an output parameter of the first API and an output parameter of the second API; and to determine at least one statement affected by a change of the first API in a test case of the code; A processing unit is used to modify the first API in the at least one statement to the second API according to the relationship between the input parameters of the first API and the input parameters of the second API, and the relationship between the output parameters of the first API and the output parameters of the second API.
10. A test case updating device, characterized in that: The device comprises: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute the steps included in any one of the methods of claims 1-8 according to the obtained program instructions.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a computer, the method according to any one of claims 1 to 8 is executed.
12. A computer program product, characterized in that The computer program product comprises a computer program code, which causes any one of claims 1 to 8 to be performed when the computer program code is run on a computer.