CN117520195A - Method, apparatus, device, storage medium and program product for testing interface - Google Patents

Method, apparatus, device, storage medium and program product for testing interface Download PDF

Info

Publication number
CN117520195A
CN117520195A CN202311625925.0A CN202311625925A CN117520195A CN 117520195 A CN117520195 A CN 117520195A CN 202311625925 A CN202311625925 A CN 202311625925A CN 117520195 A CN117520195 A CN 117520195A
Authority
CN
China
Prior art keywords
interface
test
file
tested
case
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311625925.0A
Other languages
Chinese (zh)
Inventor
闻婷婷
刘秉星
都宏宾
秦岩
刘嫣然
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202311625925.0A priority Critical patent/CN117520195A/en
Publication of CN117520195A publication Critical patent/CN117520195A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a method, a device, electronic equipment, a computer readable storage medium and a computer program product for testing an interface, and relates to the technical fields of artificial intelligence such as data processing, code testing and cloud platform. One embodiment of the method comprises the following steps: acquiring an interface name and a code set provided by a user for an interface to be tested; determining an object code associated with the interface to be tested from the code set based on the interface name; generating a test case aiming at the interface to be tested according to the test parameters indicated by the target codes; and testing the interface to be tested by using the test case, and generating an interface test result. According to the embodiment, after the test case is generated based on the code analysis result, the interface is tested, so that a user can test the interface to be tested in the code set only by providing the interface name of the interface to be tested and the related code set, the test difficulty of the user on the interface is simplified, and the test efficiency is improved.

Description

