Method, apparatus, computing device, and storage medium for determining a test template
By obtaining the attribute information of the code to be tested, determining the test template and generating test cases, the problem of long-term writing of test cases in the prior art is solved, and more efficient test case acquisition and automated testing are achieved.
Patent Information
- Application Number
- CN202011026923.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-25
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2040-09-25
AI Technical Summary
In the prior art, it takes a lot of time to write test cases, resulting in low efficiency in obtaining test cases.
By obtaining the attribute information of the code to be tested, including technical attributes and business attributes, determining the corresponding test template, and generating test cases based on known test cases, reducing the steps of manual writing.
It improves the efficiency of obtaining test cases, reduces the time to manually write test cases, and improves the degree of automation of the test process.
Smart Images

Figure CN114253828B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to a method, apparatus, computing device, and storage medium for determining a test template. Background Art
[0002] During software development, testing is a critical step and a crucial process for ensuring software quality. Testing can include unit testing and integration testing. Unit testing ensures that the units under test in a software product function properly. The code under test is typically a class or method. Integration testing tests modules composed of multiple classes.
[0003] In the related art, when testing a code to be tested, a user writes a test case for the code to be tested, and then uses the test case to test the code to be tested. Since the test case is written manually in the related art, it takes a lot of time to obtain the test case. Summary of the Invention
[0004] The present application provides a method, apparatus, computing device, and storage medium for determining a test template, so as to solve the problem that test case writing takes a long time.
[0005] In the first aspect, the present application provides a method for determining a test template, the method comprising: obtaining attribute information of the code to be tested, wherein the attribute information includes technical attributes and business attributes; determining a test template corresponding to the code to be tested based on the attribute information of the code to be tested, the test template being obtained based on multiple known test cases, and the test template being used to generate test cases corresponding to the code to be tested.
[0006] In the solution shown in the present application, the method for determining the test template can be executed by a determination device. When determining the test case of the code to be tested, the determination device can obtain the attribute information of the code to be tested, and the attribute information includes technical attributes and business attributes. The determination device determines the test template corresponding to the code to be tested based on the attribute information of the code to be tested, and the test template is used to generate the test case corresponding to the code to be tested. In this way, since the test case can be obtained based on the test template without the need to write the entire content of the test case, the efficiency of obtaining the test case is improved.
[0007] In one possible implementation, the method further includes: adjusting the test template according to the context information of the code to be tested to obtain a test case for the code to be tested; providing the test case for the code to be tested to the user, or, testing the code to be tested according to the test case of the code to be tested, and providing the test result of the code to be tested to the user.
[0008] The context information of the code to be tested may include context information of the code to be tested in the software to which it belongs and context information within the code to be tested.
[0009] In the solution shown in the present application, the determination device can obtain the context information of the code to be tested, use the context information to adjust the test template, and obtain the test case corresponding to the code to be tested. The determination device then provides the test case to the user. If the determination device has a display function, the determination device displays the test case, and the user can see the test case on the screen of the determination device. Alternatively, after obtaining the test case, the determination device can test the code to be tested based on the test case, obtain the test result of the test of the code to be tested, and then provide the test result to the user. In this way, not only can the test case be written automatically, but the user can also understand in a timely manner whether the code to be tested can operate normally.
[0010] In one possible implementation, business attributes are used to indicate the functions implemented or services completed by the code under test, while technical attributes are used to indicate the programming technology information of the code under test, which may include programming language, technology stack, etc.
[0011] In one possible implementation, the method further includes: providing a test template corresponding to the code to be tested to the user; obtaining the test template after the user modifies the test template corresponding to the code to be tested; generating a test case for the code to be tested based on the modified test template, and testing the code to be tested based on the test case of the code to be tested; or, obtaining a test template confirmed by the user in the test template corresponding to the code to be tested; generating a test case for the code to be tested based on the confirmed test template, and testing the code to be tested based on the test case of the code to be tested.
[0012] The solution shown in the present application is that after the determination device obtains the test template corresponding to the code to be tested, it can provide the test template to the user, and the user can modify the test template and then submit the modified test template. The determination device uses the modified test template as a test case for the template to be tested, and uses the test case to test the code to be tested. Alternatively, after the determination device obtains the test template corresponding to the code to be tested, it can provide the test template to the user, and the user can confirm the test template. The determination device uses the confirmed test template as a test case for the template to be tested, and uses the test case to test the code to be tested. In this way, the test template can be provided to the user, making the use of the test template more flexible.
[0013] In one possible implementation, a test template corresponding to the code to be tested is determined based on the attribute information of the code to be tested, including: querying a test template library based on the attribute information of the code to be tested; and obtaining a test template corresponding to attribute information in the test template library whose similarity with the attribute information of the code to be tested meets preset conditions.
[0014] In the solution shown in the present application, a test template library is stored in the determination device, or a test template library is stored in another device that has established a communication connection with the determination device. The determination device can obtain a test template corresponding to attribute information whose similarity to the attribute information of the code to be tested meets a preset condition from the test template library stored in itself. Alternatively, the determination device can obtain a test template corresponding to attribute information whose similarity to the attribute information of the code to be tested meets a preset condition from the other device. In this way, since the test template can be obtained based on the attribute information of the code to be tested, an accurate test template can be obtained.
[0015] In a possible implementation, the test template library includes a test template corresponding to each attribute information.
[0016] In a possible implementation, the test template library is constructed based on attribute information of multiple codes and corresponding test cases, wherein the multiple codes are existing tested codes.
[0017] In one possible implementation, before building the test template library, the method further includes filtering invalid test cases among the test cases corresponding to the multiple codes. In this way, test cases that cannot be used to determine the test template can be pre-screened, making the obtained test template more accurate.
[0018] On the second aspect, the present application provides a device for determining test cases, which includes: an acquisition module for acquiring attribute information of the code to be tested, wherein the attribute information includes technical attributes and business attributes; a determination module for determining the test template corresponding to the code to be tested based on the attribute information of the code to be tested, wherein the test template is obtained based on multiple known test cases, and the test template is used to generate the test case corresponding to the code to be tested. In this way, since the test template can be obtained based on multiple known test cases, and the test template is matched with the attribute information, the attribute information of the code to be tested can be used to determine the test template of the code to be tested, and the test case can be obtained directly based on the test template without writing the entire content of the test case, thereby improving the efficiency of obtaining the test case.
[0019] In one possible implementation, the determination module is further used to adjust the test template according to the context information of the code to be tested to obtain a test case for the code to be tested; the device also includes: a providing module for providing the user with a test case for the code to be tested, or a testing module for testing the code to be tested according to the test case of the code to be tested, and a providing module for providing the user with a test result of the code to be tested.
[0020] In a possible implementation, the business attribute is used to indicate the function implemented or the business completed by the code to be tested; and the technical attribute is used to indicate the programming technical information of the code to be tested.
[0021] In one possible implementation, the device further includes: a providing module for providing the user with a test template corresponding to the code to be tested; the acquiring module is further used to acquire the test template after the user modifies the test template corresponding to the code to be tested; the determining module is further used to generate a test case for the code to be tested based on the modified test template; the device further includes a testing module for testing the code to be tested based on the test case of the code to be tested; or, the acquiring module is further used to acquire the test template confirmed by the user in the test template corresponding to the code to be tested; the determining module is further used to generate a test case for the code to be tested based on the confirmed test template; the device further includes a testing module for testing the code to be tested based on the test case of the code to be tested.
[0022] In a possible implementation, the determination module is configured to: query a test template library based on the attribute information of the code to be tested; and obtain a test template corresponding to attribute information whose similarity to the attribute information of the code to be tested meets a preset condition in the test template library.
[0023] In a possible implementation, the test template library includes a test template corresponding to each attribute information.
[0024] In a possible implementation, the test template library is constructed based on attribute information of multiple codes and corresponding test cases.
[0025] In a possible implementation, the device further includes: a filtering module configured to filter invalid test cases among the test cases corresponding to the multiple codes before building the test template library.
[0026] In a third aspect, the present application provides a computing device comprising a processor and a memory, wherein: the memory stores computer instructions, and the processor executes the computer instructions to implement the method of the first aspect and its possible implementation methods.
[0027] In a fourth aspect, the present application provides a computer-readable storage medium storing computer instructions. When the computer instructions in the computer-readable storage medium are executed by a computing device, the computing device executes the method of the first aspect and its possible implementation methods, or the computing device implements the functions of the apparatus of the above-mentioned second aspect and its possible implementation methods.
[0028] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device, enables the computing device to execute the method of the above-mentioned first aspect and its possible implementation, or enables the computing device to implement the functions of the apparatus of the above-mentioned second aspect and its possible implementation. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is a system architecture diagram for determining a test template provided by an exemplary embodiment of the present application;
[0030] Figure 2 This is a system architecture diagram for determining a test template provided by an exemplary embodiment of the present application;
[0031] Figure 3 is a flowchart of a method for determining a test template provided by an exemplary embodiment of the present application;
[0032] Figure 4 This is an example diagram of obtaining a test template provided by an exemplary embodiment of the present application;
[0033] Figure 5 This is a flowchart of building a test template library provided by an exemplary embodiment of the present application;
[0034] Figure 6 is a schematic diagram of filtering invalid test cases provided by an exemplary embodiment of the present application;
[0035] Figure 7 is a schematic diagram of dividing test cases provided by an exemplary embodiment of the present application;
[0036] Figure 8 is a schematic diagram of generating a test template provided by an exemplary embodiment of the present application;
[0037] Figure 9 is a system flow chart for determining test cases provided by an exemplary embodiment of the present application;
[0038] Figure 10 is a structural diagram of an apparatus for determining a test template provided by an exemplary embodiment of the present application;
[0039] Figure 11is a structural diagram of an apparatus for determining a test template provided by an exemplary embodiment of the present application;
[0040] Figure 12 is a structural diagram of an apparatus for determining a test template provided by an exemplary embodiment of the present application;
[0041] Figure 13 It is a structural diagram of a computing device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0043] To facilitate understanding of the embodiments of this application, the following first introduces the concepts of the terms involved:
[0044] 1. Testing is a key step in the software development process and can include unit testing and integration testing. Unit testing aims to ensure that the test units within the software are functioning properly. Unit testing is generally performed at the method or class level. Integration testing involves testing a test module composed of multiple classes or methods as a whole.
[0045] 2. A test case is a piece of code used to test the code to be tested. By running the test case, the process logic and results of the code to be tested can be tested, and potential problems in the code to be tested can be discovered.
[0046] 3. Test templates are test frameworks that generate test cases based on multiple known test cases. Test templates are used to generate test cases. For example, you can generate test cases for the code to be tested based on the test template corresponding to the code to be tested.
[0047] Testing is a key step in the software development process, and test cases are essential tools for this process, making the writing of test cases crucial. However, in related art, users typically write test cases for the code to be tested, and then use the written test cases to test the code to be tested. In this embodiment, the user refers to the software developer. Because a software program often requires testing many areas, writing a separate test case for each area results in inefficient test case acquisition.
[0048] Before introducing the method for determining the test template in this application, the application scenario and execution subject of the embodiment of this application are first introduced:
[0049] The method for determining the test template in the embodiment of the present application can be applied before testing the code to be tested. The device for determining the test template (hereinafter referred to as the determination device) can be a hardware device. Specifically, Figure 1 As shown, the determination device can be a hardware device anywhere that runs the method code for determining the test template, such as a cloud device, an edge device, a terminal device, or other computing device. The hardware device and the integrated development environment (IDE) tool may not be on the same computing device. The user writes the code to be tested through the IDE and communicates with the determination device through the IDE.
[0050] The determining device may also be a software device. Specifically, Figure 2 As shown, the determination device can be a plug-in for an IDE tool, or a virtual machine that runs the method code for determining the test template. The IDE can be a cloud-based IDE or a client-based IDE. In addition, the determination device can also be independent software or a software cloud service.
[0051] The following will be combined Figure 3 The method for determining a test template provided in an embodiment of the present application is described, and the method can be executed by a determination device. Figure 3 As shown, the processing flow of this method is as follows:
[0052] Step 301: The determination device obtains attribute information of the code to be tested, wherein the attribute information includes technical attributes and business attributes.
[0053] The code to be tested is the code to be tested. It can be a test unit or a test module, where a module consists of multiple units. Specifically, if the code to be tested is a test unit, the unit is tested to implement unit testing; if the code to be tested is a test module, the module is tested to implement integration testing.
[0054] In this embodiment, the determination device can obtain the code to be tested written by the user, analyze the code to be tested, and obtain the attribute information of the code to be tested, which includes technical attributes and business attributes. Specifically, the code to be tested can be analyzed to obtain each word in the code to be tested, and then a preset number of words with the highest frequency of occurrence among the words can be determined. The preset number of words (also referred to as keywords) are determined as the business attributes of the code to be tested, and the preset number here can be preset, such as a preset number equal to 5, etc. The code to be tested can then be analyzed to obtain the programming language, technology stack, etc. used by the code to be tested. The programming language, technology stack, etc. are determined as the technical attributes of the code to be tested. The programming language here refers to the language used to write the code to be tested, such as C++, java, python, etc. The technology stack generally refers to a variety of technologies used to write the code to be tested.
[0055] Alternatively, the determining device may provide the code to be tested to an attribute information determining device, and obtain the attribute information of the code to be tested from the attribute information determining device.
[0056] Alternatively, if the determining device is a software device and is not installed on the terminal where the user writes the code to be tested, or if it is a hardware device and is not the same device as the terminal where the user writes the code to be tested, after the user writes the code to be tested, the terminal can determine the attribute information of the code to be tested. The terminal then submits the attribute information of the code to be tested to the determining device. Here, the terminal determines the attribute information of the code to be tested in the same manner as the determining device determines the attribute information of the test code.
[0057] In this way, the determining device can obtain the attribute information of the code to be tested.
[0058] Optionally, business attributes include a preset number of words that appear most frequently in the code under test. Since these words are keywords in the code under test, they generally refer to method names or function names in the code under test. Business attributes can be used to indicate the functionality implemented or the business performed by the code under test. Technical attributes include programming language and technology stack. Technical attributes indicate the technical aspects used during coding, that is, technical attributes are used to indicate the programming technology information of the code under test.
[0059] Step 302: The determining device determines a test template corresponding to the code to be tested based on the attribute information of the code to be tested. The test template is obtained based on multiple known test cases and is used to generate a test case corresponding to the code to be tested.
[0060] The test template is obtained based on a known test case, which is a test case that has been used to test the test code. The test template can be considered as a framework of the test case, or the test case itself.
[0061] In this embodiment, after obtaining the attribute information of the code to be tested, the determination device can use the attribute information of the code to be tested to determine the test template corresponding to the attribute information, and determine the test template as the test template corresponding to the code to be tested. The test template can be used to generate a test case corresponding to the code to be tested.
[0062] In this way, since the attribute information of the code to be tested can be used to directly determine the test template corresponding to the code to be tested, and test cases can be obtained based on the test template, users do not need to write test cases for the code to be tested, so the efficiency of obtaining test cases can be improved.
[0063] Optionally, since the test template corresponding to the attribute information of the code to be tested may not be adapted to the code to be tested in terms of syntax and other aspects, the test template corresponding to the attribute information of the code to be tested can be automatically adjusted to obtain a test case. The processing process can be:
[0064] In step 303, the determination device adjusts the test template according to the context information of the code to be tested to obtain a test case for the code to be tested; provides the test case for the code to be tested to the user, or tests the code to be tested according to the test case and provides the user with a test result of the code to be tested.
[0065] The context information of the code to be tested may include context information of the code to be tested in the software to which it belongs and context information within the code to be tested. Specifically, the context information of the code to be tested may include one or more of the called interface, data structure, and code logic.
[0066] In this embodiment, the determination device adjusts the test template based on the context information of the code under test. Specifically, the data structure in the context information can be used to adjust the structure of the input data in the test template, so that the input data in the test case meets the requirements. The call interface in the context information can be used to correct the call statement of the method in the code under test, and the code logic in the context information can be used to correct the variable name in the test template and supplement the missing statement. Based on these processing, the generated test case is made to conform to the code under test.
[0067] After obtaining the test case of the code to be tested, the determination device can automatically run the test case, test the code to be tested, obtain the test result, and provide the test result to the user.
[0068] Alternatively, after obtaining the test case for the code to be tested, the determination device may obtain multiple test cases, or the obtained test case may not be accurately used to test the code to be tested. Alternatively, if the user wishes to download the test case and test it elsewhere, the determination device may provide the user with the test case for the code to be tested. For example, if the determination device does not have a display function, the determination device may provide the test case to the terminal used by the user. The user may manually modify the test case. After the user has modified the test case, the user may submit the modified test case to the determination device. The determination device runs the modified test case to test the code to be tested. Alternatively, if the user is certain that the test case for the code to be tested is correct, the user may select a test case and submit it to the determination device. The determination device runs the test case submitted by the user to test the code to be tested. Alternatively, the user may download the test case for the code to be tested and run it elsewhere to test the code to be tested.
[0069] In this way, since test cases can be obtained based on the test template without the need for users to write test cases themselves, the efficiency of obtaining test cases can be improved.
[0070] In a possible implementation, the determining device may also directly provide the test template of the code to be tested to the user, and the user decides whether to use the test template of the code to be tested as a test case of the code to be tested, and the process is as follows:
[0071] Provide the user with a test template corresponding to the code to be tested; obtain the test template after the user modifies the test template corresponding to the code to be tested; generate a test case for the code to be tested based on the modified test template, and test the code to be tested based on the test case of the code to be tested; or, obtain the test template confirmed by the user in the test template corresponding to the code to be tested; generate a test case for the code to be tested based on the confirmed test template, and test the code to be tested based on the test case of the code to be tested.
[0072] In this embodiment, the determining device may provide the user with a test template corresponding to the code to be tested, and provide the user with a function of modifying the test template and a function of confirming the test template.
[0073] If a user discovers an error in a test template, they can modify it. Specifically, these modifications may include code logic errors, redundant test method templates, incorrect data structures, and so on. After completing these modifications, the user can submit the modified test template to the determination device. The determination device retrieves the modified test template and identifies it as a test case for the code to be tested. The determination device then runs the test case, tests the code to be tested, obtains test results, and provides these results to the user.
[0074] Alternatively, if the user believes the test template has no issues, the user can confirm the test template, and the confirmation device will receive the confirmation instruction. The confirmation device can adjust the user-confirmed test template based on the context information of the code to be tested (the adjustment method is described above and will not be repeated here), and determine the adjusted test template as the test case for the code to be tested. The test case can then be run to test the code to be tested, obtain test results, and then provide the test results to the user.
[0075] In this way, since the test template is provided to the user for confirmation after being obtained, the test case corresponding to the code to be tested can be made more accurate, thereby making it possible to test the code to be tested more accurately.
[0076] It should be noted here that this is an example of determining that the device does not have a display function. When the device has a display function, the device can directly display the test template corresponding to the code to be tested. The user can see the test template corresponding to the code to be tested on the device, and then perform corresponding operations on the test template.
[0077] In addition, after the determination device obtains the test case corresponding to the template to be tested, the template to be tested and the test case may also be stored in correspondence with each other for updating the test template library mentioned later.
[0078] In a possible implementation, the determining device may obtain a test template corresponding to the code to be tested from a test template library, and the processing may be:
[0079] The determining device queries a test template library according to the attribute information of the code to be tested; and obtains a test template corresponding to the attribute information of the code to be tested whose similarity with the attribute information of the code to be tested meets a preset condition in the test template library.
[0080] In this embodiment, a test template library is constructed in advance in the determination device, and the test template library includes a plurality of test templates. Alternatively, a request may be made to other devices to obtain the test template library, and the test template library may be obtained from other devices. The determination device may use the attribute information of the code to be tested, and determine in the test template library the attribute information whose similarity with the attribute information of the code to be tested meets the preset conditions. Here, the preset conditions may be the target number with the highest similarity, and the target number may be preset, such as 2. Here, when determining the similarity, the distance between the attribute information of the code to be tested and the attribute information in the test template library may be calculated, and the distance may be the Euclidean distance, etc. The target number of attribute information with the smallest distance is determined as the target number of attribute information with the highest similarity to the code to be tested.
[0081] Then, the test template corresponding to the target number of attribute information is determined as the test template corresponding to the code to be tested.
[0082] It should be noted that the determining device can determine one or more test templates for the code to be tested. Of course, when the similarity between the attribute information of the code to be tested and the attribute information in the test template library is less than a certain value, in order to prevent the output of an incorrect test template, a prompt message indicating that no test template for the code to be tested was found can also be output to the user.
[0083] In one possible implementation, the test template library includes test templates corresponding to each attribute information. Specifically, when the test template library stores the test templates corresponding to each attribute information, it may store multiple trees, with the vertex of each tree being a technical attribute, one or more business attributes connected to the vertex of each tree, and a test template corresponding to each business attribute. Alternatively, the vertex of each tree is a business attribute, one or more technical attributes connected to the vertex of each tree, and a test template corresponding to each technical attribute. In this way, the test template library constructs test templates corresponding to both technical attributes and business attributes, that is, constructs test templates corresponding to attribute information.
[0084] In order to better understand the embodiment of the present application, the following is also provided for determining the test template of the code to be tested by the determination device: Figure 4 Example shown:
[0085] exist Figure 4 The code to be tested is a unit to be tested, and the unit to be tested includes three methods, namely method 1, method 2, and method 3. The determining device obtains attribute information of the code to be tested, including business attribute N and technical attribute M. The determining device searches for a test template corresponding to both business attribute N and technical attribute M in a test template library, and obtains a test template corresponding to the code to be tested.
[0086] In addition, in the embodiment of the present application, the test template library can be generated by other devices, or generated by the determination device. Here, the process of generating the test template library is described by taking the determination device generating the test template library as an example. Figure 5 As shown:
[0087] Step 501: The determination device obtains test cases of multiple codes.
[0088] The multiple codes are existing, tested codes. The test cases for each code are the test cases used during the testing of each code, i.e., known test cases. This example uses code as a test unit.
[0089] In this embodiment, the determination device may collect multiple known codes and test cases corresponding to the multiple codes, that is, obtain a combination of multiple codes and test cases. Specifically, it may be, but is not limited to, analyzing code in an open source code repository, obtaining multiple codes with test cases, and obtaining the test cases corresponding to the multiple codes.
[0090] Optionally, to more accurately construct a test template library, you can perform the following processing:
[0091] Invalid test cases among test cases corresponding to multiple codes are filtered out.
[0092] In this embodiment, the determination device can analyze each code obtained in step 501 to determine whether the code contains only a code name without an actual code segment. For a code, if there is no actual code segment, the code is considered invalid and can be filtered out along with its corresponding test case. For a test case, if there is no test end statement and / or no judgment statement in the code of the test case, the test case and its corresponding code are filtered out. Figure 6 Shown is a schematic diagram of the filtration process.
[0093] Step 502: The determining device determines the attribute information corresponding to each code.
[0094] In this embodiment, the determining device may determine the attribute information corresponding to each code in accordance with the method of determining the attribute information described above, which will not be described in detail here.
[0095] Step 503: The determination device performs grouping processing on the test cases to obtain a mapping relationship between attribute information and the test cases.
[0096] In this embodiment, the determination device groups codes with identical attribute information or with attribute information similarity exceeding a certain threshold into the same group. Since each code corresponds to a test case, this is equivalent to grouping the code's test cases according to attribute information. This grouping results in a mapping between attribute information and test cases.
[0097] It should be noted here that, since the attribute information includes technical attributes and business attributes, multiple trees can be formed based on the combination of technical attributes and business attributes. The vertex of each tree is a technical attribute, and one or more business attributes are connected under the vertex of each tree. Under each business attribute, there is a combination of code and test cases. Alternatively, the vertex of each tree is a business attribute, and one or more technical attributes are connected under the vertex of each tree. Under each technical attribute, there is a combination of code and test cases. For example, Figure 7 As shown, the technical attributes of multiple codes may include technical attribute 1, technical attribute 2, ..., to technical attribute N, the business attributes connected to technical attribute 1 may include business attribute 1 to business attribute M, business attribute 1 corresponds to 3 combinations of codes and test cases, business attribute M corresponds to 6 combinations of codes and test cases, the business attributes connected to technical attribute N may include business attribute 1 to business attribute P, business attribute 1 corresponds to 2 combinations of codes and test cases, business attribute P corresponds to 3 combinations of codes and test cases, and the remaining technical attributes are in Figure 6 Not shown in the figure.
[0098] Step 504: The determining device determines a test template corresponding to each attribute information based on a combination of the code corresponding to each attribute information and the test case.
[0099] In this embodiment, under any attribute information (using target attribute information as an example for illustration), the code corresponding to the target attribute information can be analyzed to obtain a method set consisting of one or more similar methods, that is, each method set includes similar methods. For each method in each method set, the test method corresponding to the method is determined in the test case corresponding to the code to which the method belongs. In this way, the determination device can obtain the test method corresponding to each method in each method set.
[0100] Then, for any method set, which can be called the target method set, the determination device performs code analysis on the test method corresponding to each method in the target method set to obtain the code logic of the test method corresponding to each method in the target method set. The determination device then extracts the common part of the code logic of the test method corresponding to each method in the target method set through clustering, pattern recognition and other technologies, and generalizes the difference part of the code logic of the test method corresponding to each method, and the common part and the difference part after generalization constitute the code part of the test method template corresponding to the target method set. Generalization processing here refers to: changing different expressions in sentences expressing the same meaning to the same expression. For example, for two statements corresponding to two test methods, m and n are used to represent parameters with the same meaning. After generalization processing, they are changed to be represented by n. "Clustering" here can use any clustering algorithm, such as density clustering algorithm.
[0101] The determining device then determines the name of the most frequently used test method among the test methods corresponding to the methods in the target method set as the name of the test method template corresponding to the target method set. The determining device then combines the name of the test method template corresponding to the target method set and the code portion of the test method template to form a test method template corresponding to the target method set.
[0102] For the target attribute information, the determination device determines the test method template corresponding to each method set under the target attribute information in the above manner. The determination device combines the test method templates of each method set corresponding to the target attribute information to obtain the test template corresponding to the target attribute information.
[0103] exist Figure 5 In the process of determining the device to build the test template library, the process of building the test template library for other devices is as follows. Figure 5 The described process is the same and will not be repeated here.
[0104] against Figure 5 In order to better understand the embodiment of the present application, an example of generating a test template is also provided, such as Figure 8 As shown:
[0105] exist Figure 8 In the example, the target attribute information corresponds to three codes, which can be classes, namely code 1, code 2, and code 3. Code 1 includes methods 1 to 4; code 2 includes methods 5 to 9; and code 3 includes methods 10 to 12. After the determination device performs similarity analysis on the three codes, multiple method sets are obtained, including method set 1 and method set 2. Method set 1 includes methods 1, 6, and 9, and method set 2 includes methods 8 and 12. Figure 8 Only method set 1 and method set 2 are shown. The determining device determines the test method corresponding to each method in method set 1. Based on the test method corresponding to each method, the determining device generates the code portion and the name of the test method template, thereby obtaining the test method template corresponding to method set 1. Similarly, the test method template corresponding to test method set 2 can also be obtained. The determining device combines the test method templates corresponding to the multiple method sets into a test template corresponding to the target attribute information.
[0106] It should also be noted here that Figure 5 In the process, for the target attribute information, the determination device not only needs to identify similar methods, but also needs to identify the unique methods in each code in the target attribute information, and does not consider this method as the scope of test template generation.
[0107] In addition, in order to better understand the embodiments of the present application, the embodiments of the present application also provide Figure 3 and Figure 5 The combined process diagram is as follows: Figure 9As shown, the determining device obtains multiple codes and the test cases corresponding to each of the codes, i.e., a test case library exists. The determining device then groups the test cases based on the code attribute information, obtains a mapping relationship between the attribute information and the test cases, and extracts the test template corresponding to each attribute information based on this mapping relationship, thus constructing a test template library. Subsequently, when the determining device obtains a test template for the code to be tested, it obtains the attribute information of the code to be tested and, based on the test template library, obtains the test template corresponding to the attribute information of the code to be tested.
[0108] In addition, it should be noted that in the embodiments of the present application, the code to be tested may be a test unit. When adjusting the test template of the code to be tested, since the code to be tested may contain certain unique methods, this part of the test method template needs to be written by the user, and the user can write this part of the test method template. In addition, the test methods corresponding to certain test method templates in the test template may not exist in the code to be tested, and the determination device may also delete these test method templates.
[0109] In an embodiment of the present application, the test template corresponding to the template to be tested is determined based on the combination of the business attributes and technical attributes of the code to be tested. The test template of the code to be tested can be automatically obtained from the perspective of business functions and coding information. In this way, the user does not need to write the entire test case, which can improve the efficiency of test case generation.
[0110] Figure 10 This is a structural diagram of the device for determining test cases provided by the embodiment of the present application. The device can be implemented as part or all of the device through software, hardware, or a combination of both. The device provided by the embodiment of the present application can implement the embodiment of the present application. Figure 3 The process described above includes: an acquisition module 1010 and a determination module 1020, wherein:
[0111] An acquisition module 1010 is used to acquire attribute information of the code to be tested, wherein the attribute information includes technical attributes and business attributes, and can be used to implement the acquisition function of step 301 and execute the implicit steps included in step 301;
[0112] Determination module 1020 is used to determine the test template corresponding to the code to be tested based on the attribute information of the code to be tested. The test template is obtained based on multiple known test cases. The test template is used to generate the test case corresponding to the code to be tested, and can be specifically used to implement the function determined in step 302 and execute the implicit steps contained in step 302.
[0113] In a possible implementation, the determining module 1020 is further configured to adjust the test template according to the context information of the code to be tested to obtain a test case for the code to be tested;
[0114] like Figure 11 As shown, the device also includes:
[0115] The providing module 1030 is used to provide the user with the test cases of the code to be tested, or the testing module 1040 is used to test the code to be tested according to the test cases of the code to be tested. The providing module 1030 is used to provide the user with the test results of the code to be tested.
[0116] In a possible implementation, the business attribute is used to indicate the function implemented or the business completed by the code to be tested; and the technical attribute is used to indicate programming technical information of the code to be tested.
[0117] In a possible implementation, the apparatus further includes: a providing module 1030, configured to provide a user with a test template corresponding to the code to be tested;
[0118] The acquisition module 1010 is further configured to acquire a test template after the user modifies the test template corresponding to the code to be tested;
[0119] The determining module 1020 is further configured to generate a test case for the code to be tested according to the modified test template;
[0120] The apparatus further includes a testing module 1040 for testing the code to be tested according to a test case of the code to be tested;
[0121] or,
[0122] The acquisition module 1010 is further configured to acquire the test template confirmed by the user from the test template corresponding to the code to be tested;
[0123] The determining module 1020 is further configured to generate a test case for the code to be tested according to the confirmed test template;
[0124] The apparatus further includes a testing module 1040 configured to test the code to be tested according to a test case of the code to be tested.
[0125] In a possible implementation, the determining module 1020 is configured to:
[0126] Querying a test template library according to the attribute information of the code to be tested;
[0127] A test template corresponding to attribute information whose similarity with the attribute information of the code to be tested meets a preset condition is obtained in the test template library.
[0128] In a possible implementation, the test template library includes a test template corresponding to each attribute information.
[0129] In a possible implementation, the test template library is constructed based on attribute information of multiple codes and corresponding test cases.
[0130] In one possible implementation, Figure 12 As shown, the device also includes:
[0131] The filtering module 1050 is used to filter invalid test cases in the test cases corresponding to the multiple codes before building the test template library.
[0132] The division of modules in the embodiments of the present application is illustrative and is merely a logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional modules in the various embodiments of the present application may be integrated into a single processor, or may exist physically separately, or two or more modules may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or software functional modules.
[0133] An embodiment of the present application also provides a computing device for determining a test template. Figure 13 A possible architecture diagram of a computing device 1300 is provided as an example.
[0134] The computing device 1300 includes a memory 1301 , a processor 1302 , a communication interface 1303 , and a bus 1304 . The memory 1301 , the processor 1302 , and the communication interface 1303 are connected to each other via the bus 1304 .
[0135] Memory 1301 can be a ROM, static storage device, dynamic storage device, or RAM. Memory 1301 can store programs. When the program stored in memory 1301 is executed by processor 1302, processor 1302 and communication interface 1303 are used to perform the method for determining a test template. Memory 1301 can also store data sets. For example, a portion of the storage resources in memory 1301 is used to store a test template library.
[0136] The processor 1302 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), a graphics processing unit (GPU), or one or more integrated circuits.
[0137] Processor 1302 may also be an integrated circuit chip with signal processing capabilities. During implementation, some or all of the functions of the device for determining a test template of the present application may be performed by hardware integrated logic circuits or software instructions in processor 1302. The aforementioned processor 1302 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component. The various methods, steps, and logic block diagrams disclosed in the above embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present application may be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or the like. The storage medium is located in the memory 1301, and the processor 1302 reads the information in the memory 1301 and combines its hardware to complete part of the functions of the device for determining the test template in the embodiment of the present application.
[0138] The communication interface 1303 uses a transceiver module such as, but not limited to, a transceiver to implement communication between the computing device 1300 and other devices or a communication network.
[0139] The bus 1304 may include a path for transmitting information between various components of the computing device 1300 (eg, the memory 1301 , the processor 1302 , and the communication interface 1303 ).
[0140] When there are multiple computer devices 1300, a communication path is established between each of the computing devices 1300 via a communication network. Each computing device 1300 runs any one or more of the acquisition module 1010 and the determination module 1020.
[0141] In the above embodiments, they can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, they 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 server or terminal, the process or function described in the embodiment of the present application is generated in whole or in part. 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 one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a server or terminal or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, and a tape, etc.), an optical medium (e.g., a digital video disk (DVD), etc.), or a semiconductor medium (e.g., a solid-state drive, etc.).
Claims
1. A method for determining a test template, characterized in that: The method comprises: Obtaining attribute information of the code to be tested, the attribute information including technical attributes and business attributes, the technical attributes including the language and technology stack used to program the code to be tested, and the business attributes including a preset number of words that appear most frequently in the code to be tested; Determine, based on the attribute information of the code to be tested, a test template corresponding to the code to be tested, wherein the test template is obtained based on a plurality of known test cases and is used to generate a test case corresponding to the code to be tested; Adjust the test template according to the context information of the code to be tested to obtain a test case for the code to be tested, wherein the context information includes one or more of a called interface, a data structure, or code logic. When the context information includes a called interface, adjust the test template to use the called interface and correct the calling statement of the method in the code to be tested. When the context information includes a data structure, adjust the test template to adjust the structure of the input data in the test template. When the context information includes code logic, adjust the test template to correct the variable name in the test template and supplement the missing statements in the test template. Providing a test case of the code to be tested to a user, or testing the code to be tested according to the test case of the code to be tested, and providing a test result of the code to be tested to the user.
2. The method according to claim 1, characterized in that The method further comprises: Providing the user with a test template corresponding to the code to be tested; Obtaining a test template after the user modifies the test template corresponding to the code to be tested; Generate a test case for the code to be tested according to the modified test template, and test the code to be tested according to the test case for the code to be tested; or, Obtaining the test template confirmed by the user in the test template corresponding to the code to be tested; A test case for the code to be tested is generated according to the confirmed test template, and the code to be tested is tested according to the test case for the code to be tested.
3. The method according to claim 1, characterized in that The step of determining a test template corresponding to the code to be tested according to the attribute information of the code to be tested includes: Querying a test template library according to the attribute information of the code to be tested; A test template corresponding to attribute information whose similarity with the attribute information of the code to be tested meets a preset condition is obtained in the test template library.
4. The method according to claim 3, characterized in that The test template library includes test templates corresponding to various attribute information.
5. The method according to claim 3, characterized in that The test template library is constructed based on attribute information of multiple codes and corresponding test cases.
6. The method according to claim 5, characterized in that Before constructing the test template library, the method further includes: Invalid test cases among the test cases corresponding to the multiple codes are filtered.
7. A device for determining a test template, characterized in that: The device comprises: an acquisition module, configured to acquire attribute information of the code to be tested, wherein the attribute information includes technical attributes and business attributes, the technical attributes including the language and technology stack used to program the code to be tested, and the business attributes including a preset number of words that appear most frequently in the code to be tested; A determination module, configured to determine a test template corresponding to the code to be tested based on the attribute information of the code to be tested, wherein the test template is obtained based on a plurality of known test cases and is used to generate a test case corresponding to the code to be tested; The determination module is further configured to adjust the test template according to context information of the code to be tested to obtain a test case for the code to be tested, wherein the context information includes one or more of a called interface, a data structure, or code logic; in a case where the context information includes a called interface, the test template is adjusted to use the called interface and the calling statement of the method in the code to be tested is corrected; in a case where the context information includes a data structure, the test template is adjusted to adjust the structure of input data in the test template; in a case where the context information includes code logic, the test template is adjusted to correct the variable name in the test template and supplement the missing statements in the test template; A providing module is used to provide the user with test cases of the code to be tested, or a testing module is used to test the code to be tested according to the test cases of the code to be tested, and a providing module is used to provide the user with test results of the code to be tested.
8. The device according to claim 7, characterized in that The device further includes: a providing module, configured to provide a user with a test template corresponding to the code to be tested; The acquisition module is further configured to acquire the test template after the user modifies the test template corresponding to the code to be tested; The determining module is further configured to generate a test case for the code to be tested according to the modified test template; The device further includes a testing module for testing the code to be tested according to a test case of the code to be tested; or, The acquisition module is further configured to acquire the test template confirmed by the user from the test template corresponding to the code to be tested; The determining module is further configured to generate a test case for the code to be tested according to the confirmed test template; The device further includes a testing module configured to test the code to be tested according to a test case of the code to be tested.
9. The device according to claim 7, characterized in that The determining module is configured to: Querying a test template library according to the attribute information of the code to be tested; A test template corresponding to attribute information whose similarity with the attribute information of the code to be tested meets a preset condition is obtained in the test template library.
10. The device according to claim 9, characterized in that The test template library includes test templates corresponding to various attribute information.
11. The device according to claim 9, characterized in that The test template library is constructed based on attribute information of multiple codes and corresponding test cases.
12. The device according to claim 11, characterized in that The device further comprises: The filtering module is used to filter invalid test cases in the test cases corresponding to the multiple codes before building the test template library.
13. A computing device, characterized in that The computing device includes a memory and a processor, the memory being configured to store computer instructions; The processor executes the computer instructions stored in the memory to perform the method according to any one of claims 1 to 6.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program code. When the computer program code is executed by a computing device, the computing device performs the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Test method and test system for WEB pages
CN104679658A
Test case generation method and apparatus
CN106528395A
Test case editing method and device, terminal and computer readable storage medium
CN109885474A
Chip testing method and device, electronic equipment and computer readable medium
CN111105839A