Program interface testing method and device, equipment, medium and product
Through automated traversal and testing of interfaces, the problem of low manual testing efficiency is solved, accurate and efficient testing of program interfaces is achieved, and the reliability of interface testing is improved.
Patent Information
- Application Number
- CN202410390038.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-01
- Publication Date
- 2024-08-23
AI Technical Summary
In the existing technology, manual program interface testing is inefficient and prone to omissions or errors, resulting in extended testing cycles and affecting the reliability of interface testing.
By traversing the interface parameter data in the parameterless interface collection, it is determined whether the interface is the specified interface. If there is no test record, test data is generated based on the interface attribute information, and the test is performed. The test results are stored and the test report is generated to realize the program interface. of automated testing.
It improves the accuracy, efficiency and reliability of interface testing, reduces human errors and shortens the test cycle.
Smart Images

Figure CN118535451A
Abstract
Description
Background Art
[0002] At present, with the continuous development of software development, the complexity and scale of software products are increasing, and manual testing by testers / developers can no longer meet the needs.
[0003] In the related art, the interface testing of the program has at least the following problems:
[0004] 1. During manual testing, test cases are manually written to create test data and test libraries, and then tests are performed, and test reports are written based on test results and experience. If a more complex program is encountered, or the staff lacks testing experience, it will be difficult to conduct interface testing smoothly, which may lead to an indefinite extension of the test cycle, resulting in low test efficiency.
[0005] 2. During the manual testing process, omissions or inaccurate testing may occur, or erroneous testing may occur due to human fatigue, affecting the reliability of interface testing.
[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0007] The purpose of the present disclosure is to provide a method, apparatus, device, medium and product for testing a program interface, which are used to overcome the problems of low efficiency of interface testing caused by the limitations and defects of related technologies, at least to a certain extent.
[0008] According to a first aspect of an embodiment of the present disclosure, a method for testing a program interface is provided, comprising: traversing parameter data of an interface in a parameterless interface set to determine whether the interface is a specified interface, the specified interface including a newly added interface and / or a modified interface; searching a specified database to determine whether there is a test record for the specified interface; if it is determined that the test record does not exist, generating test data based on attribute information of the specified interface; testing the specified interface based on the test data, and storing the test result of the specified interface in the specified database; generating a test report based on the test result of the specified interface and the attribute information.
[0009] In an exemplary embodiment of the present disclosure, if it is determined that the test record does not exist, generating test data according to the attribute information of the specified interface includes:
[0010] If it is determined that the test record does not exist, storing the relevant data of the specified interface in a preset untested interface set;
[0011] Determine the interface type according to the attribute information of the interfaces in the untested interface set;
[0012] Generate and inject test data of corresponding type according to the interface type.
[0013] In an exemplary embodiment of the present disclosure, generating test data of a corresponding type according to the interface type and injecting the test data includes:
[0014] Determine whether the interface type is a bean type or a non-bean type;
[0015] If the interface type is determined to be a non-bean type, test data of the corresponding type of the interface is randomly generated and injected;
[0016] If it is determined that the interface type is a bean type, a query data table corresponding to the interface of the bean type is determined, and test data of a corresponding type is generated and injected according to whether specified data exists in the query data table.
[0017] In an exemplary embodiment of the present disclosure, if it is determined that the interface type is a bean type, a query data table corresponding to the interface of the bean type is determined, and test data of a corresponding type is generated and injected according to whether specified data exists in the query data table, including:
[0018] If it is determined that the interface type is a bean type, then determining a query data table corresponding to the interface of the bean type;
[0019] Determine whether the specified data exists in the query data table;
[0020] If it is determined that the specified data exists in the query data table, randomly extract data from the specified data as test data and inject it;
[0021] If it is determined that the specified data does not exist in the query data table, test data of the corresponding type is randomly generated and injected according to the data structure of the interface of the bean type.
[0022] In an exemplary embodiment of the present disclosure, before traversing the parameter data of the interfaces in the parameterless interface set, the method further includes:
[0023] Embed the interface information collection code into the program file corresponding to the interface;
[0024] Traversing the interface based on the interface information acquisition code to obtain attribute information of the interface, the attribute information including at least one of an interface name, an interface parameter list, an interface return type, and an interface annotation list;
[0025] The parameterless interface set is generated according to the attribute information.
[0026] In an exemplary embodiment of the present disclosure, traversing parameter data of an interface in a parameterless interface set to determine whether the interface is a designated interface, wherein the designated interface includes a newly added interface and / or a modified interface, includes:
[0027] Check whether the parameter data of the interfaces in the no-parameter interface set are empty;
[0028] If it is determined that the parameter data is empty, the interface is determined to be a non-designated interface, and the test result of the non-designated interface is stored in the tested interface set;
[0029] If it is determined that the parameter data is not empty, the interface is determined to be the designated interface, and the identifier of the designated interface is stored in the untested interface set, where the designated interface includes a newly added interface and / or a modified interface.
[0030] In an exemplary embodiment of the present disclosure, generating a test report according to the test result of the designated interface and the attribute information includes:
[0031] Parsing the interface name and interface parameter list included in the attribute information;
[0032] Determine the corresponding relationship between the test result and the interface parameter list;
[0033] A test report corresponding to each of the interface names is generated based on the corresponding relationship.
[0034] According to a second aspect of an embodiment of the present disclosure, a testing device for a program interface is provided, comprising:
[0035] A traversal module, configured to traverse parameter data of interfaces in a parameterless interface set to determine whether the interface is a designated interface, wherein the designated interface includes a newly added interface and / or a modified interface;
[0036] A retrieval module, configured to search a specified database for test records of the specified interface;
[0037] A generating module, configured to generate test data according to attribute information of a specified interface if it is determined that the test record does not exist;
[0038] A storage module, configured to test the designated interface based on the test data, and store the test result of the designated interface in the designated database;
[0039] The generating module is configured to generate a test report according to the test result of the designated interface and the attribute information.
[0040] According to a third aspect of the present disclosure, there is provided an electronic device, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the methods described above based on instructions stored in the memory.
[0041] According to a fourth aspect of the present disclosure, there is provided a computer-readable storage medium on which a program is stored, and when the program is executed by a processor, the program implements the test method of the program interface as described in any one of the above.
[0042] According to a fifth aspect of the present disclosure, there is provided a computer program product, comprising a computer program, characterized in that when the computer program is executed by a processor, the computer program implements a method for testing a program interface as described in any one of the above.
[0043] The disclosed embodiment traverses the parameter data of the interfaces in the parameterless interface set to determine whether the interface is a specified interface, to determine whether there is a new interface and / or a modified interface, and searches a specified database to determine whether there is a test record for the specified interface. If it is determined that the test record does not exist, test data is generated according to the attribute information of the specified interface, and the specified interface is tested based on the test data, and the test result of the specified interface is stored in the specified database. A test report is generated according to the test result of the specified interface and the attribute information. While realizing automatic testing of the program interface, local testing of the new interface and / or modified interface is realized, thereby comprehensively improving the accuracy, efficiency and reliability of the interface testing solution.
[0044] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0046] Figure 1 A schematic diagram showing an exemplary system architecture of a testing solution for a program interface of an embodiment of the present invention is shown;
[0047] Figure 2 is a flow chart of a method for testing a program interface in an exemplary embodiment of the present disclosure;
[0048] Figure 3 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0049] Figure 4 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0050] Figure 5 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0051] Figure 6 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0052] Figure 7 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0053] Figure 8 is a flow chart of another method for testing a program interface in an exemplary embodiment of the present disclosure;
[0054] Fig. 9 is a schematic diagram of an architecture of another program interface testing solution in an exemplary embodiment of the present disclosure;
[0055] Fig.10 is a flow chart of another program interface testing scheme in an exemplary embodiment of the present disclosure;
[0056] Fig.11 is a block diagram of a testing device for a program interface in an exemplary embodiment of the present disclosure;
[0057] Fig.12 is a block diagram of an electronic device in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0058] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0059] In addition, the accompanying drawings are only schematic diagrams of the present disclosure, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0060] Figure 1 A schematic diagram showing an exemplary system architecture of a testing solution for a program interface according to an embodiment of the present invention is shown.
[0061] like Figure 1 As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0062] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 105 may be a server cluster composed of multiple servers.
[0063] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens, including but not limited to smart phones, tablet computers, portable computers, desktop computers, etc.
[0064] In some embodiments, the program interface testing method provided by the embodiments of the present invention is generally executed by the server 105. Accordingly, the program interface testing device is generally set in the terminal device 103 (or the terminal device 101 or 102). In other embodiments, some terminals may have functions similar to those of the server device to execute the method.
[0065] The exemplary embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0066] Figure 2 is a flowchart of a method for testing a program interface in an exemplary embodiment of the present disclosure.
[0067] refer to Figure 2 , the testing methods of the program interface can include:
[0068] Step S202, traverse the parameter data of the interface in the no-parameter interface set to determine whether the interface is a designated interface, and the designated interface includes a newly added interface and / or a modified interface.
[0069] In an exemplary embodiment of the present disclosure, parameter data of the interface is recorded in a parameterless interface set. When an interface is added and / or modified, the parameter data is not zero. If the interface has not changed, the parameter data is zero. Based on this, the parameter data is traversed to determine whether there is a local state change of addition and / or modification in the interface, and then the interface test is performed based on the local state change, thereby improving the timeliness, efficiency and reliability of the interface test.
[0070] Step S204: searching in a designated database whether there is a test record of the designated interface.
[0071] In an exemplary embodiment of the present disclosure, after determining that there is a newly added interface and / or a modified interface, it is determined whether it has been tested by searching for a test record in a specified database. If there is a test record, the test result corresponding to the test record is used as the test interface of the specified result, and is fed back to the client, and the identifier of the specified interface is stored in the tested interface set. If there is no test record, the specified interface is determined to be an untested interface, and the identifier of the specified interface is stored in the untested interface set.
[0072] Step S206: If it is determined that the test record does not exist, generate test data according to the attribute information of the specified interface.
[0073] In an exemplary embodiment of the present disclosure, the attribute information includes an interface data structure, an interface name, an interface parameter list, an interface (return) type, an interface annotation, etc., and then test data is generated through the attribute information to perform interface testing in a timely manner.
[0074] In an exemplary embodiment of the present disclosure, the parameters of an interface generally refer to the input parameters of a method or function, or the variables declared in the method or function definition, which are used to receive the values, objects or other data passed by the caller, and specifically include the following types:
[0075] Basic data type parameters: These parameters are basic data types, such as integer (int), floating point (float), Boolean (boolean), character (char), etc.
[0076] Reference data type parameters: These parameters are reference data types, including class instances, arrays, interfaces, etc. By using reference data type parameters, more complex data structures can be passed.
[0077] Array parameter: An array parameter allows a group of data of the same type to be passed as a parameter, which can be an array of primitive data types or an array of reference data types.
[0078] Variable parameters: Variable parameters allow methods to accept a variable number of parameters. In Java, variable parameters are defined using ellipsis (...), for example, void methodName(int...nums).
[0079] Generic parameters: Generic parameters allow the use of parameterized types in methods or classes, thereby increasing the flexibility and reuse of code.
[0080] Callback function parameters: Some interfaces may require a function or method to be passed in as a parameter for calling in specific situations. Such parameters are called callback function parameters.
[0081] Configuration parameters: The interface may require the input of configuration parameters to control the behavior of the interface or set specific options.
[0082] Other custom type parameters: Based on specific needs, the interface can also contain other custom type parameters to meet specific business logic requirements.
[0083] Step S208: testing the designated interface based on the test data, and storing the test result of the designated interface in the designated database.
[0084] In an exemplary embodiment of the present disclosure, the designated interface is tested based on the test data, and the test results of the designated interface are stored in the designated database, thereby timely updating the test records. This makes it possible to determine at any time whether the designated interface has been tested based on the test records, thereby improving the efficiency and reliability of the test.
[0085] Step S210: Generate a test report according to the test result of the designated interface and the attribute information.
[0086] In an exemplary embodiment of the present disclosure, the test results are filled into the corresponding parameter items according to the attribute information, and then a test report of the specified interface is generated and fed back to the client, so that the client can obtain the results of the local test of the interface in a timely manner.
[0087] Based on the above-mentioned embodiments of the present disclosure, by traversing the parameter data of the interfaces in the parameterless interface set to determine whether the interface is a specified interface, to determine whether there is a new interface and / or a modified interface, and to search in a specified database whether there is a test record of the specified interface, if it is determined that the test record does not exist, then test data is generated according to the attribute information of the specified interface, and the specified interface is tested based on the test data, and the test result of the specified interface is stored in the specified database, and a test report is generated according to the test result of the specified interface and the attribute information, so that while realizing automatic testing of the program interface, local testing of the new interface and / or modified interface is realized, thereby comprehensively improving the accuracy, efficiency and reliability of the interface testing solution.
[0088] Below, each step of the program interface testing method is described in detail.
[0089] In an exemplary embodiment of the present disclosure, Figure 3 As shown, if it is determined that the test record does not exist, generating test data according to the attribute information of the specified interface includes:
[0090] Step S302: If it is determined that the test record does not exist, the relevant data of the designated interface is stored in a preset untested interface set.
[0091] Step S304: determining the interface type according to the attribute information of the interfaces in the untested interface set.
[0092] Step S306: Generate test data of a corresponding type according to the interface type and inject it.
[0093] In an exemplary embodiment of the present disclosure, Figure 4 As shown, generating test data of corresponding type according to the interface type and injecting the test data includes:
[0094] Step S402, determining whether the interface type is a bean type or a non-bean type.
[0095] Step S404: If it is determined that the interface type is a non-bean type, test data of a type corresponding to the interface is randomly generated and injected.
[0096] Step S406: If it is determined that the interface type is a bean type, a query data table corresponding to the bean type interface is determined, and test data of a corresponding type is generated and injected according to whether there is specified data in the query data table.
[0097] In an exemplary embodiment of the present disclosure, for example, the interface type is a simple JavaBean class, which contains the following data structure:
[0098]
[0099] You can generate a random User object by calling the generateRandomUser() method, where the name is randomly selected from the predefined name array, the age is randomly generated within the specified range, and the active status is randomly set to true or false, thus generating bean type test data.
[0100] In an exemplary embodiment of the present disclosure, Figure 5 As shown, if the interface type is determined to be a bean type, the query data table corresponding to the interface of the bean type is determined, and the corresponding type of test data is generated and injected according to whether the specified data exists in the query data table:
[0101] Step S502: If it is determined that the interface type is a bean type, a query data table corresponding to the interface of the bean type is determined.
[0102] Step S504, determining whether the specified data exists in the query data table.
[0103] Step S506: If it is determined that the designated data exists in the query data table, data from the designated data is randomly extracted and injected as test data.
[0104] Step S508: If it is determined that the specified data does not exist in the query data table, test data of the corresponding type is randomly generated according to the data structure of the bean type interface and injected.
[0105] In an exemplary embodiment of the present disclosure, by determining the data structure of the Bean type, including the type, value range, association relationship, etc. of each field, but not limited thereto, and then according to the data structure of the Bean, corresponding logic is written in the program to generate random parameters that meet the data structure requirements, so as to ensure that the generated random parameters meet the expected data format and constraints of the Bean.
[0106] In an exemplary embodiment of the present disclosure, if it is determined that the specified data exists in the query data table, data from the specified data is randomly extracted and injected as test data, or if it is determined that the specified data does not exist in the query data table, test data of the corresponding type is randomly generated and injected according to the data structure of the interface of the bean type. Two methods are provided for generating random test data corresponding to the bean type, thereby improving the reliability and accuracy of local testing of the bean type interface.
[0107] In an exemplary embodiment of the present disclosure, Figure 6As shown, before traversing the parameter data of the interfaces in the parameterless interface set, it also includes:
[0108] Step S602: embed the interface information collection code into the program file corresponding to the interface.
[0109] Step S604, traverse the interface based on the interface information acquisition code to obtain attribute information of the interface, wherein the attribute information includes at least one of an interface name, an interface parameter list, an interface return type, and an interface annotation list.
[0110] Step S606: Generate the parameterless interface set according to the attribute information.
[0111] In an exemplary embodiment of the present disclosure, the interface is traversed by the interface information collection code to obtain the attribute information of the interface, and the attribute information is filled into the parameterless interface set. For non-newly added or non-updated interfaces, the parameter values in the parameterless interface set remain zero. Once a new interface and / or an updated interface appears, the parameter values in the parameterless interface set are not zero.
[0112] In an exemplary embodiment of the present disclosure, Figure 7 As shown, traversing the parameter data of the interface in the parameterless interface set to determine whether the interface is a designated interface, the designated interface includes a newly added interface and / or a modified interface including:
[0113] Step S702, traverse the parameter data of the interfaces in the no-parameter interface set to see if they are empty.
[0114] Step S704: If it is determined that the parameter data is empty, the interface is determined to be a non-designated interface, and the test result of the non-designated interface is stored in the tested interface set.
[0115] Step S706: If it is determined that the parameter data is not empty, determine that the interface is the designated interface, and store the identifier of the designated interface into the untested interface set, wherein the designated interface includes a newly added interface and / or a modified interface.
[0116] In an exemplary embodiment of the present disclosure, Figure 8 As shown, generating a test report according to the test result of the specified interface and the attribute information includes:
[0117] Step S802: parsing the interface name and interface parameter list included in the attribute information.
[0118] Step S804: determine the correspondence between the test result and the interface parameter list.
[0119] Step S806: Generate a test report corresponding to each of the interface names based on the corresponding relationship.
[0120] In an exemplary embodiment of the present disclosure, Fig. 9 As shown, a program interface test architecture 900 is provided, including a data collection module, an interface analysis strategy module, a parameter simulation strategy module, an automatic test module and a client 902. The specific implementation of the program interface test solution is as follows:
[0121] (1) Data collection module: embedded in the program, traverses the program interface based on the software program source code to obtain information such as interface name, interface parameter list, interface return type, interface annotation, etc.
[0122] (2) Analysis strategy module: determines whether the collected interface data needs to be tested. If necessary, it further determines which specific interfaces need to be tested.
[0123] (3) Parameter simulation strategy module: Parameter simulation is performed by judging the parameter types of all test interfaces. If the parameter type is a common parameter, random parameter simulation of the corresponding data type is performed. If the parameter type is a Bean type, a database query is performed. If there is data, a random parameter is taken out and injected to form simulated data. If there is no data, random parameter simulation is continued according to the internal data structure of the Bean.
[0124] (4) Automatic test module: Automatically test the interface through simulated test data, generate a test report after the test is completed, and save all the test data to the database, which maintains a test interface table, a test data table, and a test result table, etc., but is not limited to these;
[0125] Among them, the automatic learning mode is composed of the interface analysis strategy module and the parameter simulation strategy module.
[0126] In an exemplary embodiment of the present disclosure, Fig.10 As shown, a test process of a program interface is provided, including:
[0127] Step S1002, collect interface information to form a parameterless interface set, specifically by embedding the dependent files of the software program into the source code, traversing the program interface to obtain the interface name, interface parameter list, interface return type, interface annotation list and other information to form a parameterless interface set.
[0128] Step S1004, execute analysis strategy 1, specifically traverse the parameterless interface set to determine whether the interface has been tested, if so, execute step S1008, if not, execute step S1006, that is, enter the automatic learning mode based on the generated parameterless interface set, and create a tested interface set and an untested interface set.
[0129] Specifically, the parameterless interface collection is traversed and the test interface table is queried according to the interface parameter name, return type, and parameter list. If it exists, it means it has been tested. The test report will be obtained through the corresponding identifier and stored in the tested interface collection. If it does not exist, it will be stored in the untested interface collection.
[0130] Step S1006, storing the interface data into the untested interface set.
[0131] Step S1008, obtaining the measured results and storing them in the measured interface set.
[0132] Step S1010, executing analysis strategy 2, that is, determining whether all interfaces tested this time are tested interfaces, if so, executing step S1008, if not, executing step S1006.
[0133] Step S1012, executing the parameter simulation strategy, that is, traversing the unmeasured interface set, and generating interface parameters of the unmeasured interface through the following parameter simulation strategy.
[0134] Step S1014, generating random data for injection for common data types. If the parameter is a common data type, randomly generating corresponding type data and injecting it.
[0135] Step S1016, if the parameter is of Bean type, find the corresponding data table according to the type, query the data in the data table, randomly extract data and inject it. If there is no corresponding data, randomly generate corresponding type data according to the internal data structure of the type and inject it.
[0136] Step S1018, perform automatic testing based on the untested interface set and the corresponding parameter data and store them in the tested interface set. After all interfaces are tested, the interface information collected in this test, the generated parameter data, and the interface test results are stored in the database for the next test.
[0137] Step S1020, generating a test report based on the interface name, parameter list, test results and other data of the tested interface set.
[0138] In an exemplary embodiment of the present disclosure, another program interface testing solution is provided, including:
[0139] If it is determined that a software program needs interface testing, the collection module will first read all interfaces of the software program as test cases, including the login interface, the interface for viewing order information, the interface for viewing personal information, etc.
[0140] Furthermore, the database of the test interface is queried to determine whether there is data about the login interface, the interface for viewing order information, and the interface for viewing personal information.
[0141] Furthermore, the last test result is obtained from the test result table through the information of the login interface, and stored in the tested interface set.
[0142] Furthermore, two test cases, namely, the order information interface and the personal information interface, are checked and stored in the untested interface set.
[0143] Furthermore, check whether there is any data in the untested interface set. If there is no data, it means that there are no new / modified interfaces in this test, and the test will end directly, and the last test result report will be output. If there is data, it will enter the parameter simulation strategy module and check the order information interface and personal information interface data.
[0144] Furthermore, the parameter simulation strategy module will start learning and generating according to the test data required by these two interfaces. For example, the interface for viewing order information usually requires user information and query date range information. Usually, user information belongs to the parameter of Bean type, and Bean type parameter can be read by reading interface information.
[0145] Furthermore, the Bean type parameter usually corresponds to a table in the database. At this time, the database will be directly queried to see whether there is user data. If there is, a piece of data will be randomly extracted. If not, a piece of data will be created based on the user information and a random number of the corresponding type. The random number can be determined using the random number method of the String type or the random number method of the Int type in Java.
[0146] Furthermore, for common Date type data such as date range, the Date random number generation in Java will be used directly. After the generation is completed, the interface information and test data will be combined to initiate a request to the interface and record the results until all interfaces are tested. A test report is generated and the test data is stored in the database.
[0147] Based on the above embodiments, the program interface testing solution disclosed in the present invention achieves at least the following technical effects:
[0148] (1) Determine whether an interface needs to be tested through interface analysis strategy, and implement local testing of newly added / modified interfaces, thus reducing the test cycle and saving resources.
[0149] (2) Test data can be simulated through parameter simulation strategies to automatically generate test data without creating test data and test libraries, thus reducing human errors and labor costs.
[0150] Corresponding to the above method embodiments, the present disclosure also provides a testing device for a program interface, which can be used to execute the above method embodiments.
[0151] Fig.11 It is a block diagram of a testing device for a program interface in an exemplary embodiment of the present disclosure.
[0152] Referring to Figure 1100, a testing device 1100 for a program interface may include:
[0153] The traversal module 1102 is configured to traverse the parameter data of the interfaces in the parameterless interface set to determine whether the interface is a designated interface, where the designated interface includes a newly added interface and / or a modified interface.
[0154] The search module 1104 is configured to search in a specified database whether there is a test record of the specified interface.
[0155] The generating module 1106 is configured to generate test data according to the attribute information of the specified interface if it is determined that the test record does not exist.
[0156] The storage module 1108 is configured to test the designated interface based on the test data and store the test result of the designated interface in the designated database.
[0157] The generating module 1106 is configured to generate a test report according to the test result of the designated interface and the attribute information.
[0158] In an exemplary embodiment of the present disclosure, the generating module 1106 is further configured to:
[0159] If it is determined that the test record does not exist, storing the relevant data of the specified interface in a preset untested interface set;
[0160] Determine the interface type according to the attribute information of the interfaces in the untested interface set;
[0161] Generate and inject test data of corresponding type according to the interface type.
[0162] In an exemplary embodiment of the present disclosure, the generating module 1106 is further configured to:
[0163] Determine whether the interface type is a bean type or a non-bean type;
[0164] If the interface type is determined to be a non-bean type, test data of the corresponding type of the interface is randomly generated and injected;
[0165] If it is determined that the interface type is a bean type, a query data table corresponding to the interface of the bean type is determined, and test data of a corresponding type is generated and injected according to whether specified data exists in the query data table.
[0166] In an exemplary embodiment of the present disclosure, the generating module 1106 is further configured to:
[0167] If it is determined that the interface type is a bean type, then determining a query data table corresponding to the interface of the bean type;
[0168] Determine whether the specified data exists in the query data table;
[0169] If it is determined that the specified data exists in the query data table, randomly extract data from the specified data as test data and inject it;
[0170] If it is determined that the specified data does not exist in the query data table, test data of the corresponding type is randomly generated and injected according to the data structure of the interface of the bean type.
[0171] In an exemplary embodiment of the present disclosure, the generating module 1106 is further configured to:
[0172] Embed the interface information collection code into the program file corresponding to the interface;
[0173] Traversing the interface based on the interface information acquisition code to obtain attribute information of the interface, the attribute information including at least one of an interface name, an interface parameter list, an interface return type, and an interface annotation list;
[0174] The parameterless interface set is generated according to the attribute information.
[0175] In an exemplary embodiment of the present disclosure, the traversal module 1102 is further configured to:
[0176] Check whether the parameter data of the interfaces in the no-parameter interface set are empty;
[0177] If it is determined that the parameter data is empty, the interface is determined to be a non-designated interface, and the test result of the non-designated interface is stored in the tested interface set;
[0178] If it is determined that the parameter data is not empty, the interface is determined to be the designated interface, and the identifier of the designated interface is stored in the untested interface set, where the designated interface includes a newly added interface and / or a modified interface.
[0179] In an exemplary embodiment of the present disclosure, the generating module 1106 is configured to:
[0180] Parsing the interface name and interface parameter list included in the attribute information;
[0181] Determine the corresponding relationship between the test result and the interface parameter list;
[0182] A test report corresponding to each of the interface names is generated based on the corresponding relationship.
[0183] Since the functions of the device 1100 have been described in detail in the corresponding method embodiments, the present disclosure will not elaborate on them here.
[0184] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0185] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0186] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".
[0187] Refer to the following Fig.12 The electronic device 1200 according to this embodiment of the present invention is described. Fig.12 The electronic device 1200 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.
[0188] like Fig.12 As shown, the electronic device 1200 is in the form of a general computing device. The components of the electronic device 1200 may include but are not limited to: at least one processing unit 1210, at least one storage unit 1220, and a bus 1230 connecting different system components (including the storage unit 1220 and the processing unit 1210).
[0189] The storage unit stores program codes, which can be executed by the processing unit 1210, so that the processing unit 1210 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 1210 can perform the method shown in the embodiment of the present disclosure.
[0190] The storage unit 1220 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 12201 and / or a cache storage unit 12202 , and may further include a read-only storage unit (ROM) 12203 .
[0191] The storage unit 1220 may also include a program / utility 12204 having a set (at least one) of program modules 12205, such program modules 12205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0192] Bus 1230 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0193] The electronic device 1200 may also communicate with one or more external devices 1240 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1200, and / or communicate with any device that enables the electronic device 1200 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1250. Furthermore, the electronic device 1200 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 1260. As shown, the network adapter 1260 communicates with other modules of the electronic device 1200 via a bus 1230. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0194] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0195] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.
[0196] The program product for implementing the above method according to an embodiment of the present invention can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0197] Among them, the readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can 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 readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable 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.
[0198] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0199] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0200] In an exemplary embodiment of the present disclosure, a computer program product is also provided, which can be loaded or stored in any combination of one or more readable media, and can be written in any combination of one or more programming languages to perform the program code of the present invention, including object-oriented programming languages such as Java, C++, etc., and also conventional procedural programming languages such as "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or completely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0201] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0202] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are to be considered exemplary only, and the true scope and concept of the present disclosure are indicated by the claims.
Claims
1. A method for testing a program interface, characterized in that: include: Traversing the parameter data of the interfaces in the parameterless interface set to determine whether the interface is a designated interface, wherein the designated interface includes a newly added interface and / or a modified interface; Searching in a specified database whether there is a test record of the specified interface; If it is determined that the test record does not exist, generating test data according to the attribute information of the specified interface; Testing the designated interface based on the test data, and storing the test result of the designated interface in the designated database; A test report is generated according to the test result of the designated interface and the attribute information.
2. The method for testing a program interface according to claim 1, wherein: If it is determined that the test record does not exist, generating test data according to the attribute information of the specified interface includes: If it is determined that the test record does not exist, storing the relevant data of the specified interface in a preset untested interface set; Determine the interface type according to the attribute information of the interfaces in the untested interface set; Generate and inject test data of corresponding type according to the interface type.
3. The method for testing a program interface according to claim 1, wherein: Generate test data of corresponding type according to the interface type and inject it into: Determine whether the interface type is a bean type or a non-bean type; If the interface type is determined to be a non-bean type, test data of the corresponding type of the interface is randomly generated and injected; If it is determined that the interface type is a bean type, a query data table corresponding to the interface of the bean type is determined, and test data of a corresponding type is generated and injected according to whether specified data exists in the query data table.
4. The method for testing a program interface according to claim 1, wherein: If it is determined that the interface type is a bean type, then determining the query data table corresponding to the interface of the bean type, and generating and injecting test data of the corresponding type according to whether the specified data exists in the query data table includes: If it is determined that the interface type is a bean type, then determining a query data table corresponding to the interface of the bean type; Determine whether the specified data exists in the query data table; If it is determined that the specified data exists in the query data table, randomly extract data from the specified data as test data and inject it; If it is determined that the specified data does not exist in the query data table, test data of the corresponding type is randomly generated and injected according to the data structure of the interface of the bean type.
5. The method for testing a program interface according to claim 1, wherein: Before traversing the parameter data of the interfaces in the parameterless interface set, it also includes: Embed the interface information collection code into the program file corresponding to the interface; Traversing the interface based on the interface information acquisition code to obtain attribute information of the interface, the attribute information including at least one of an interface name, an interface parameter list, an interface return type, and an interface annotation list; The parameterless interface set is generated according to the attribute information.
6. The method for testing a program interface according to claim 1, wherein: Traversing the parameter data of the interfaces in the no-parameter interface set to determine whether the interface is a designated interface, wherein the designated interface includes a newly added interface and / or a modified interface including: Check whether the parameter data of the interfaces in the no-parameter interface set are empty; If it is determined that the parameter data is empty, the interface is determined to be a non-designated interface, and the test result of the non-designated interface is stored in the tested interface set; If it is determined that the parameter data is not empty, the interface is determined to be the designated interface, and the identifier of the designated interface is stored in the untested interface set, where the designated interface includes a newly added interface and / or a modified interface.
7. The method for testing a program interface according to claim 1, wherein: Generating a test report according to the test result of the designated interface and the attribute information includes: Parsing the interface name and interface parameter list included in the attribute information; Determine the corresponding relationship between the test result and the interface parameter list; A test report corresponding to each of the interface names is generated based on the corresponding relationship.
8. A testing device for a program interface, characterized in that: include: A traversal module, configured to traverse parameter data of interfaces in a parameterless interface set to determine whether the interface is a designated interface, wherein the designated interface includes a newly added interface and / or a modified interface; A retrieval module, configured to search a specified database for test records of the specified interface; A generating module, configured to generate test data according to attribute information of a specified interface if it is determined that the test record does not exist; A storage module, configured to test the designated interface based on the test data, and store the test result of the designated interface in the designated database; The generating module is configured to generate a test report according to the test result of the designated interface and the attribute information.
9. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, the processor being configured to execute the program interface testing method according to any one of claims 1 to 7 based on instructions stored in the memory.
10. A computer-readable storage medium having a program stored thereon, wherein when the program is executed by a processor, the program implements the method for testing a program interface according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the method for testing the program interface according to any one of claims 1 to 7.