Method, apparatus, device, storage medium and program product for testing interface
Technical Field
The present disclosure relates to the field of computer technology, and in particular, to the field of artificial intelligence technologies such as data processing, code testing, and cloud platform, and more particularly, to a method and apparatus for testing an interface, an electronic device, a computer readable storage medium, and a computer program product.
Background
With the development of computer technology, different software applications are required to provide support based on different needs of users to realize different functions. On the basis, in order to ensure the availability and the use quality of the software application, a series of indexes such as the availability, the stability and the like of each interface associated with the software function need to be tested in the software development process. The interface test can detect whether the exchange, transmission and control management processes of the data of the interaction points between the external systems and the systems and between the internal subsystems are abnormal, the mutual logic dependency relationship among the systems and the like.
In general, test cases can be selected to simulate actual operation conditions and ideal operation scenes so as to test interfaces among system components. Thus, how to perform interface testing quality and efficiency is of great concern and urgency.
Disclosure of Invention
Embodiments of the present disclosure provide a method, apparatus, electronic device, computer-readable storage medium, and computer program product for testing an interface.
In a first aspect, an embodiment of the present disclosure provides a method for testing an interface, including: acquiring an interface name and a code set provided by a user for an interface to be tested; determining an object code associated with the interface to be tested from the code set based on the interface name; generating a test case aiming at the interface to be tested according to the test parameters indicated by the target codes; and testing the interface to be tested by using the test case, and generating an interface test result.
In a second aspect, an embodiment of the present disclosure provides an apparatus for testing an interface, including: the name and code acquisition unit is configured to acquire an interface name and code set provided by a user aiming at an interface to be tested; an object code determining unit configured to determine an object code associated with an interface to be tested from a code set based on the interface name; the test case generation unit is configured to generate a test case for the interface to be tested according to the test parameters indicated by the target codes; the test result generating unit is configured to test the interface to be tested by using the test case and generate an interface test result.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to implement a method of testing an interface as described in any one of the implementations of the first aspect when executed.
In a fourth aspect, embodiments of the present disclosure provide a non-transitory computer-readable storage medium storing computer instructions for enabling a computer to implement a method of testing an interface as described in any of the implementations of the first aspect when executed.
In a fifth aspect, embodiments of the present disclosure provide a computer program product comprising a computer program which, when executed by a processor, is capable of implementing a method of testing an interface as described in any of the implementations of the first aspect.
The method, the device, the electronic equipment, the computer readable storage medium and the computer program product for testing the interface provided by the embodiment of the disclosure determine the target code associated with the interface to be tested from the code set based on the interface name after acquiring the interface name and the code set provided by the user for the interface to be tested. Further, according to the test parameters indicated by the object codes, test cases for the interfaces to be tested are generated. And finally, testing the interface to be tested by using the test case, and generating an interface test result.
After the test case is generated based on the code analysis result, the interface is tested, so that a user can test the interface to be tested in the code set only by providing the interface name of the interface to be tested and the related code set, the test difficulty of the user on the interface is simplified, and the test efficiency is improved.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification.
Drawings
Other features, objects and advantages of the present disclosure will become more apparent upon reading of the detailed description of non-limiting embodiments, made with reference to the following drawings:
FIG. 1 is an exemplary system architecture in which the present disclosure may be applied;
FIG. 2 is a flow chart of a method of testing an interface provided by an embodiment of the present disclosure;
FIG. 3 is a flowchart of a process of generating test cases provided by an embodiment of the present disclosure;
FIG. 4 is a flow chart of a method for testing an interface under an application scenario provided by an embodiment of the present disclosure;
FIG. 5 is a block diagram of a device for testing an interface according to an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of an electronic device adapted to perform a method for testing an interface according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness. It should be noted that, without conflict, the embodiments of the present disclosure and features of the embodiments may be combined with each other.
In addition, in the technical scheme related to the disclosure, the processes of acquiring, storing, using, processing, transporting, providing, disclosing and the like of related user personal information (such as interface names and codes related to later steps of the disclosure) all conform to the regulations of related laws and regulations and do not violate the popular regulations of the public order.
FIG. 1 illustrates an exemplary system architecture 100 of an embodiment of a method, apparatus, electronic device, and computer-readable storage medium to which the test interface of the present disclosure may be applied.
As shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide 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 fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various applications for implementing information communication between the terminal devices 101, 102, 103 and the server 105, such as a software development type application, a cloud test type application, an instant messaging type application, and the like, may be installed on the terminal devices.
The terminal devices 101, 102, 103 and the server 105 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices with display screens, including but not limited to smartphones, tablets, laptop and desktop computers, etc.; when the terminal devices 101, 102, 103 are software, they may be installed in the above-listed electronic devices, which may be implemented as a plurality of software or software modules, or may be implemented as a single software or software module, which is not particularly limited herein. When the server 105 is hardware, it may be implemented as a distributed server cluster formed by a plurality of servers, or may be implemented as a single server; when the server is software, the server may be implemented as a plurality of software or software modules, or may be implemented as a single software or software module, which is not particularly limited herein.
The server 105 can provide various services through various built-in applications, and for example, can provide a software development type application with an interface test function, and the server 105 can achieve the following effects when running the software development type application: firstly, acquiring interface names and code sets provided by a user for an interface to be tested from terminal equipment 101, 102 and 103 through a network 104; then, the server 105 determines an object code associated with the interface to be tested from the code set based on the interface name; then, the server 105 generates a test case for the interface to be tested according to the test parameters indicated by the object code; finally, the server 105 tests the interface to be tested by using the test case, and generates an interface test result.
It should be noted that the interface names and code sets provided by the user for the interface to be tested may be stored in advance in the server 105 in various ways, in addition to being acquired from the terminal devices 101, 102, 103 via the network 104. Thus, when the server 105 detects that such data has been stored locally (e.g., an interface test task that was left until processing was initiated), it may choose to retrieve such data directly from the local, in which case the exemplary system architecture 100 may not include the terminal devices 101, 102, 103 and network 104.
Since storing codes and analyzing codes may occupy more computing resources and stronger computing power, the method for testing an interface provided by the subsequent embodiments of the present disclosure is generally performed by the server 105 having stronger computing power and more computing resources, and accordingly, the device for testing an interface is also generally disposed in the server 105. However, it should be noted that, when the terminal devices 101, 102, 103 also have the required computing capability and computing resources, the terminal devices 101, 102, 103 may also complete each operation performed by the server 105 through the software development application installed thereon, and further output the same result as the server 105. Especially in the case that there are a plurality of terminal devices having different computing capabilities at the same time, but when the software development application determines that the terminal device has a stronger computing capability and more computing resources remain, the terminal device can execute the above-mentioned computation, so that the computing pressure of the server 105 is properly reduced, and correspondingly, the device for testing the interface can also be provided in the terminal devices 101, 102, 103. In this case, the exemplary system architecture 100 may also not include the server 105 and the network 104.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring to fig. 2, fig. 2 is a flowchart of a method for testing an interface according to an embodiment of the disclosure, wherein the flowchart 200 includes the following steps:
step 201: acquiring an interface name and a code set provided by a user for an interface to be tested;
this step aims at acquiring, by an execution subject of the method of testing an interface (for example, the server 105 shown in fig. 1), an interface name and a code set provided by a user for the interface to be tested. For example, a user (e.g., development of software, tester) may utilize, for example, the terminal devices 101, 102, 103 shown in fig. 1 as user devices to communicate with the server 105, which is exemplified as an execution subject, and provide the execution subject with a set of interface names and codes provided for an interface to be tested. The interface name, which may be the name of the interface to be tested, is exemplified in the Python environment where the interface may be understood as a convention or protocol for defining which methods or properties the class should implement. The interface does not provide an actual implementation, but rather only a signature that defines which methods and properties the class should have. Interfaces in Python are typically implemented by abstract base classes (Abstract Base Class, ABC for short). ABC is an abstract class that cannot be instantiated, but rather is a common interface for defining other classes.
The set of codes is typically associated with, or otherwise includes, at least the above-described interface to be tested. In some scenarios, the interface name may also be referred to as a service name. In this way, the user may be caused to indicate to the executing subject, by way of communication therewith, the interface to be tested that needs to be tested, and the set of codes (or code items) associated with the interface to be tested, thereby to instruct the executing subject to perform testing of the interface to be tested that the user desires to test. Alternatively, the user may dispatch to the executing body a task of testing for the interface to be tested.
It should be understood that any type of code may be included in the code set in addition to or instead of the object code. Thus, after the project codes and the code sets are specified, the execution subject can automatically realize the interface test based on analysis and extraction of the code sets.
Alternatively or additionally, the user may provide interface names and corresponding code sets in bulk, by way of, for example, a list, excel manifest, or the like, so that the user efficiently indicates that the executing subject needs to be tested for an interface, efficiently "dispatching tasks of test interfaces" to the executing subject.
It should be noted that the code sets may be obtained directly from the local storage device by the execution body, or may be obtained from a non-local storage device (for example, the terminal devices 101, 102, 103 shown in fig. 1). For example, in the scenarios of collaborative coding, cloud development, etc., the code set may be stored in a storage device local to the execution body, e.g., the local storage device may be a data storage module, e.g., a server hard disk, disposed in the execution body, where the code set may be quickly read locally; the non-local storage device may also be any other electronic device arranged to store data, such as some user terminal or the like, in which case the executing entity may obtain the desired set of codes by sending an acquisition command to the electronic device.
Step 202: determining an object code associated with the interface to be tested from the code set based on the interface name;
on the basis of the above step 201, this step is aimed at, after determining an interface to be tested that the user desires to test based on the interface name indicated by the user, extracting an object code associated with the interface to be tested from a code set designated by the user and associated with the interface. For example, the execution subject may match, from the code set, the code that called, that relates to the interface (interface name) based on the interface name, and take it as the target code.
Step 203: generating a test case aiming at the interface to be tested according to the test parameters indicated by the target codes;
on the basis of the above step 202, this step is intended to be performed by the execution body based on the analysis of the object code to determine the test parameters. Typically, the kind and content of the test parameters are associated with the development environment and interface kind of the code. For example, in the Python development environment, the test parameters may be interface constants of an interface to be tested, application programming interface (Application Programming Interface, API for short), and case-class anomaly test (TestAbnormal). For example, the interface constant of the interface to be tested may be a constant indicated by the object code, such as a uniform resource locator (Uniform Resource Locator, URL) file (e.g., url_const.py). In some scenarios, based on the implemented functionality, the uniform locator file, the application programming interface file, and the use case testcase file may also be alternatively referred to as a uniform locator script, an application programming interface script, and a use case testcase script.
Accordingly, after determining the test parameters based on the object code, the execution body may generate test cases for the interface to be tested based on the test parameters. For ease of understanding, the following description will be given in terms of the development environment of Python. In the Python environment, the execution body may construct a uniform locator file (url_const.py), an application programming interface file (api.py) and a target case testcase file (testcases.py) after determining interface constants of the interface to be tested, the application programming interface and the case exception test, thereby obtaining the test case by using a combination of url_const.py, api.py and testcases.
Step 204: and testing the interface to be tested by using the test case, and generating an interface test result.
Based on the step 203, the present step aims to test the interface to be tested by the execution subject by using the test case generated in the step 203, and obtain and generate an interface test result based on the execution result of the interface to be tested for the test case, so as to complete the test work for the interface to be tested.
It should be appreciated that after generating the interface test results, the executing body may return the test results to the user device it uses based on the user's previous configuration, request, or send, store the test results to a default path indicated by the user or pre-configured so that the user may obtain the interface test results based on their indicated or default path.
According to the method for testing the interface, after the test case is generated based on the code analysis result, the interface is tested, so that a user can test the interface to be tested in the code set only by providing the interface name of the interface to be tested and the related code set, the interface to be tested in the code set is tested, the test difficulty of the user on the interface is simplified, and the test efficiency is improved.
In some optional implementations of this embodiment, the execution body may further read a case storage address included in the storage request in response to receiving a storage request for the test case from the user; and storing the test case to the case storage address.
Specifically, to meet the requirements of a user for checking the test case, reusing the test case, and the like, the user can instruct the execution body to specify a position of the generated test case, so as to avoid the execution body from storing the test case by using a random storage position, a default storage position, and other storage positions which are not known or are not easy to find by the user, or avoid the execution body from erroneously clearing the test case due to lack of storage execution. For example, in the process of providing the interface name and the code combination to the execution body in the step 201, the user may provide the case storage address by providing the storage request for the test case together, so as to instruct and normalize the execution body to store the test case in the case storage address after generating the test case, so as to facilitate the subsequent call of the user. It should be understood that the user may also choose to provide the use case storage address independently of any transmission occasion other than step 201, and this disclosure is not intended to be limiting. Accordingly, after the execution body generates the test case, the test case can be stored to the case storage address indicated by the user, so that the user can conveniently retrieve and inquire based on the requirement later.
In some optional implementations of this embodiment, when storing the test case, the execution body may further store, in association with the test case, identification information of an interface to be tested, and target test parameters for generating the test case, where the identification information is used to indicate an interface name of the interface to be tested for which the test case is intended. Specifically, when the execution body stores the test case (for example, stores the test case to a storage address indicated by the user), the execution body may further indicate, by using the identification information, an interface name of an interface to be tested for which the test case is to be tested and a target test parameter used when the test case to be tested is generated (i.e., a test parameter obtained when the test case to be tested is generated). Therefore, the interface to be tested and the target test parameters corresponding to the test case to be tested can be understood based on the identification information later, so as to judge whether the quality of the test case generated by the execution main body meets the requirement or not, and determine whether the test case can be multiplexed in other test processes or not.
In some embodiments, if it is allowed to call the test case that has been generated before, in the scenario and embodiment where it is desired to achieve the purpose of avoiding repeated generation and improving the test efficiency, the generating the test case for the interface to be tested according to the test parameters indicated by the object code includes: detecting whether a history test case meeting the test requirement exists or not according to the test parameters indicated by the target codes, wherein the history test case is used for testing the interface to be tested, and the similarity between the history test parameters associated with the history test case and the test parameters is higher than a preset threshold; and generating the test cases aiming at the interfaces to be tested in response to the fact that no historical test cases exist.
Specifically, when the execution body generates a test case for the interface to be tested according to the test parameters indicated by the target code, after the test parameters indicated by the target code are obtained, the execution body can detect whether a history test case meeting the test requirements exists for the interface to be tested.
For example, the execution body may acquire one or more test cases that were generated in the previous test process, and then determine whether there is a history test case that satisfies the test requirement among the one or more test cases that have been generated previously, based on whether the similarity between the test parameters that generated the one or more test cases (or, the history test parameters) and the acquired test parameters at this time satisfies the requirement. For example, if the similarity between a certain previously generated test case and the current acquired test parameter meets the requirement, or the similarity is higher than a preset threshold (typically, the preset threshold may be preconfigured according to the "confidence" requirement), the "certain previously generated test case" may be determined as the historical test case. If there are no history test cases that meet the requirements, the execution body may respond to this and then choose to execute the process of generating test cases as described in flow 200 above. Therefore, only when the history test cases meeting the requirements do not exist, the test cases are selected to be generated, so that the operation resources are saved.
Accordingly, in some optional implementations of the present embodiment, if the executing body determines that such a history test case exists, the executing body may select to determine the history test case as a test case for the interface to be tested, so as to execute the current test process and perform the test. Therefore, under the condition that the repeated detection requirement exists by a user, the test is performed based on the historical test cases meeting the test requirement, and additional and new test cases are not required to be generated, so that the operation resources are saved.
In some embodiments, obtaining the interface name and code set provided by the user for the interface to be tested includes: receiving an operation function transmitted by a user, wherein the operation function at least indicates an access path of a code set and an interface name of an interface to be tested; based on the analysis result for the running function, the interface name and the code set are obtained.
In particular, to simplify the operational difficulty of a user, the execution body may allow the code set and interface name to be provided in the manner of a run function. The run function is, for example, a run. The user can indicate the access path of the code set and the interface name of the interface to be tested using at least the values of the parameters in the run.py function. In some optional implementations of this embodiment, a parameter for indicating a use case storage address may also be included in the running function. Illustratively, in the run.py function, the repoPath value may be used to indicate the access path of the code set, the url list value to indicate the interface name, and the caseDir value to indicate the use case storage address. Therefore, the user can conveniently provide information required by the execution main body through the running function, so that the operation difficulty of the user is reduced, and the interaction efficiency is improved.
Alternatively or additionally, in some scenarios, if the user needs to set custom code for an API function, it may also be indicated with a value of a running function, such as selfDefine.
The details of generating test cases for the interface to be tested according to the test parameters indicated by the object code provided by the present disclosure will be described in detail below. For ease of understanding, please refer to fig. 3 at the same time, fig. 3 is a flowchart of a process 300 for generating test cases according to an embodiment of the disclosure. The flow 300 may be used as an alternative to step 203 in the embodiment shown in fig. 2 described above. Specifically, the process 300 includes the steps of:
step 301: constructing a unified locator file name, an application programming interface file name and a use case testcase file name based on the interface name;
specifically, the execution body may determine a uniform locator file name, an application programming interface file name, and a use case testcase file name based on the interface name, or the execution body may determine names of a uniform locator file, an application programming interface file, and a use case testcase file that may be associated to the "interface name" based on the interface name.
Step 302: detecting whether a target unified locator file corresponding to the unified locator file name, a target application programming interface file corresponding to the application programming interface file name and a target use case testcase file corresponding to the use case testcase file name are maintained locally based on the unified locator file name, the application programming interface file name and the use case testcase file name;
specifically, this step is intended to search locally whether the target uniform locator file corresponding to the uniform locator file name, the target application programming interface file corresponding to the application programming interface file name, and the target case testcase file corresponding to the case testcase file name have been maintained, using the uniform locator file name, the application programming interface file name, and the case testcase file name generated in step 301. Alternatively, it is detected whether at least one of a target uniform locator file (e.g., url_const.py), a target application programming interface file (e.g., api.py), and a target use case testcase file (e.g., testcases.py) corresponding thereto for testing the interface to be tested is missing locally.
If the executing body detects that at least one of the target uniform locator file corresponding to the uniform locator file name, the target application programming interface file corresponding to the application programming interface file name, and the target use case testcase file corresponding to the use case testcase file name is not maintained locally, or that there is a missing item (i.e., an item that is not maintained locally at the executing body among the three items), step 303 is executed to generate the missing item.
If the execution body detects that the target uniform locator file corresponding to the uniform locator file name, the target application programming interface file corresponding to the application programming interface file name, and the target use case testcase file corresponding to the use case testcase file name are all maintained locally, or the execution body detects that there is no missing item, the execution body may directly execute step 304 to generate a test use case for the interface to be tested based on the target uniform locator file, the target application programming interface file, and the target use case testcase file.
Step 303: generating a missing item based on a file name of the missing item;
for example, in the event that the target uniform locator file is missing, the execution body may generate the target uniform locator file based on the uniform locator file name determined above. In some embodiments, when the executing body generates the file of the missing item, the executing body may store the file generated to fill the missing item based on the file storage address configured in advance, which is not described herein.
Further, after filling the missing item, the execution body may continue to select the execution step 304 to generate a test case for the interface to be tested based on the target uniform locator file, the target application programming interface file, and the target case testcase file. Therefore, the test case can be ensured to be generated normally, and system errors caused by the lack of files and the like are avoided.
Step 304: and generating a test case aiming at the interface to be tested based on the target uniform locator file, the target application programming interface file and the target case testcase file.
In some embodiments, for a case where the test parameters include interface constants, application programming interface functions, and use case exception tests for the interface to be tested, generating the test case for the interface to be tested based on the target uniform locator file, the target application programming interface file, and the target use case testcase file includes: adjusting the target unified locator file based on the interface constant, adjusting the target application programming interface file based on the application programming interface function, and adjusting the target use case testcase file based on the use case exception test; and generating a test case aiming at the interface to be tested based on the adjustment result of the target unified locator file, the adjustment result of the target application programming interface file and the adjustment result of the target case testcase file.
Specifically, for the case that the test parameters include an interface constant of the interface to be tested, an application programming interface function, and a case type exception test, if the target uniform locator file, the target application programming interface file, and the target case testcase file all exist, the execution subject adjusts the target uniform locator file based on the interface constant, adjusts the target application programming interface file based on the application programming interface function, and adjusts the target case testcase file based on the case type exception test, respectively.
For url_const.py, the execution body may check, for example, whether the class in which the interface constant (or interface constant value) of the interface to be tested is located exists, and if so, the execution body may splice the definition of this interface constant to the last row of this class. Conversely, if the class in which the interface's constant value resides does not exist, the execution body may correspondingly create this class and add the definition of this interface constant to this class.
For api.py, the executing body may check whether there is an application programming interface function (API function) of the interface to be tested in api.py, if so, skip generating the API function, if not, the executing body may check whether the class in which the interface to be tested API is located exists, if not, create the class, and add the API function to the class; if present, the API function is added directly to the end of this class.
Illustratively, for testcases.py, the executing body may check whether a use case class exception test (TestAbnormal) of the API exists, and if not, the executing body may choose to create this class and generate an exception test (use case) of the necessary parameters do not pass, parameter value errors, etc.; in some embodiments, the executing body may also check whether a use case test (TestNormal) of the interface under test exists, and if not, the executing body may also generate a forward use case such as a get-only parameter, a combination of get-to-get parameter and a single get-to-get parameter, get-to-all parameter, etc. after creating this class.
Correspondingly, after the execution main body completes the adjustment, generating a test case aiming at the interface to be tested based on the adjustment result of the target uniform locator file, the adjustment result of the target application programming interface file and the adjustment result of the target case testcase file. Therefore, the execution main body can automatically complete available test cases which can be used for testing the interface to be tested based on the extraction result of the code set, and the test difficulty of a user on the interface is simplified.
For further understanding, the present disclosure also provides a specific implementation in connection with a specific application scenario, please refer to the flowchart 400 shown in fig. 4.
In flow 400, a user 410 provides a communication execution function 420 to an executing subject (e.g., server 105). Run function 411 may be used, for example, to indicate access paths and use case storage paths 421 for code set 431, interface names 422 for interfaces to be tested, and use case storage addresses 423 for storing test cases 433.
After receiving the run function 420, the server 105 may first obtain a code set 431 based on the access path and the use case storage path 421.
Further, server 105 may determine object code 432 from code set 431 based on interface name 422.
Further, the execution body may generate test cases 433 based on the test parameters indicated by the object code 432 and the case storage addresses 423. Accordingly, the test case 433 generated by the server 105 may be stored at the case storage address 423.
Finally, the server 105 may utilize the test 433 to test the interface to be tested (i.e., the interface indicated by the interface name 422), generate the test result 434, and then communicate and return the test result 434 to the user 410 to end the complete test procedure.
Therefore, after the test case is generated based on the code analysis result, the interface is tested, so that the user can test the interface to be tested in the code set only by providing the interface name of the interface to be tested and the related code set, the purpose of testing the interface to be tested in the code set can be achieved, the test difficulty of the user on the interface is simplified, and the test efficiency is improved.
With further reference to fig. 5, as an implementation of the method shown in the foregoing figures, the present disclosure provides an embodiment of an apparatus for testing an interface, where the apparatus embodiment corresponds to the method embodiment shown in fig. 2, and the apparatus is particularly applicable to various electronic devices.
As shown in fig. 5, the apparatus 500 for testing an interface of the present embodiment may include: a name and code acquisition unit 501, an object code determination unit 502, a test case generation unit 503, and a test result generation unit 504. Wherein, the name and code obtaining unit 501 is configured to obtain an interface name and code set provided by a user for an interface to be tested; an object code determining unit 502 configured to determine an object code associated with an interface to be tested from a code set based on the interface name; a test case generating unit 503 configured to generate a test case for the interface to be tested according to the test parameters indicated by the object code; the test result generating unit 504 is configured to test the interface to be tested by using the test case and generate an interface test result.
In this embodiment, in the device 500 for testing an interface: specific processing of the name and code acquiring unit 501, the object code determining unit 502, the test case generating unit 503 and the test result generating unit 504 and technical effects thereof may refer to the relevant descriptions of steps 201 to 204 in the corresponding embodiment of fig. 2, and are not repeated here.
In some optional implementations of the present embodiment, the test case generating unit 503 includes: a file name determination subunit configured to construct a uniform locator file name, an application programming interface file name, and a use case testcase file name based on the interface name; a file integrity detection subunit configured to detect, based on the uniform locator file name, the application programming interface file name, and the use case testcase file name, whether a target uniform locator file corresponding to the uniform locator file name, a target application programming interface file corresponding to the application programming interface file name, and a target use case testcase file corresponding to the use case testcase file name are maintained locally; a missing file shim subunit configured to generate a missing item based on a file name of the missing item in response to a deletion of at least one of the target uniform locator file, the target application programming interface file, and the target use case testcase file; the first test case generation subunit is configured to generate a test case for the interface to be tested based on the target uniform locator file, the target application programming interface file and the target case testcase file.
In some optional implementations of this embodiment, the test parameters include an interface constant of an interface to be tested, an application programming interface function, and a case anomaly test, and the first test case generation subunit includes: the file adjustment module is configured to adjust the target unified locator file based on the interface constant, adjust the target application programming interface file based on the application programming interface function and adjust the target use case testcase file based on the use case exception test respectively; the test case generation module is configured to generate a test case for the interface to be tested based on the adjustment result of the target uniform locator file, the adjustment result of the target application programming interface file and the adjustment result of the target case testcase file.
In some optional implementations of this embodiment, the apparatus 500 further includes: a storage address reading unit configured to read a case storage address included in a storage request in response to receiving the storage request of a user for a test case; and the test case storage unit is configured to store the test case to the case storage address.
In some optional implementations of this embodiment, the apparatus 500 further includes: the additional information association unit is configured to store identification information of the interface to be tested and target test parameters for generating the test case in association with the test case, wherein the identification information is used for indicating the interface name of the interface to be tested, which is aimed at by the test case.
In some optional implementations of the present embodiment, the test case generating unit 503 includes: the historical test case query subunit is configured to detect whether a historical test case meeting the test requirement exists according to the test parameters indicated by the target codes, wherein the historical test case is used for testing the interface to be tested, and the similarity between the historical test parameters associated with the historical test case and the test parameters is higher than a preset threshold; and the second test case generation subunit is configured to generate a test case aiming at the interface to be tested in response to the absence of the historical test case.
In some optional implementations of the present embodiment, the test case generating unit 503 further includes: and the third test case generation subunit is configured to determine the historical test case as the test case aiming at the interface to be tested in response to the existence of the historical test case.
In some optional implementations of the present embodiment, the name and code acquisition unit 501 includes: the running function receiving subunit is configured to receive a running function transmitted by a user, wherein the running function at least indicates an access path of the code set and an interface name of an interface to be tested; and a name and code acquisition subunit configured to acquire an interface name and code set based on the analysis result for the running function.
The device for testing the interface provided by the embodiment of the present invention can test the interface after generating the test case based on the code analysis result, so that the user can test the interface to be tested in the code set by only providing the interface name of the interface to be tested and the related code set, thereby simplifying the test difficulty of the user on the interface and improving the test efficiency.
According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
Fig. 6 illustrates a schematic block diagram of an example electronic device 600 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 6, the apparatus 600 includes a computing unit 601 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 602 or a computer program loaded from a storage unit 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 may also be stored. The computing unit 601, ROM 602, and RAM 603 are connected to each other by a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Various components in the device 600 are connected to the I/O interface 605, including: an input unit 606 such as a keyboard, mouse, etc.; an output unit 607 such as various types of displays, speakers, and the like; a storage unit 608, such as a magnetic disk, optical disk, or the like; and a communication unit 609 such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The computing unit 601 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 601 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as testing interfaces. For example, in some embodiments, the method of testing an interface may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device 600 via the ROM 602 and/or the communication unit 609. When the computer program is loaded into RAM 603 and executed by computing unit 601, one or more steps of the method of testing an interface described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the method of testing the interface in any other suitable way (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of large management difficulty and weak service expansibility in the traditional physical host and virtual private server (VPS, virtual Private Server) service. Servers may also be divided into servers of a distributed system or servers that incorporate blockchains.
According to the technical scheme of the embodiment of the disclosure, after the test case is generated based on the code analysis result, the interface is tested, so that a user can test the interface to be tested in the code set only by providing the interface name of the interface to be tested and the related code set, the test difficulty of the user on the interface is simplified, and the test efficiency is improved.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel, sequentially, or in a different order, provided that the desired results of the technical solutions provided by the present disclosure are achieved, and are not limited herein.
The above detailed description should not be taken as limiting the scope of the present disclosure. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure are intended to be included within the scope of the present disclosure.

Claims (19)

1. A method of testing an interface, comprising:
Acquiring an interface name and a code set provided by a user for an interface to be tested;
determining an object code associated with the interface to be tested from the code set based on the interface name;
generating a test case aiming at the interface to be tested according to the test parameters indicated by the target codes;
and testing the interface to be tested by using the test case to generate an interface test result.
2. The method of claim 1, wherein the generating the test case for the interface to be tested according to the test parameters indicated by the object code comprises:
constructing a unified locator file name, an application programming interface file name and a use case testcase file name based on the interface name;
detecting whether a target unified locator file corresponding to the unified locator file name, a target application programming interface file corresponding to the application programming interface file name and a target case testcase file corresponding to the case testcase file name are maintained locally based on the unified locator file name, the application programming interface file name and the case testcase file name;
Generating a missing item based on the file name of the missing item in response to the absence of at least one of the target uniform locator file, the target application programming interface file and the target use case testcase file;
and generating a test case aiming at the interface to be tested based on the target uniform locator file, the target application programming interface file and the target case testcase file.
3. The method of claim 2, wherein the test parameters include interface constants, application programming interface functions, and case anomaly tests for the interface to be tested, the generating a test case for the interface to be tested based on the target uniform locator file, the target application programming interface file, and the target case testcase file comprising:
adjusting the target unified locator file based on the interface constant, adjusting the target application programming interface file based on the application programming interface function, and adjusting the target use case testcase file based on the use case exception test, respectively;
and generating a test case aiming at the interface to be tested based on the adjustment result of the target uniform locator file, the adjustment result of the target application programming interface file and the adjustment result of the target case testcase file.
4. The method of claim 1, further comprising:
responding to a received storage request of the user for the test case, and reading a case storage address included in the storage request;
and storing the test case to the case storage address.
5. The method of claim 4, further comprising:
and storing the identification information of the interface to be tested and the target test parameters for generating the test case in association with the test case, wherein the identification information is used for indicating the interface name of the interface to be tested, which is aimed by the test case to be tested.
6. The method of claim 1, wherein the generating the test case for the interface to be tested according to the test parameters indicated by the object code comprises:
detecting whether a history test case meeting a test requirement exists or not according to the test parameters indicated by the target codes, wherein the history test case is used for testing the interface to be tested, and the similarity between the history test parameters associated with the history test case and the test parameters is higher than a preset threshold;
and generating a test case aiming at the interface to be tested in response to the fact that the history test case does not exist.
7. The method of claim 6, further comprising:
and in response to the existence of the historical test case, determining the historical test case as a test case aiming at the interface to be tested.
8. The method according to any one of claims 1-7, wherein the obtaining the set of interface names and codes provided by the user for the interface to be tested comprises:
receiving an operation function transmitted by a user, wherein the operation function at least indicates an access path of a code set and an interface name of an interface to be tested;
and acquiring the interface name and the code set based on the analysis result aiming at the running function.
9. An apparatus for testing an interface, comprising:
the name and code acquisition unit is configured to acquire an interface name and code set provided by a user aiming at an interface to be tested;
an object code determining unit configured to determine an object code associated with the interface to be tested from the code set based on the interface name;
the test case generation unit is configured to generate a test case aiming at the interface to be tested according to the test parameters indicated by the target code;
and the test result generating unit is configured to test the interface to be tested by using the test case and generate an interface test result.
10. The apparatus of claim 9, wherein the test case generating unit comprises:
a file name determination subunit configured to construct a uniform locator file name, an application programming interface file name, and a use case testcase file name based on the interface name;
a file integrity detection subunit configured to detect, based on the uniform locator file name, the application programming interface file name, and the use case testcase file name, whether a target uniform locator file corresponding to the uniform locator file name, a target application programming interface file corresponding to the application programming interface file name, and a target use case testcase file corresponding to the use case testcase file name are maintained locally;
a missing file shim subunit configured to generate a missing item based on a file name of the missing item in response to a deletion of at least one of the target uniform locator file, the target application programming interface file, and the target use case testcase file;
the first test case generation subunit is configured to generate a test case for the interface to be tested based on the target uniform locator file, the target application programming interface file and the target case testcase file.
11. The apparatus of claim 10, wherein the test parameters include interface constants, application programming interface functions, and case-type exception tests of the interface to be tested, the first test case generation subunit comprising:
the file adjustment module is configured to adjust the target unified locator file based on the interface constant, adjust the target application programming interface file based on the application programming interface function and adjust the target use case testcase file based on the use case exception test, respectively;
the test case generation module is configured to generate a test case for the interface to be tested based on the adjustment result of the target uniform locator file, the adjustment result of the target application programming interface file and the adjustment result of the target case testcase file.
12. The apparatus of claim 9, further comprising:
a storage address reading unit configured to read a case storage address included in a storage request for the test case in response to receiving the storage request for the test case from the user;
and the test case storage unit is configured to store the test case to the case storage address.
13. The apparatus of claim 12, further comprising:
the additional information association unit is configured to store identification information of the interface to be tested and target test parameters for generating the test case in association with the test case, wherein the identification information is used for indicating the interface name of the interface to be tested, which is aimed at by the test case.
14. The apparatus of claim 9, wherein the test case generating unit comprises:
a history test case query subunit configured to detect whether a history test case meeting a test requirement exists according to a test parameter indicated by the target code, where the history test case is used to test the interface to be tested, and a similarity between a history test parameter associated with the history test case and the test parameter is higher than a preset threshold;
and the second test case generation subunit is configured to generate a test case aiming at the interface to be tested in response to the fact that the history test case does not exist.
15. The apparatus of claim 14, the test case generating unit further comprising:
and the third test case generation subunit is configured to determine the historical test case as the test case aiming at the interface to be tested in response to the existence of the historical test case.
16. The apparatus according to any one of claims 9-15, wherein the name and code acquisition unit comprises:
a running function receiving subunit configured to receive a running function input by a user, wherein the running function at least indicates an access path of a code set and an interface name of an interface to be tested;
and a name and code acquisition subunit configured to acquire the interface name and the code set based on a result of parsing for the running function.
17. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of testing an interface of any one of claims 1-8.
18. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of the test interface of any one of claims 1-8.
19. A computer program product comprising a computer program which, when executed by a processor, implements a method of testing an interface according to any of claims 1-8.
CN202311625925.0A 2023-11-30 2023-11-30 Method, apparatus, device, storage medium and program product for testing interface Pending CN117520195A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311625925.0A CN117520195A (en) 2023-11-30 2023-11-30 Method, apparatus, device, storage medium and program product for testing interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311625925.0A CN117520195A (en) 2023-11-30 2023-11-30 Method, apparatus, device, storage medium and program product for testing interface

Publications (1)

Publication Number Publication Date
CN117520195A true CN117520195A (en) 2024-02-06

Family

ID=89762594

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311625925.0A Pending CN117520195A (en) 2023-11-30 2023-11-30 Method, apparatus, device, storage medium and program product for testing interface

Country Status (1)

Country Link
CN (1) CN117520195A (en)

Similar Documents

Publication Publication Date Title
CN111752843A (en) Method, device, electronic equipment and readable storage medium for determining influence surface
EP3920500A1 (en) Method and apparatus for verifying operation state of application
CN113360144B (en) Auxiliary processing method, device, storage medium and program product for software development
CN112035344A (en) Multi-scenario test method, device, equipment and computer readable storage medium
CN114389969A (en) Client test method and device, electronic equipment and storage medium
CN110688305A (en) Test environment synchronization method, device, medium and electronic equipment
CN113821433A (en) Method, device, equipment, medium and product for testing cloud mobile phone application program
CN113778849A (en) Method, apparatus, device and storage medium for testing code
CN112052152A (en) Simulation test method and device
CN116126719A (en) Interface testing method and device, electronic equipment and storage medium
CN117520195A (en) Method, apparatus, device, storage medium and program product for testing interface
CN114003497A (en) Method, device and equipment for testing service system and storage medium
CN114546799A (en) Point burying log checking method and device, electronic equipment, storage medium and product
CN113691403A (en) Topological node configuration method, related device and computer program product
CN113127357A (en) Unit testing method, device, equipment, storage medium and program product
CN113674246B (en) Method, device, electronic equipment and storage medium for auditing picture files
CN116561075B (en) Method for generating dynamic link library file, method and device for calling operator
CN113626409B (en) Test data processing method, device, equipment and storage medium
CN116991737A (en) Software testing method, system, electronic equipment and storage medium
CN116795611A (en) Test method, test device, electronic equipment and storage medium
CN116932033A (en) Component packaging method and device, electronic equipment and storage medium
CN114238149A (en) Batch testing method of accounting system, electronic device and storage medium
CN115480922A (en) Resource information processing method, device, electronic equipment and storage medium
CN116578555A (en) Data verification method, system, electronic equipment and storage medium
CN116107899A (en) MOCK interface management method, device, terminal equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination