Interface test script generation method and device, storage medium and electronic device
The API script generator automatically generates API test scripts, solving the problem of low efficiency in manually writing API test scripts and achieving efficient and accurate API test script generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- QINGDAO HAIER TECH
- Filing Date
- 2021-09-26
- Publication Date
- 2026-05-29
AI Technical Summary
Manually writing test scripts for interfaces in software projects is inefficient and makes it difficult to guarantee quality.
The API script generator obtains the database update time of the target project, acquires the API dataset, generates API test scripts, and uses the target algorithm to automatically generate API test scripts, ensuring timely data updates and accuracy.
It improves the efficiency and accuracy of writing interface test scripts, reduces the steps of manual writing, and ensures the quality of interface test scripts.
Smart Images

Figure CN115878443B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communications, and more specifically, to a method and apparatus for generating interface test scripts, a storage medium, and an electronic device. Background Technology
[0002] With the development of modern society, a software project is usually quite large and is used to implement multiple functions. Traditional development thinking is usually procedural development, but this often leads to high coupling between different functional codes. Therefore, in order to reduce the coupling between different functional codes and to allow different users to write different functional codes, modern software development is usually interface-oriented development. This can improve project development efficiency and reduce the coupling between different functional codes.
[0003] However, some problems may arise during the development of APIs. Different developers may be developing the same project at the same time, which may result in the API data in the database not being the latest API data for that project. In addition, test scripts for traditional APIs are written manually by testers. However, due to the large number of fields involved in the API, data omissions may occur when writing scripts manually, and the quality cannot be guaranteed.
[0004] For related technologies, testers manually write test scripts for interfaces in software projects, which leads to low efficiency in writing interface scripts, and no effective solution has yet been proposed.
[0005] Therefore, it is necessary to improve the relevant technology to overcome the aforementioned defects. Summary of the Invention
[0006] This invention provides a method and apparatus for generating interface test scripts, a storage medium, and an electronic device, to at least solve the problem of low efficiency in writing interface scripts for software projects due to testers manually writing them.
[0007] According to one aspect of the present invention, a method for generating interface test scripts is provided, comprising: obtaining a generation instruction, wherein the generation instruction is used to instruct the generation of interface test scripts for a target project, the target project being implemented by code; accessing a database of the target project according to the generation instruction to obtain an update time of the database, wherein the update time is used to indicate the time when data in the database changes; and, if the time interval between the update time and the current time is less than a preset threshold, obtaining a first interface dataset from the database of the target project, and generating an interface test script for each interface in the target project according to the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0008] Further, generating an interface test script for each interface in the target project based on the first interface dataset includes: obtaining interface data for each interface in the target project from the first interface dataset; and generating an interface test script for each interface based on the interface data for each interface.
[0009] Further, generating an interface test script for each interface based on the interface data of each interface includes: obtaining a target algorithm, wherein the target algorithm is used to generate an interface test script based on the interface data; and generating an interface test script for each interface from the interface data of each interface using the target algorithm.
[0010] Further, after accessing the database of the target project according to the generation instruction to obtain the update time of the database, the method further includes: if it is determined that the time interval between the update time and the current time is greater than a preset threshold, obtaining the second interface dataset saved by the target project at the current time, wherein the second interface dataset contains interface data corresponding to multiple interfaces in the target project saved by the target project at the current time; and generating an interface test script for each interface in the target project according to the second interface dataset.
[0011] Further, obtaining the second interface dataset saved by the target project at the current time includes: sending a request instruction to the target plugin and receiving an interface file sent by the target plugin in response to the request instruction, wherein the interface file is a file generated by the target plugin after the target object configures the target plugin for the target project; parsing the interface file to obtain the second interface dataset saved by the target project at the current time.
[0012] Furthermore, after generating the interface test script for each second interface in the target project based on the second interface dataset, the method further includes: obtaining a first interface dataset from the database of the target project, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project; if it is determined that there is a difference between the first interface dataset and the second interface dataset, replacing the first interface dataset in the database with the second interface dataset, and determining the update time of the database.
[0013] Further, accessing the database of the target project according to the generation instruction includes: determining the project identifier of the target project according to the generation instruction; and accessing the database of the target project corresponding to the project identifier.
[0014] According to one aspect of the present invention, an interface test script generation apparatus is also provided, comprising: a first acquisition module, configured to acquire a generation instruction, wherein the generation instruction is used to instruct the generation of an interface test script for a target project, the target project being implemented through code; a second acquisition module, configured to access the database of the target project according to the generation instruction to acquire the update time of the database, wherein the update time is used to indicate the time when data in the database changes; and a generation module, configured to, when the time interval between the update time and the current time is less than a preset threshold, acquire a first interface dataset from the database of the target project, and generate an interface test script for each interface in the target project according to the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0015] According to another aspect of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer program, wherein the computer program is configured to execute the above-described method for generating the interface test script at runtime.
[0016] According to another aspect of the present invention, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the interface test script generation method through the computer program.
[0017] This invention addresses the problem of low efficiency in writing interface scripts for software projects. By retrieving the interface script generator from the database and automatically generating interface test scripts for each interface, the efficiency and accuracy of writing interface test scripts for the target project are improved. When the interface script generator receives a generation instruction, it accesses the target project's database to obtain the database's update time. If the time interval between the database's update time and the current time is less than a preset threshold, it retrieves a first interface dataset from the target project's database and generates an interface test script for each interface based on the dataset. Attached Figure Description
[0018] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with the description thereof, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0019] Figure 1This is a hardware structure block diagram of a computer terminal for the interface test script generation method according to an embodiment of the present invention.
[0020] Figure 2 This is a flowchart (a) of a method for generating interface test scripts according to an embodiment of the present invention;
[0021] Figure 3 This is a flowchart (II) of the method for generating interface test scripts according to an embodiment of the present invention;
[0022] Figure 4 This is a timing diagram of a method for generating interface test scripts according to an embodiment of the present invention;
[0023] Figure 5 This is a structural block diagram of an interface test script generation device according to an embodiment of the present invention. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0026] The methods and embodiments provided in this application can be executed on a computer terminal or similar computing device. Taking running on a computer terminal as an example, Figure 1 This is a hardware structure block diagram of a computer terminal for the interface test script generation method according to an embodiment of the present invention. For example... Figure 1 As shown, a computer terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor unit (MPU) or a programmable logic device (PLD)) and a memory 104 for storing data are also shown. In one exemplary embodiment, the computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 Equivalent functions or ratios shown Figure 1 The functions shown have more different configurations.
[0027] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the interface test script generation method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0028] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider for the computer terminal. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0029] It should be noted that, in order to address the problem of low efficiency and accuracy in writing interface scripts due to manually written interface data, this application provides a method for automatically generating interface test scripts based on interface data. In an exemplary embodiment, this can be implemented using an interface script generator, wherein the interface script generator is implemented by developers writing code based on the target algorithm.
[0030] This embodiment provides a method for generating interface test scripts. Figure 2 This is a flowchart (I) of a method for generating interface test scripts according to an embodiment of the present invention, which includes the following steps:
[0031] Step S202: Obtain generation instructions, wherein the generation instructions are used to instruct the generation of interface test scripts for the target project, and the target project is implemented through code;
[0032] It should be noted that the technical solution of this application can be applied in an interface script generator. The interface script generator can determine the project identifier of the target project according to the generation instruction, and then the interface script generator accesses the database of the target project corresponding to the project identifier.
[0033] Step S204: Access the database of the target project according to the generation instruction to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes;
[0034] Step S206: If the time interval between the update time and the current time is less than a preset threshold, obtain the first interface dataset from the database of the target project, and generate an interface test script for each interface in the target project based on the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0035] It's important to note that to prevent errors in the project interface test scripts generated by the interface script generator due to prolonged periods without updates to the interface dataset in the database, it's necessary to check the database update time. The interface dataset is only retrieved from the database if the update time is less than a preset threshold. This preset threshold is set for the target object. For target projects under development, where code changes are frequent, the preset threshold can be set to 10 minutes, 20 minutes, etc. For delivered target projects, the preset threshold can be set to 3 hours, 6 hours, etc.
[0036] Through the above steps, when the interface script generator receives the generation instruction, it accesses the target project's database according to the instruction to obtain the database's update time. If the time interval between the database's update time and the current time is less than a preset threshold, it retrieves the first interface dataset from the target project's database and generates interface test scripts for each interface in the target project based on the first interface dataset. This technical solution solves the problem of low efficiency in writing interface scripts for software projects due to testers manually writing them. Furthermore, it can automatically generate interface test scripts for each interface in the target project by retrieving the target project's interface dataset from the database, thus improving the efficiency and accuracy of writing interface project scripts for the target project.
[0037] It should be noted that the above-mentioned generation of interface test scripts for each interface in the target project based on the first interface dataset can be achieved in the following way: obtain the interface data of each interface in the target project from the first interface dataset; generate the interface test script for each interface based on the interface data of each interface.
[0038] In other words, the first interface dataset contains interface data for multiple interfaces of the target project. The interface script generator can then generate an interface test script for each interface based on the interface data of each interface. Specifically, the interface script generator needs to obtain a target algorithm, which is used to generate interface test scripts based on the interface data. The interface script generator then uses the target algorithm to generate the interface test script for each interface from the interface data of each interface.
[0039] It should be noted that since there is a fixed algorithm for generating interface test scripts from interface test data, users can convert the steps of manually writing test scripts into a target algorithm that can be executed by a machine, and then send the target algorithm to the interface script generator so that the interface script generator can use the target algorithm to generate an interface test script for each interface based on the interface data of each interface.
[0040] It should be noted that if it is determined that the interface script generator accesses the database and the time interval between the database update time and the current time is greater than a preset threshold, then the second interface dataset saved by the target project at the current time is obtained. The second interface dataset contains interface data corresponding to multiple interfaces in the target project that are saved by the target project at the current time. An interface test script for each interface in the target project is generated based on the second interface dataset.
[0041] Understandably, if the database update time is the 1st of this month, while the current time is the 3rd of this month, it indicates that the database has not been updated for a long time. The reason for this could be a system failure, a failure to save the changes by the developers, or the target project not having undergone any changes. Because the database has not been updated for a long time, the interface data of the target project at the current time may differ from the interface data in the database. If the interface data from the database is used in this case, the interface test scripts generated by the interface script generator may contain errors. Therefore, the interface script generator needs to obtain a second interface dataset saved by the target project at the current time, and then generate interface test scripts for each interface in the target project based on this second interface dataset.
[0042] Optionally, the interface script generator can obtain the second interface dataset in the following ways: send a request instruction to the target plugin and receive the interface file sent by the target plugin in response to the request instruction, wherein the interface file is a file generated by the target plugin after the target object configures the target plugin for the target project; parse the interface file to obtain the second interface dataset saved by the target project at the current time.
[0043] It's important to note that in related technologies, the development team collaboratively maintains a single online API file. Each time the API is modified, the corresponding file is updated, leading to a lack of real-time updates and inconsistencies between the APIs in the target project and the API file itself. To address this issue, the target entity (the developers of the target project) configures a target plugin for the target project; this plugin can be a Swagger plugin. This plugin automatically generates the target project's API file based on the latest code. Subsequently, the API script generator can obtain the target project's API file and, by parsing it, obtain the target project's second API dataset.
[0044] In an optional embodiment, after generating the interface test script for each second interface in the target project based on the second interface dataset, the interface script generator also needs to obtain the first interface dataset from the database of the target project, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project; if it is determined that there is a difference between the first interface dataset and the second interface dataset, the first interface dataset in the database is replaced with the second interface dataset, and the update time of the database is determined.
[0045] In other words, there are two scenarios: one is that the target project has indeed remained unchanged for a long time, and the other is that the target project has changed, but the interface dataset has not been synchronized to the database. To correct the second scenario, the interface script generator also needs to obtain the first interface dataset from the database and then compare it with the second interface dataset. If there is no difference, it means that the target project has indeed not been updated for a long time. If there is a difference, it means that the target project's interface dataset has not been synchronized to the database. Therefore, the interface script generator needs to replace the first interface dataset in the database with the second interface dataset and redetermine the database update time.
[0046] It should be noted that the embodiments described above are merely some embodiments of the present invention, and not all embodiments. For better understanding, the above process will be described below in conjunction with embodiments, but this is not intended to limit the technical solutions of the embodiments of the present invention. Specifically:
[0047] In an optional embodiment, the interface script generator further obtains a third interface dataset of the target project, the target project containing multiple first interfaces at a first time, the third interface dataset containing: interface data for each first interface; the interface data includes at least one of the following: interface variables, interface constants, and interface functions;
[0048] The interface script generator replaces the fourth interface dataset stored in the database with the third interface dataset. The fourth interface dataset contains interface data for each of a plurality of second interfaces at a second time. The plurality of second interfaces are the interfaces included in the target project at the second time. The second time is earlier than the first time.
[0049] It should be noted that since a target project may be developed by multiple developers, each developer needs to update the latest interface data of the project to the database after writing the interface.
[0050] Upon receiving a script generation instruction, the interface test script retrieves the third interface dataset from the database and generates an interface test script for each first interface based on the third interface dataset.
[0051] To better understand the above steps, the following is a detailed explanation: The API script generator continuously listens for the latest API dataset of the target project sent by different developers at the current time (equivalent to the first time mentioned above). It then replaces the historical API dataset of the target project at a historical time (equivalent to the second time mentioned above) in the database with the latest API dataset of the target project. If the developer instructs the API script generator to generate API test scripts for the target project at this time, the API script generator needs to retrieve the API data of multiple APIs of the target project from the database at the current time, and then generate API test scripts for each of the multiple APIs of the target project at the current time.
[0052] After the interface script generator obtains the third interface dataset, it will retrieve the fourth interface dataset of the target project from the database based on the third interface dataset; the third interface dataset and the fourth interface dataset will be compared to replace the fourth interface dataset in the database with the third interface dataset.
[0053] In other words, the API script generator needs to replace the historical API dataset (equivalent to the second API dataset) of the target project in the database with the new API dataset (equivalent to the first API dataset).
[0054] Optionally, comparing the third interface dataset and the fourth interface dataset to replace the fourth interface dataset in the database with the third interface dataset can be achieved in the following ways: If the name of a third interface in the third interface dataset is different from that of every fourth interface, save the interface data of the third interface to the fourth interface dataset in the database, wherein the first interface includes the third interface; If the name of a fourth interface in the third interface dataset is the same as that of a fifth interface in the fourth interface dataset, replace the interface data of the fifth interface in the database with the interface data of the fourth interface, wherein the first interface includes the fourth interface, and the second interface includes the fifth interface; If the name of a sixth interface in the fourth interface dataset is different from that of every first interface in the third interface dataset, delete the interface data of the sixth interface from the fourth interface dataset, wherein the second interface includes the sixth interface.
[0055] To better understand, the following is a detailed explanation: If the interface names of multiple interfaces in the third interface dataset are: Interface A, Interface B, and Interface C; and the interface names of multiple interfaces in the fourth interface dataset are: Interface B, Interface C, and Interface D. The interface script generator determines that Interface A does not exist in the fourth interface dataset, so it saves the interface data of Interface A to the fourth interface dataset in the database. The interface script generator then determines that Interface D does not exist in the third interface dataset, possibly because the developer deleted Interface D. Therefore, the interface script generator needs to delete the interface data of Interface D from the fourth interface dataset in the database. Furthermore, the interface script generator needs to compare the interfaces with the same names in the third and fourth interface datasets to see if the interface data is the same. If they are different, the interface data corresponding to the interface in the fourth interface dataset needs to be replaced with the data from the third interface dataset.
[0056] It should be noted that the interface script generator can also directly generate corresponding interface test scripts based on the third interface dataset generated by the target plugin. However, since the target project is constantly changing, if the corresponding interface test script is generated directly every time the interface dataset generated by the target plugin is obtained, it will not correspond to the latest interfaces of the project. Therefore, the interface script generator needs to save the interface dataset generated by the target plugin in the database. After the target project is completed, the target object will send a script generation instruction to the interface script generator. Only then will the interface script generator retrieve the latest interface dataset from the database and generate the interface test script for the target project based on the latest interface dataset, so that the generated interface test script corresponds to the interfaces in the target project.
[0057] To better understand, Figure 3 This is a flowchart (II) of the interface test script generation method according to an embodiment of the present invention, illustrating the overall process of the interface script generator generating interface test scripts, specifically:
[0058] Step S302: After the target object configures the target plugin for the target project, the target plugin generates the interface file of the target project;
[0059] Step S304: The interface script generator parses the interface file and obtains the third interface dataset;
[0060] Step S306: Replace the fourth interface dataset in the database with the third interface dataset;
[0061] Step S308: Upon receiving the script generation instruction, retrieve the third interface dataset from the database and generate the interface test script corresponding to the target project.
[0062] The above steps solve the problem of mismatch between interfaces and interface files caused by developers' inability to maintain the target project's interface files in real time during the interface modification process. They also solve the problem of data omissions, low efficiency, and unreliable quality when testers manually write interface test scripts based on interface files.
[0063] Obviously, the embodiments described above are merely some embodiments of the present invention, and not all embodiments. To better understand the above method for generating interface test scripts, the process is described below with reference to embodiments, but this is not intended to limit the technical solutions of the embodiments of the present invention. Specifically:
[0064] In an optional embodiment, Figure 4 This is a timing diagram of a method for generating interface test scripts according to an embodiment of the present invention, which can be divided into the following steps:
[0065] Step 1: The developer (equivalent to the target object in the above example) configures the Swagger plugin (equivalent to the target plugin in the above example) for the target project and deploys the project to the server;
[0066] Step 2: Developers access the target project's api-doc address (e.g., http: / / localhost:8080 / demo / v2 / api-docs) to obtain the api-doc.json file (equivalent to the interface file in the above example);
[0067] Step 3: The developer sends the api-doc.json file to the API script generator;
[0068] Step 4: The API script generator parses the API-doc.json file to obtain the current API data of the project (equivalent to the third API dataset in the above embodiment);
[0069] Step 5: The interface script generator obtains the historical interface data of the corresponding project (equivalent to the fourth interface dataset in the above embodiment);
[0070] Step Six: The database returns the query results to the API script generator;
[0071] Step 7: The API script generator compares historical API data and adds / modifies / deletes API data for the target project in the database;
[0072] Step 8: Update the interface data in the database:
[0073] Step 9: Obtain the project interface script generation instruction sent by the target object (equivalent to the script generation instruction in the above embodiment);
[0074] Step 10: The API script generator queries the project's API data;
[0075] Step 10: The database returns the query results to the API script generator;
[0076] Step 11: The interface script generator generates an interface automation script (equivalent to the interface test script in the above embodiment) for the target object.
[0077] Furthermore, the technical solution described above in this embodiment of the invention automatically generates the project's interface documentation (equivalent to the interface file in the above embodiment) when developers add / modify project interfaces; this improves the efficiency of developers in maintaining interface documentation, while simplifying the operation of testers in writing interface test scripts through interface documentation, and delegating the generation of interface test scripts to the program; this enables the interface script generator to write interface test scripts in a strictly standardized manner, reducing data entry errors during the manual writing of interface test scripts.
[0078] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0079] This embodiment also provides an interface test script generation device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, hardware implementations, or a combination of software and hardware, are also possible and contemplated.
[0080] Figure 5 This is a structural block diagram of an interface test script generation apparatus according to an embodiment of the present invention, the apparatus comprising:
[0081] The first acquisition module 52 is used to acquire a generation instruction, wherein the generation instruction is used to instruct the generation of an interface test script for a target project, and the target project is implemented through code;
[0082] The second acquisition module 54 is used to access the database of the target project according to the generation instruction to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes;
[0083] The generation module 56 is used to obtain a first interface dataset from the database of the target project when the time interval between the update time and the current time is less than a preset threshold, and generate an interface test script for each interface in the target project based on the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0084] Through the aforementioned modules, when the interface script generator receives a generation instruction, it accesses the target project's database according to the instruction to obtain the database's update time. If the time interval between the database's update time and the current time is less than a preset threshold, it retrieves a first interface dataset from the target project's database and generates interface test scripts for each interface in the target project based on this dataset. This technical solution addresses the problem of low efficiency in writing interface scripts for software projects due to manual writing by testers. Furthermore, by retrieving the target project's interface dataset from the database and automatically generating interface test scripts for each interface in the target project based on this dataset, it improves the efficiency and accuracy of writing interface project scripts for the target project.
[0085] Optionally, the generation module 56 is further configured to obtain interface data for each interface in the target project from the first interface dataset; and generate an interface test script for each interface based on the interface data of each interface.
[0086] Optionally, the generation module 56 is further configured to obtain a target algorithm, wherein the target algorithm is configured to generate an interface test script based on the interface data; and to generate an interface test script for each interface by using the interface data of each interface through the target algorithm.
[0087] Optionally, the generation module 56 is further configured to, when determining that the time interval between the update time and the current time is greater than a preset threshold, obtain the second interface dataset saved by the target project at the current time, wherein the second interface dataset contains interface data corresponding to multiple interfaces in the target project saved by the target project at the current time; and generate an interface test script for each interface in the target project based on the second interface dataset.
[0088] Optionally, the generation module 56 is further configured to send a request instruction to the target plugin and receive an interface file sent by the target plugin in response to the request instruction, wherein the interface file is a file generated by the target plugin after the target object configures the target plugin for the target project; and parse the interface file to obtain the second interface dataset saved by the target project at the current time.
[0089] Optionally, the generation module 56 is further configured to obtain a first interface dataset from the database of the target project, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project; if it is determined that there is a difference between the first interface dataset and the second interface dataset, the first interface dataset in the database is replaced with the second interface dataset, and the update time of the database is determined.
[0090] The optional second acquisition module 54 is further configured to determine the project identifier of the target project according to the generation instruction; and access the database of the target project corresponding to the project identifier.
[0091] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.
[0092] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0093] S1, Obtain the generation instruction, wherein the generation instruction is used to instruct the generation of the interface test script of the target project, and the target project is implemented through code;
[0094] S2, access the database of the target project according to the generation instruction to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes;
[0095] S3, if the time interval between the update time and the current time is less than a preset threshold, obtain the first interface dataset from the database of the target project, and generate an interface test script for each interface in the target project based on the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0096] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0097] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0098] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0099] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0100] S1, Obtain the generation instruction, wherein the generation instruction is used to instruct the generation of the interface test script of the target project, and the target project is implemented through code;
[0101] S2, access the database of the target project according to the generation instruction to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes;
[0102] S3, if the time interval between the update time and the current time is less than a preset threshold, obtain the first interface dataset from the database of the target project, and generate an interface test script for each interface in the target project based on the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project.
[0103] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0104] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0105] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0106] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for generating interface test scripts, characterized in that, include: Obtain a generation instruction, wherein the generation instruction is used to instruct the generation of an interface test script for a target project, the target project being implemented through code; According to the generation instruction, access the database of the target project to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes; If the time interval between the update time and the current time is less than a preset threshold, a first interface dataset is obtained from the database of the target project, and an interface test script for each interface in the target project is generated based on the first interface dataset. The first interface dataset contains interface data corresponding to multiple interfaces in the target project, and the interface data includes at least one of the following: interface variables, interface constants, and interface functions. If the time interval between the update time and the current time is determined to be greater than a preset threshold, the second interface dataset saved by the target project at the current time is obtained, wherein the second interface dataset contains interface data corresponding to multiple interfaces in the target project saved at the current time; an interface test script for each interface in the target project is generated based on the second interface dataset; a first interface dataset is obtained from the database of the target project, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project; if it is determined that there is a difference between the first interface dataset and the second interface dataset, the first interface dataset in the database is replaced with the second interface dataset, and the update time of the database is determined.
2. The method for generating interface test scripts according to claim 1, characterized in that, Based on the first interface dataset, generate interface test scripts for each interface in the target project, including: Obtain the interface data for each interface in the target project from the first interface dataset; Generate an interface test script for each interface based on the interface data of each interface.
3. The method for generating interface test scripts according to claim 2, characterized in that, Generate an interface test script for each interface based on the interface data of each interface, including: Obtain the target algorithm, wherein the target algorithm is used to generate interface test scripts based on interface data; The interface data of each interface is used to generate an interface test script for each interface through the target algorithm.
4. The method for generating interface test scripts according to claim 1, characterized in that, Obtain the second interface dataset saved by the target project at the current time, including: Send a request instruction to the target plugin and receive the interface file sent by the target plugin in response to the request instruction, wherein the interface file is a file generated by the target plugin after the target object configures the target plugin for the target project; Parse the interface file to obtain the second interface dataset saved by the target project at the current time.
5. The method for generating interface test scripts according to claim 1, characterized in that, Accessing the database of the target project according to the generation instructions includes: The project identifier of the target project is determined according to the generation instructions; Access the database of the target project corresponding to the project identifier.
6. An apparatus for generating interface test scripts, characterized in that, include: The first acquisition module is used to acquire a generation instruction, wherein the generation instruction is used to instruct the generation of an interface test script for a target project, and the target project is implemented through code; The second acquisition module is used to access the database of the target project according to the generation instruction to obtain the update time of the database, wherein the update time is used to indicate the time when the data in the database changes; The generation module is used to obtain a first interface dataset from the database of the target project when the time interval between the update time and the current time is less than a preset threshold, and generate an interface test script for each interface in the target project based on the first interface dataset, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project. The generation module is further configured to: obtain a second interface dataset saved by the target project at the current time when the time interval between the update time and the current time is greater than a preset threshold; obtain interface test scripts for each interface in the target project based on the second interface dataset; obtain a first interface dataset from the database of the target project, wherein the first interface dataset contains interface data corresponding to multiple interfaces in the target project; and replace the first interface dataset in the database with the second interface dataset when a difference is found between the first interface dataset and the second interface dataset, and determine the update time of the database.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program, when executed, performs the method described in any one of claims 1 to 5.
8. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 5 through the computer program.