A method and device for generating automatic test code

By using probes to collect data and generate code in automated testing, the problems of high cost and low utilization in the existing technology are solved, and the automatic generation and efficient maintenance of automated test codes are realized, and the testing efficiency and quality are improved.

CN110858172BActive Publication Date: 2024-11-22BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201810966515.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-08-23
Publication Date
2024-11-22
Estimated Expiration
2038-08-23

AI Technical Summary

Technical Problem

In the existing automation testing technology, the separation of functional testing and automation testing has led to high development costs, high maintenance costs, low utilization rates, and relying on high-tech talents, which has become an implementation bottleneck.

Method used

By using probes to collect test data in the target application, generating automated test codes based on templates, and using bytecode enhancement technology to obtain test data in real time, so as to synchronize functional tests and automated tests, reducing the cost of code writing.

Benefits of technology

It realizes automatic generation of automated test codes, reduces code writing and maintenance costs, improves testing efficiency, reduces dependence on high-tech talents, and improves test coverage and quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110858172B_ABST
    Figure CN110858172B_ABST
Patent Text Reader

Abstract

The present invention discloses an automated test code generation method and device, and relates to the field of computer technology. A specific implementation of the method includes: determining an interface corresponding to a test instruction in a target application, collecting test data of the interface during the test process based on a probe corresponding to the target application; in the test process of the interface, generating automated test code corresponding to the interface according to a template corresponding to the target application and the test data. This implementation adopts bytecode enhancement technology to obtain test data in real time, provides an implementation basis for automatically generating automated code while performing functional testing, and when the functional test is completed, the automated code is also automatically completed, reducing the cost of code writing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an automatic test code generation method and device. Background Art

[0002] With the rapid development of Internet technology, automated testing technology plays an increasingly important role in the current testing process. It can save testing time in the regression testing phase and contribute to the overall quality assurance of the software.

[0003] In the existing automated testing process, testers usually manually write automated testing codes or use scripts based on functional test cases after the test is completed.

[0004] In the process of implementing the present invention, the inventors found that the prior art has at least the following problems:

[0005] 1) Functional testing is separated from automated testing. Generally, functional testing is performed first, and then automated testing is performed after completion, resulting in high development costs;

[0006] 2) The writing of automated test code is usually done after functional testing and cannot assist in the execution of functional testing, resulting in high code writing costs;

[0007] 3) Automated testing requires separate maintenance of test data. When the application under test has a change requirement, it is necessary to retest and generate automated test code, resulting in high maintenance costs and low utilization;

[0008] 4) It is time-consuming and relies on highly skilled personnel, thus becoming a bottleneck in the implementation of automated testing. Summary of the invention

[0009] In view of this, an embodiment of the present invention provides an automated test code generation method and device, which can at least solve the problems of high code writing cost, difficult maintenance and low utilization rate in the prior art.

[0010] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, there is provided a method for generating automated test code, comprising: determining an interface corresponding to a test instruction in a target application, and collecting test data of the interface during the test process based on a probe corresponding to the target application; during the test process of the interface, generating automated test code corresponding to the interface based on a template corresponding to the target application and the test data.

[0011] Optionally, probes are generated based on bytecode enhancement;

[0012] Based on the probe corresponding to the target application, the test data of the interface during the test process is collected, including: based on the probe, adding predetermined code to the test code of the interface; running the test code after the interface is changed, and based on the predetermined reflection method, obtaining the input parameters, output parameters and parameter types of the interface during the test process.

[0013] Optionally, after collecting test data of the interface during the test process based on the probe corresponding to the target application, the method further includes: receiving a data deletion instruction, extracting test data corresponding to the data deletion instruction, and performing a deletion operation on the extracted test data.

[0014] Optionally, generating automated test code corresponding to the interface according to the template and test data corresponding to the target application also includes:

[0015] Based on a predetermined matching rule, when there is a matching interface corresponding to the interface, using the automated test code corresponding to the matching interface as the automated test code corresponding to the interface; or

[0016] When there is no matching interface corresponding to the interface, an automated test code corresponding to the interface is generated according to the template and the test data.

[0017] Optional, including:

[0018] Obtaining description information of the interface, extracting keywords in the description information that meet a predetermined keyword extraction rule, and determining the interface corresponding to the keyword as a matching interface; wherein the matching interface does not include an interface; and / or

[0019] Obtaining the parameter type and parameter quantity of the interface, and determining the interface corresponding to the parameter type and / or parameter quantity as the matching interface; and / or

[0020] Obtain the landing data of the interface, and use the interface in the same database table as the landing data as the matching interface; and / or

[0021] Determine the service type of the interface and use the interface of the same service type as the matching interface.

[0022] Optionally, after generating the automated test code corresponding to the interface, it also includes: receiving a change instruction for the automated test code, and changing the test data based on the change data in the change instruction; and regenerating the automated test code corresponding to the interface based on the changed test data and the template.

[0023] To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided an automatic test code generation device, comprising:

[0024] A data acquisition module, used to determine the interface corresponding to the test instruction in the target application, and to collect test data of the interface during the test process based on the probe corresponding to the target application;

[0025] The code generation module is used to generate automated test code corresponding to the interface according to the template and test data corresponding to the target application during the interface testing process.

[0026] Optionally, probes are generated based on bytecode enhancement;

[0027] The data acquisition module is used to: add predetermined code to the test code of the interface based on the probe; run the test code after the interface is changed, and obtain the input parameters, output parameters and parameter types of the interface during the test process based on the predetermined reflection method.

[0028] Optionally, the data acquisition module is used to: receive a data deletion instruction, extract test data corresponding to the data deletion instruction, and perform a deletion operation on the extracted test data.

[0029] Optionally, the code generation module is also used to:

[0030] Based on a predetermined matching rule, when there is a matching interface corresponding to the interface, the automated test code corresponding to the matching interface is used as the automated test code corresponding to the interface; wherein the matching interface does not include the interface; or

[0031] When there is no matching interface corresponding to the interface, an automated test code corresponding to the interface is generated according to the template and the test data.

[0032] Optional, code generation module for:

[0033] Obtaining description information of the interface, extracting keywords in the description information that meet a predetermined keyword extraction rule, and determining the interface corresponding to the keyword as a matching interface; and / or

[0034] Obtaining the parameter type and parameter quantity of the interface, and determining the interface corresponding to the parameter type and / or parameter quantity as the matching interface; and / or

[0035] Obtain the landing data of the interface, and use the interface in the same database table as the landing data as the matching interface; and / or

[0036] Determine the service type of the interface and use the interface of the same service type as the matching interface.

[0037] Optionally, it also includes a code change module, which is used to: receive a change instruction for the automated test code, and change the test data based on the change data in the change instruction; and regenerate the automated test code corresponding to the interface based on the changed test data and the template.

[0038] The electronic device of an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any of the above-mentioned automated test code generation methods.

[0039] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, any of the above-mentioned automated test code generation methods is implemented.

[0040] According to the solution provided by the present invention, one embodiment of the above invention has the following advantages or beneficial effects: bytecode enhancement technology is used to obtain test data in real time, which provides an implementation basis for automatically generating automation code while performing functional testing. When the functional test is completed, the automation code is also automatically completed, reducing the cost of code writing.

[0041] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0043] Figure 1 It is a main flow chart of an automatic test code generation method according to an embodiment of the present invention;

[0044] Figure 2 is a flow chart of an optional method for generating automated test code according to an embodiment of the present invention;

[0045] Figure 3 is a flowchart of another optional method for generating automated test code according to an embodiment of the present invention;

[0046] Figure 4 is a flowchart of another optional method for generating automated test code according to an embodiment of the present invention;

[0047] Figure 5 is a flowchart of another optional method for generating automated test code according to an embodiment of the present invention;

[0048] Figure 6 is a schematic diagram of main modules of an automatic test code generation device according to an embodiment of the present invention;

[0049] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0050] Figure 8 It is a schematic diagram of the structure of a computer system of a mobile device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0051] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0052] It should be noted that the method provided in the embodiment of the present invention is applicable to automated testing of all Java languages ​​in the software industry, and its purpose is to automatically test products or interfaces regularly. Other types of unit testing can be implemented according to specific language extensions. The present invention is mainly explained using the login function and the shopping cart as examples.

[0053] Automated testing simulates the implementation of manual testing, which refers to the process of automatically executing software testing in the form of code or script. Therefore, the generation of corresponding code and script is necessary.

[0054] It should be noted that the code and script here mean the same thing. Automated testing can be generated by scripting language or by code. The two are basically the same. Although the operating principles and methods are different, the problems they solve are the same.

[0055] The nouns involved in the present invention are explained as follows:

[0056] Bytecode: It can be understood as the intermediate process of translating source code into binary data that can be recognized by computers. Because the Java code developed by developers is just a combination of words and formats, but these words need to be translated for computer recognition, because computers only recognize binary codes 0 / 1. In addition, bytecode is a necessary process in the operation of Java language, regardless of the environment. Any program developed in Java language must execute this process.

[0057] Bytecode enhancement: After the Java bytecode is generated, it is modified to enhance its functionality. This method is equivalent to modifying the binary file of the application, mainly to reduce redundant code and improve performance.

[0058] FreeMarker: A template engine, that is, a general tool for generating output text based on a template and the data to be changed.

[0059] Landed data: data that is persisted. This type of data is usually stored on a hard disk or other persistent storage device, such as pictures, system logs, data displayed on a page, and data stored in a relational database. Landed data must have a fixed carrier and will not disappear instantly.

[0060] See also Figure 1 , which shows a main flow chart of an automated test code generation method provided by an embodiment of the present invention, comprising the following steps:

[0061] S101: determining an interface corresponding to a test instruction in a target application, and collecting test data of the interface during a test process based on a probe corresponding to the target application;

[0062] S102: During the test of the interface, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and test data.

[0063] In the above implementation, for step S101, during testing, the probe Agent for development bytecode enhancement can be deployed into the test environment together with the application:

[0064] 1) Test environment: Whether it is an online environment or a test environment, as long as the code is developed in Java, it must rely on the Java virtual machine, namely JVM (Java Virtual Machine).

[0065] 2) Application: The test of application is mainly the test of application interface. For example, the functional correctness of a television can only be tested by changing channels and volume, which are aimed at the television interface; but the internal implementation of the television, such as display and signal flow, is not considered in the present invention.

[0066] 3) Probe Agent: It is mainly for applications and must be started together with the application. When the application starts, modify the startup parameters of the jvm to load the startup of the probe. Because only the jvm configuration is modified, not the code submitted by the developer, it is universal for all java applications.

[0067] The purpose of the agent is to collect data during the application call / test process, and this process is necessary, otherwise the automated test code cannot be automatically generated. Of course, it can also collect data from non-interface calls, such as the actual user name abcdef and password 123456 in the login function, which is a non-interface.

[0068] For example, user A sends a message "Hello" to user B, but there is actually a lot of hidden information in the background, such as the sending address, encryption and decryption information, etc., which users cannot see. However, for writing automated test code later, the information that cannot be seen on the page may be necessary. If the computer cannot automatically obtain it, it cannot automatically generate automated test code, so it is necessary to rely on the agent to obtain this data.

[0069] The Agent obtains this information and makes interception changes based on the code of the calling interface. For example, when the RPC (Remote Procedure Call Protocol) is called remotely, it can intercept before loading the class (the name of the bytecode file), modify the bytecode of the interface, and replace the original bytecode file. In addition, it obtains information such as the request path parameters of the remote call (for example, after the user clicks the login button, a login request will be generated to connect to the background server. This request contains the user name and password entered by the user), as well as information such as the call result parameters after the call is completed. Finally, the collected information is written to the database or sent to the asynchronous MQ queue message. For details, see Figure 2 Description shown.

[0070] It should be noted that, unlike ordinary code modification, the use of bytecode enhancement technology only simulates code modification. For example, a copy is made and the code in the copy is modified. In fact, the code of the application under test is not modified.

[0071] In addition, the probes used may be universal, for example, application 1-probe 1, application 2-probe 1, or may be specifically configured, for example, application 1-probe 1, application 2-probe 2.

[0072] For step S102, during the functional testing process, a Collector is developed to dynamically generate automated testing codes based on collected test data and corresponding templates (eg FreeMarker) to reduce the cost of developing automated testing scripts.

[0073] It should be noted that the Collector is not in the agent. The agent exists to collect the request information of the developer interface code. After the information is collected, it needs to be processed according to the Collector. The Collector can be regarded as a data processing center. Figure 3 to Figure 5 describe.

[0074] Take the login function as an example. When the login encryption method is outdated and needs to be replaced, if there is automated test code, it can be run directly without manual testing. The significance of generating automated test code during functional testing is that there is no need to wait until the next time the project / interface is changed to realize it. For example, in the scenario where the username and password in the login function are both data, in the manual test, the username is 123 and the password is 12, then the subsequent combinations of 1234 can be executed with automated testing, which fully reflects the purpose of automated testing to assist functional testing.

[0075] The method provided in the above embodiment uses bytecode enhancement technology to obtain test data in real time, and provides data support for automatically generating automation code while performing functional testing. When the functional test is completed, the automation code is also automatically completed, reducing the cost of code writing.

[0076] See also Figure 2 , shows a schematic flow chart of an optional automated test code generation method according to an embodiment of the present invention, comprising the following steps:

[0077] S201: Determine an interface corresponding to a test instruction in a target application, and add a predetermined code to a test code of the interface based on a probe corresponding to the target application;

[0078] S202: Run the test code after the interface is changed, and obtain the input parameters, output parameters and parameter types of the interface during the test based on a predetermined reflection method;

[0079] S203: During the test of the interface, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and test data.

[0080] In the above implementation, step S203 can refer to Figure 1 The description of step S102 is not repeated here.

[0081] In the above implementation, for step S201, the probe Agent implemented by Java bytecode enhancement technology intervenes in the code that initiates the RPC (i.e., intercepts and modifies the bytecode) to automatically process the label information. In this way, the developer does not need to modify the code, and the code can be intercepted before the class file is loaded to implement the modification of the bytecode.

[0082] Among them, it should be noted that:

[0083] 1) Code for initiating RPC

[0084] Testers usually use black box testing to test applications, that is, the application under test is regarded as a black box, and the performance of the entire black box is tested only through the reserved interface outside the box, for example, TV-external button-tuning key. For the application under test, any place where an RPC call is initiated is the reserved external interface (the description of this invention only involves the external interface of the application, and does not consider the internal interface of the application).

[0085] 2) The Agent modifies the code that initiates the PRC:

[0086] In principle, bytecode enhancement technology can modify any code in the Java language. However, for the test process, only the interface code that initiates the RPC call can be modified to achieve the purpose of the test. No code modification is required for other places where no call occurs. RPC call is a protocol Java code. To use this protocol, there must be code to implement this part.

[0087] In addition, the modification of the interface code is simulated and implemented in memory, which only adds a part of the code without other deletions, so the source code will not be modified. And this modification process is necessary because the application outputs information in a directional manner.

[0088] For step S202, the added part of code is equivalent to marking the added code with a mark, and this mark can be understood as a label.

[0089] After the code is marked, the added code can be automatically run when the source code of the application interface is running. This part of the code can help testers obtain some information that was not available before, such as the input parameters and input parameter types of RPC remote calls, call address methods, output parameters and output parameter types, etc.

[0090] Take shopping cart function testing as an example;

[0091] 1) The user selects a product on the shopping interface and clicks Add to Cart. The shopping cart interface shows that the product is stored:

[0092] 2) For the computer: In response to the user's click to add a product to the shopping cart, the corresponding interface address is triggered to pass the product information of the product as an input parameter to the backend server; after the backend server receives the input parameter, it goes through a series of business processing and sends the information of the successful addition of the product to the shopping cart to the interface through the interface address, so that the user can see the product added to the shopping cart on the interface.

[0093] 3) To automate this process, input parameters are required, such as product information. The automation code automatically triggers the interface address and sends it to the backend server through the maintained input parameters. The backend server processes it in the same way as when a user manually adds a product to the shopping cart, and then returns it to the automation test code, which then determines whether the addition is successful based on the server's response.

[0094] For similar processes, all test cases / test methods are written into code, so that no matter how the backend server is modified, the automated test code can replace the manual test. Alternatively, it can be understood that the automated test code simulates the manual test process and saves this process for subsequent reuse.

[0095] Furthermore, the acquisition of the above data can rely on reflection technology. Reflection technology can be regarded as a function of Java itself, which can perform self-checking when the application is running. In the present invention, it is mainly used to obtain parameter types. Automated testing mainly tests whether the source code is correct, so the type of the source code parameter must be known.

[0096] For example, when testing the two parameters in the login function - username (character type) and password (integer type), when a correct login scenario case needs to be sent in the automated test, a parameter of the same type must be entered.

[0097] The method provided in the above embodiment adopts bytecode enhancement technology to automatically obtain test data for generating automated test code, and does not require testers to modify the application source code. It directly intervenes in the test scenario to collect method parameters. The shown method solves the problem that in the prior art, when writing automated test code, it is necessary to complete the functional test and fully obtain the data.

[0098] See also Figure 3 , shows a schematic flow chart of another optional method for generating automated test code according to an embodiment of the present invention, comprising the following steps:

[0099] S301: Determine an interface corresponding to a test instruction in a target application, and collect test data of the interface during a test process based on a probe corresponding to the target application;

[0100] S302: receiving a data deletion instruction, extracting test data corresponding to the data deletion instruction, and performing a deletion operation on the extracted test data;

[0101] S303: During the test of the interface, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and test data.

[0102] In the above implementation, step S301 can refer to Figure 1For the description of step S101, see Figure 2 The description of steps S201 and S202 is not repeated here.

[0103] In the above implementation, for step S302, the newly added interface refers to the interface in the system or application that the tester has never tested, and all historical information is non-existent, and the tester needs to start functional testing first.

[0104] Taking the shopping cart function test as an example, the tester needs to add some products to the shopping cart according to the test method. For example, 10 products with different attributes are prepared, including physical products (such as clothes) and virtual products (such as phone card recharges). When all 10 products are successfully added to the shopping cart, it means that the shopping cart function is normal.

[0105] According to the Agent, the generated interface or remote call process will be completely saved and stored. Continuing with the previous example, when a product is added to the shopping cart, the addition is determined by checking whether the product exists in the shopping cart. When all products are added, the test ends. Through this solution, the previous 10 processes of adding products to the shopping cart can be recorded, and the required data is also retained. When generating automated test code, the test data of these 10 products can be used to simulate the tester's 10 manual operation processes.

[0106] After the data is stored in the database, testers can consume the MQ queue messages sent by the Agent to display the overall test process. For example, if the functional test generates 20 test cases for the interface, the page will display the process of these test cases.

[0107] It should be noted that:

[0108] 1) Display of test cases

[0109] Continuing with the previous example, functional testing is the process of discovering application problems, such as problems with the program itself or testers’ operating errors (for example, they clicked Y instead of X). However, when the background agent collects information such as the tester’s operation records and operation data, it cannot distinguish whether it is the program itself or human factors. Therefore, the test data needs to be fully displayed so that testers can exclude some invalid use cases that are not related to this test, reducing the cost and time consumption of generating invalid automated test code in the future.

[0110] In addition, the display of test data may be in other forms besides web page display, such as web page, such as Excel table. The present invention mainly displays in web page form.

[0111] 2) Screening of test cases

[0112] In actual application testing, erroneous / duplicate cases are usually generated due to factors such as the test environment, so the number of cases obtained may be large, for example, 20+.

[0113] The screening of valid cases is done manually by the testers. During the testing process, the testers know which tests are valid and which are invalid, which is the significance of the test.

[0114] Testers can mark valid test cases on the page, and then generate corresponding automated test codes for the interface based on a unified template (for example, freemarker, etc.) based on the marked test cases. For example, 20 automated test code cases can be generated based on 20 test cases and saved for subsequent regression testing.

[0115] It should be noted that test case is a general term for test cases. Taking the login function as an example, there must be at least two test cases - a correct username and password, and an incorrect username and password.

[0116] The method shown is applicable to commonly used HTTP interfaces, web services, JSF (Java Server Faces) protocol interfaces, MQ message queue interfaces, database operations, etc.

[0117] For details of the automated test code generation process in step S303, see Figure 1 The description of step S102 is shown, except that the test data at this time is the filtered test data.

[0118] The method provided in the above embodiment can display test data so that testers can screen valid data, eliminate erroneous or invalid test cases, and mark valid data to improve the availability and reusability of subsequent automated test codes.

[0119] See also Figure 4 , shows a schematic flow chart of another optional automated test code generation method according to an embodiment of the present invention, comprising the following steps:

[0120] S401: Determine an interface corresponding to a test instruction in a target application, and collect test data of the interface during the test process based on a probe corresponding to the target application;

[0121] S402: Based on a predetermined matching rule, when there is a matching interface corresponding to the interface, using the automated test code corresponding to the matching interface as the automated test code corresponding to the interface; wherein the matching interface does not include the interface;

[0122] S402': when there is no matching interface corresponding to the interface, generating an automated test code corresponding to the interface according to a template corresponding to the target application and test data.

[0123] In the above implementation, step S401 can refer to Figure 1 For the description of step S101, see Figure 2 The description of steps S201 and S202 is not repeated here.

[0124] In the above implementation, for step S402, after the test data is collected by the Agent, the automated test code can be generated based on the collector for regression testing, but the prerequisite is that the test data can only be generated after passing the functional test.

[0125] However, based on the similarity of interfaces, the corresponding automated test codes can be reused, so that the functional testing process can be skipped to a certain extent and automated testing can be directly performed:

[0126] For similar interfaces, for example, interface A has a login function, and interface B also has a login function. For testers, the functions of both interfaces must be fully tested. On this basis, the interfaces can be analyzed and matched for similarity. If they are similar, the saved historical data can be directly used to intelligently generate automated test codes for related scenarios, so as to directly skip the functional testing process and directly conduct automated testing, thereby improving testing efficiency and saving testing time.

[0127] Furthermore, interface refers to the content targeted by automated testing, and interface needs to be supported by test data / parameters, etc. For matching of the same interface, you can directly generate it by modifying only part of the code:

[0128] For example, after the test of interface A is completed and the automated test code is generated, when testing interface B, the difference between the two interfaces can be directly modified. Externally, the only difference may be the address, and the test does not care about the internally implemented algorithm (such as encryption algorithm, etc.). Therefore, the calling address of A can be modified and directly applied to the automated test of interface B.

[0129] Furthermore, the codes may be similar. For interfaces A and B, although the displayed methods may be usernames and passwords, the background may use different encryption or verification methods. For such similar functions, some parameters can be replaced, for example, address path information.

[0130] The matching rules involved in determining whether interfaces are similar can be:

[0131] Matching rule 1: Match the interface description information in the form of keywords, and mainly use fuzzy search. For example, interface A-login, user name, password, interface B-login, user name, password;

[0132] Matching rule 2: Match by interface parameter type and number:

[0133] Take the login function as an example. Interface A has two parameters - username and password, and another interface C has three parameters - username, password and expiration date. If the interface to be matched also has three parameters, the automated test code of interface C must be selected;

[0134] Similarly, for parameter types, for example, the parameter type of the user name in interface A is a string type, and the type of the user name in interface C is an integer type. If the user name of the current interface to be matched is also a string type, then the automated test code of interface A is selected.

[0135] Matching rule 3: determined by the landing data (ie, persistent data) of the interface, for example, both access the same database table.

[0136] Matching rule 4: Match by business type and function of the interface, for example, interface A and interface B with the same login function. The business type of the interface can be preset, determined online by the tester, or customized.

[0137] It should be noted that the matching rules include but are not limited to the above rules, and the number can be increased at any time. For the matching rules, one can be selected for matching, or two or more can be selected for matching, depending on actual needs. When the number of selected matching rules is large, they can be screened step by step to improve the accuracy of interface matching.

[0138] The determination of the matching interface cannot be determined by a single matching rule, so the process also needs to rely on information such as the parameter type and number of the test data in step S402.

[0139] Taking the login function as an example, if the matching keyword can match both interfaces, then other rules can be used for fine-tuning. However, when the number of matching interfaces is large, for example, two, one can be randomly selected as the matching interface.

[0140] In addition, the matching accuracy will gradually improve with the accumulation of usage time. In the initial stage, the amount of test data and automation code is small, and the matching probability may be zero; but as the usage time increases, the number of automation codes gradually increases, and the probability of meeting the corresponding matching rules will also increase. In theory, when the amount of data in the database accumulates to a certain extent, there is no need to automatically generate automated test code, because the library has covered all business scenarios. Although this is an ideal state, it also means that the more information there is in the library, the more accurate the chance of meeting the matching rules.

[0141] For smart matching, there is no cost of writing automation code. You can directly use other similar interfaces and functions to perform automated testing and skip the functional testing part, which greatly improves the efficiency of the entire testing process.

[0142] For step S402', when there is no matching interface, Figure 1 The method shown generates automated test code based on test data and templates.

[0143] The method provided in the above embodiment uses rule matching to directly generate the automated test code required this time based on the historical automated test code for similar requests or business logic, thereby realizing the reuse of the automated test code and achieving the purpose of intelligently skipping the functional test steps and directly executing the automated test case, providing a foundation for subsequent artificial intelligence.

[0144] See also Figure 5 , shows a schematic flow chart of another optional automated test code generation method according to an embodiment of the present invention, comprising the following steps:

[0145] S501: Determine an interface corresponding to a test instruction in a target application, and collect test data of the interface during the test process based on a probe corresponding to the target application;

[0146] S502: During the interface testing process, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and test data;

[0147] S503: receiving a change instruction for the automated test code, and changing the test data based on the change data in the change instruction;

[0148] S504: Regenerate automated test code corresponding to the interface based on the changed test data and the template.

[0149] In the above implementation, step S501 can refer to Figure 1 For the description of step S101, see Figure 2For the description of steps S201 and S202, see step S502. Figure 1 The description of step S102 is not repeated here.

[0150] In the above implementation, for steps S503 and S504, the test data can be stored in the database in real time, so as to facilitate the subsequent search for the entire test process.

[0151] If the application under test has functional changes and the changes are large, the previously generated automated test code also needs to be changed. For these automated test codes that need to be changed, the test data can be directly modified and the automated test code can be regenerated, reducing the maintenance of the original automated test code.

[0152] For example, old-fashioned televisions did not have remote controls, and testing was done based on TV buttons. Now that they have become remote controls, the corresponding automated test code must be transferred to the remote control. However, the functions of the TV buttons and the buttons on the remote control are the same, for example, changing channels / adjusting volume, etc., which means that only by modifying a part of the data, the automated test code can be regenerated / modified, which is relatively fast and convenient.

[0153] The method provided in the above embodiment facilitates the preservation of test data and the dynamic maintenance and updating of automated test codes in the later stage, thereby greatly reducing the maintenance cost of automated test codes and shortening the debugging and maintenance time of codes.

[0154] The method provided in the embodiment of the present invention is based on the idea of ​​automatically generating automated test code while performing functional testing, which can greatly improve the coverage of automated test code, assist functional testing efficiency, and ensure test quality; based on the idea of ​​intelligent matching, automated test code can be intelligently generated; the preservation of test data facilitates subsequent updating and debugging of automated test code and reduces maintenance costs.

[0155] See also Figure 6 , shows a schematic diagram of main modules of an automatic test code generation device 600 provided in an embodiment of the present invention, including:

[0156] The data collection module 601 is used to determine the interface corresponding to the test instruction in the target application, and collect the test data of the interface during the test process based on the probe corresponding to the target application;

[0157] The code generation module 602 is used to generate an automated test code corresponding to the interface according to a template and test data corresponding to the target application during the interface testing process.

[0158] In the implementation device of the present invention, the probe is generated based on the bytecode enhancement method;

[0159] The data acquisition module 601 is used to: add predetermined code to the test code of the interface based on the probe; run the test code after the interface is changed, and obtain the input parameters, output parameters and parameter types of the interface during the test process based on a predetermined reflection method.

[0160] In the implementation device of the present invention, the data acquisition module 601 is used to: receive a data deletion instruction, extract test data corresponding to the data deletion instruction, and perform a deletion operation on the extracted test data.

[0161] In the implementation device of the present invention, the code generation module 602 is also used for:

[0162] Based on a predetermined matching rule, when there is a matching interface corresponding to the interface, the automated test code corresponding to the matching interface is used as the automated test code corresponding to the interface; wherein the matching interface does not include the interface; or

[0163] When there is no matching interface corresponding to the interface, an automated test code corresponding to the interface is generated according to the template and the test data.

[0164] In the implementation device of the present invention, the code generation module 602 is used to:

[0165] Obtaining description information of the interface, extracting keywords in the description information that meet a predetermined keyword extraction rule, and determining the interface corresponding to the keyword as a matching interface; and / or

[0166] Obtaining the parameter type and parameter quantity of the interface, and determining the interface corresponding to the parameter type and / or parameter quantity as the matching interface; and / or

[0167] Obtain the landing data of the interface, and use the interface in the same database table as the landing data as the matching interface; and / or

[0168] Determine the service type of the interface and use the interface of the same service type as the matching interface.

[0169] The implementation device of the present invention also includes a code change module 603 (not shown in the figure), which is used to: receive change instructions for the automated test code, change the test data based on the change data in the change instructions; and regenerate the automated test code corresponding to the interface based on the changed test data and the template.

[0170] In addition, the specific implementation content of the automatic test code generation device described in the embodiment of the present invention has been described in detail in the automatic test code generation method described above, so the repeated content will not be described again here.

[0171] The device provided in the embodiment of the present invention can greatly improve the coverage of automated test codes based on the idea of ​​automatically generating automated test codes while performing functional testing, and can assist in the efficiency of functional testing and ensure the quality of testing; based on the idea of ​​intelligent matching, automated test codes can be intelligently generated; the preservation of test data facilitates the subsequent updating and debugging of automated test codes and reduces maintenance costs.

[0172] Figure 7 An exemplary system architecture 700 is shown to which the automatic test code generation method or automatic test code generation apparatus according to the embodiment of the present invention can be applied.

[0173] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705 (just an example). Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0174] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0175] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0176] The server 705 may be a server that provides various services, such as a backend management server (only for example) that supports shopping websites browsed by users using the terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only for example) to the terminal device.

[0177] It should be noted that the automated test code generation method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the automated test code generation device is generally disposed in the server 705 .

[0178] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0179] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0180] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0181] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0182] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

[0183] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0184] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0185] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, they may be described as: a processor including a data acquisition module, a code generation module, and an acquisition module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the code generation module may also be described as an "automated test code generation module".

[0186] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:

[0187] Determine an interface corresponding to the test instruction in the target application, and collect test data of the interface during the test process based on a probe corresponding to the target application;

[0188] In the process of testing the interface, corresponding automated test code is generated according to the template and test data corresponding to the target application.

[0189] According to the technical solution of the embodiments of the present invention, based on the idea of ​​automatically generating automated test code while performing functional testing, the coverage of automated test code can be greatly improved, the efficiency of auxiliary functional testing can be assisted, and the test quality can be guaranteed; based on the idea of ​​intelligent matching, automated test code can be intelligently generated; the preservation of test data facilitates the subsequent updating and debugging of automated test code and reduces maintenance costs.

[0190] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for generating automated test code, characterized in that: include: Determine the interface corresponding to the test instruction in the target application, and collect the test data of the interface during the test process based on the probe corresponding to the target application; wherein the probe is generated based on the bytecode enhancement method, and the acquisition of the test data is intercepted and modified based on the interface code; for the modification of the interface code, only a part of the code is added, and the source code is not modified; During the test of the interface, based on a predetermined matching rule, when there is a matching interface corresponding to the interface, the automated test code corresponding to the matching interface is used as the automated test code corresponding to the interface; wherein the matching interface does not include the interface, and the predetermined matching rule includes one or more of the following: Acquire description information of the interface, extract keywords in the description information that meet a predetermined keyword extraction rule, and determine the interface corresponding to the keyword as a matching interface; Acquire the parameter type and parameter quantity of the interface, and determine the interface corresponding to the parameter type and / or the parameter quantity as a matching interface; Acquire the landing data of the interface, and use the interface in the same database table as the landing data as the matching interface; Determine the service type to which the interface belongs, and use the interface with the same service type as a matching interface; When there is no matching interface corresponding to the interface, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and the test data.

2. The method according to claim 1, characterized in that The collecting test data of the interface during the test process based on the probe corresponding to the target application includes: Based on the probe, adding predetermined code to the test code of the interface; Run the test code after the interface is changed, and obtain the input parameters, output parameters and parameter types of the interface during the test based on a predetermined reflection method.

3. The method according to claim 1, characterized in that After collecting the test data of the interface during the test process based on the probe corresponding to the target application, the method further includes: A data deletion instruction is received, and test data corresponding to the data deletion instruction is extracted to perform a deletion operation on the extracted test data.

4. The method according to claim 1, characterized in that: After the automatic test code corresponding to the interface is generated, the method further includes: receiving a change instruction for the automated test code, and changing the test data based on change data in the change instruction; Based on the changed test data and the template, the automated test code corresponding to the interface is regenerated.

5. An automated test code generation device, characterized in that: include: The data acquisition module is used to determine the interface corresponding to the test instruction in the target application, and based on the probe corresponding to the target application, collect the test data of the interface during the test process; wherein the probe is generated based on the bytecode enhancement method, and the acquisition of the test data is intercepted and modified based on the interface code; for the modification of the interface code, only a part of the code is added, and the source code is not modified; A code generation module is used for, during the test process of the interface, based on a predetermined matching rule, when there is a matching interface corresponding to the interface, using the automated test code corresponding to the matching interface as the automated test code corresponding to the interface; wherein the matching interface does not include the interface, and the predetermined matching rule includes one or more of the following: Acquire description information of the interface, extract keywords in the description information that meet a predetermined keyword extraction rule, and determine the interface corresponding to the keyword as a matching interface; Acquire the parameter type and parameter quantity of the interface, and determine the interface corresponding to the parameter type and / or the parameter quantity as a matching interface; Acquire the landing data of the interface, and use the interface in the same database table as the landing data as the matching interface; Determine the service type to which the interface belongs, and use the interface with the same service type as a matching interface; When there is no matching interface corresponding to the interface, an automated test code corresponding to the interface is generated according to a template corresponding to the target application and the test data.

6. The device according to claim 5, characterized in that The data acquisition module is used for: Based on the probe, adding predetermined code to the test code of the interface; Run the test code after the interface is changed, and obtain the input parameters, output parameters and parameter types of the interface during the test based on a predetermined reflection method.

7. The device according to claim 5, characterized in that The data acquisition module is used for: A data deletion instruction is received, and test data corresponding to the data deletion instruction is extracted to perform a deletion operation on the extracted test data.

8. The device according to claim 5, characterized in that Also includes code change modules for: receiving a change instruction for the automated test code, and changing the test data based on change data in the change instruction; Based on the changed test data and the template, the automated test code corresponding to the interface is regenerated.

9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.