Interface testing method, system, computer device and storage medium

By splitting the script on the interface test page and converting it into test messages, the high cost of traditional interface testing is solved, enabling efficient and low-cost testing of multiple interface types and improving R&D efficiency.

CN115203055BActive Publication Date: 2026-02-17INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210915686.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-01
Publication Date
2026-02-17
Estimated Expiration
2042-08-01

AI Technical Summary

Technical Problem

Traditional interface testing methods are costly and inefficient when dealing with a large number of different interface types.

Method used

This provides an interface testing method that loads a script on the interface testing page and splits it into data preparation code segments and message template code segments. The script is then converted into a test message and sent to the test node for interface testing. This method supports testing of multiple interface types and avoids cross-domain issues related to the HTTP protocol.

Benefits of technology

It improves the efficiency of R&D personnel in organizing test scripts, reduces the overall cost of interface testing, enhances R&D efficiency, and can effectively perform testing of various interface types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115203055B_ABST
    Figure CN115203055B_ABST
Patent Text Reader

Abstract

The application relates to an interface test method, system, computer device and storage medium in the field of financial technology or other related fields. The method comprises the following steps: loading an interface test script in an interface test page; splitting the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment; converting the message template code segment into a test message according to the data preparation code segment; sending the test message to a test node corresponding to the interface test page, so as to instruct the test node to call a corresponding interface under test, and perform interface test on the interface under test according to the test message. The method can reduce the interface test cost.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and in particular to an interface testing method and system, a computer device, a storage medium, and a computer program product. BACKGROUND

[0002] With the rapid development of the Internet, the number of interfaces used by software has increased dramatically, and the implementation methods of interfaces under different software are various, and the types of interfaces exposed to the outside also present various forms. In the traditional way, corresponding interface testing methods are taken for different interface types.

[0003] However, when there are a large number of different interface types to be tested, using the traditional way to test the interface will result in high cost of interface testing. SUMMARY

[0004] Therefore, it is necessary to provide an interface testing method, system, computer device, computer readable storage medium, and computer program product capable of reducing the cost of interface testing.

[0005] In a first aspect, the present application provides an interface testing method. The method comprises:

[0006] loading an interface testing script on an interface testing page;

[0007] splitting the interface testing script to obtain a plurality of code segments; the plurality of code segments include a data preparation code segment and a message template code segment;

[0008] converting the message template code segment into a test message according to the data preparation code segment;

[0009] sending the test message to a test node corresponding to the interface testing page to instruct the test node to call a corresponding interface to be tested, and performing interface testing on the interface to be tested according to the test message.

[0010] In one of the embodiments, the code segment further includes an after-execution code segment; the method further comprises:

[0011] receiving an interface testing result returned by the test node, and performing assertion on the interface testing result according to the after-execution code segment.

[0012] In one of the embodiments, converting the message template code segment into a test message according to the data preparation code segment comprises:

[0013] preparing data according to the data preparation code segment to obtain target data;

[0014] dynamically replacing the content to be replaced in the message template code segment according to the target data to obtain the test message.

[0015] In one of the embodiments, the method further comprises:

[0016] When it is identified by the test node that the corresponding interface to be tested is a remote call interface, the remote call interface is instantiated;

[0017] The test node remotely calls the instantiated remote call interface, and performs interface testing on the instantiated remote call interface according to the test message.

[0018] In one of the embodiments, the method further comprises:

[0019] When it is identified by the test node that the corresponding interface to be tested is an application programming interface, the calling permission of the application programming interface is acquired;

[0020] The test node calls the application programming interface according to the calling permission, and performs interface testing on the application programming interface according to the test message.

[0021] In one of the embodiments, the method further comprises:

[0022] The test service configuration request is acquired on the configuration page, and the test service configuration request carries test service configuration information;

[0023] The test service corresponding to the interface to be tested is configured according to the test service configuration information, so as to instruct the test node to call the configured test service, and the interface to be tested is tested according to the test message through the configured test service.

[0024] In a second aspect, the application further provides an interface testing system. The system comprises:

[0025] A terminal is configured to load an interface testing script on an interface testing page, split the interface testing script to obtain a plurality of code segments, wherein the plurality of code segments comprise a data preparation code segment and a message template code segment, convert the message template code segment into a test message according to the data preparation code segment, and send the test message to a test node corresponding to the interface testing page;

[0026] A test node is configured to call a corresponding interface to be tested, and perform interface testing on the interface to be tested according to a test message.

[0027] In a third aspect, the application further provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0028] An interface testing script is loaded on an interface testing page;

[0029] Split the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment;

[0030] Convert the message template code segment into a test message according to the data preparation code segment;

[0031] Send the test message to a test node corresponding to the interface test page to instruct the test node to call a corresponding interface under test, and perform interface test on the interface under test according to the test message.

[0032] In a fourth aspect, the present application also provides a computer readable storage medium. The computer readable storage medium has a computer program stored thereon, and the computer program, when executed by a processor, implements the following steps:

[0033] Load an interface test script on an interface test page;

[0034] Split the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment;

[0035] Convert the message template code segment into a test message according to the data preparation code segment;

[0036] Send the test message to a test node corresponding to the interface test page to instruct the test node to call a corresponding interface under test, and perform interface test on the interface under test according to the test message.

[0037] In a fifth aspect, the present application also provides a computer program product. The computer program product comprises a computer program, and the computer program, when executed by a processor, implements the following steps:

[0038] Load an interface test script on an interface test page;

[0039] Split the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment;

[0040] Convert the message template code segment into a test message according to the data preparation code segment;

[0041] Send the test message to a test node corresponding to the interface test page to instruct the test node to call a corresponding interface under test, and perform interface test on the interface under test according to the test message.

[0042] The interface test method, system, computer device, storage medium and computer program product can split the interface test script loaded in the page by providing a unified interface test page and script standard, thereby obtaining a plurality of code segments including a data preparation code segment and a message template code segment, and realizing parsing of the custom segmented JavaScript interface test script. The message template code segment is converted into a test message according to the data preparation code segment, test logic is introduced in the script, and the test message is obtained, thereby improving the ability of the R&D personnel to organize efficient test scripts and improving the R&D efficiency. Then, the terminal sends the test message to the test node for interface test, and the specific steps of the interface test are realized by the test node according to the test message, thereby avoiding the influence of different interface types or HTTP protocol cross-domain problems, being capable of testing the interfaces of various interface types, and reducing the cost of the interface test as a whole. BRIEF DESCRIPTION OF DRAWINGS

[0043] Figure 1 An application environment diagram of an interface test method in an embodiment;

[0044] Figure 2 A flowchart of an interface test method in an embodiment;

[0045] Figure 3 A flowchart of a step of converting a message template code segment into a test message according to a data preparation code segment in an embodiment;

[0046] Figure 4 A schematic diagram of RPC interface service calling in an embodiment;

[0047] Figure 5 A schematic diagram of API interface service calling in an embodiment;

[0048] Figure 6 A flowchart of an interface test method in another embodiment;

[0049] Figure 7 A structural block diagram of an interface test system in an embodiment;

[0050] Figure 8 A structural block diagram of an interface test system in another embodiment;

[0051] Figure 9 An internal structure diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0052] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not to limit the present application.

[0053] The interface testing method provided by the embodiments of the present application can be applied to an application environment as shown in Figure 1 . The terminal 102 communicates with the test node 104 through a network. There can be multiple terminals 102 and multiple test nodes 104. The data storage system can store data to be processed by the test node 104. The data storage system can be integrated on the test node 104 or placed on a cloud or other network server. The terminal 102 can load an interface testing script on an interface testing page of a browser, split the interface testing script to obtain multiple code segments, and convert a message template code segment into a test message according to a data preparation code segment, and then send the test message to the test node 104 corresponding to the interface testing page to instruct the test node 104 to call a corresponding interface to be tested and perform interface testing on the interface to be tested according to the test message. The terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, etc. The test node can be a server, and the test node 104 can be implemented by an independent server or a server cluster composed of multiple servers.

[0054] In one embodiment, as shown in Figure 2 , an interface testing method is provided. Taking the terminal in Figure 1 as an example, the method includes the following steps:

[0055] Step 202: loading an interface testing script on an interface testing page.

[0056] The interface testing page refers to a browser page run by the terminal and used for interface testing. The interface testing script refers to a code used for interface testing.

[0057] Specifically, the terminal can first create a Web Worker space on the browser's interface test page, loading the test page script executor and custom functions. The interface test page serves as a unified test interface, allowing testing of various interface types. Custom functions are divided into system control classes and client-defined classes; client-defined functions are permitted in the interface test script. Initialization processing is then performed, which may include creating a cache area and workspace, clearing the context cache, etc. Creating the cache area can be done by building a Cache using the test script executor to cache JavaScript objects. The Cache is defined according to its lifecycle as a temporary cache and a permanent cache. The temporary cache is used to clear caches before execution, eliminating cache interference between different execution scenarios when the interface test script is executed multiple times in the same workspace. The permanent cache is used for system control or the context of multiple execution scenarios. Afterwards, the interface test script is loaded through the test page script executor. The interface test script can perform interface tests on various interface types. The interface test script covers test logic calculations, including general content calculations and backend service scenarios (other services, non-interface components, such as route calculations, SQL (Structured Query Language) statement execution, etc.).

[0058] Step 204: Split the interface test script to obtain multiple code segments; the multiple code segments include data preparation code segment and message template code segment.

[0059] Interface test scripts are custom three-part execution scripts based on the JavaScript language. JavaScript is a lightweight language. Interface test scripts are defined in three parts, for example, using the format: / / script segment identifier. These can be defined as / / [BEFORE] for data preparation, / / [MESSAGE] for message template, and / / [AFTER] for post-execution. The terminal can split the interface test script according to the script segment identifier to obtain the data preparation segment, message template segment, and post-execution segment. The data preparation segment is used for data preparation, the message template segment is used to generate messages usable for interface testing, and the post-execution segment is used to assert the interface test results.

[0060] Step 206: Based on the data preparation code segment, convert the message template code segment into a test message.

[0061] Among them, test messages refer to available messages used for interface testing.

[0062] Specifically, the data preparation code segment is executed on the interface test page through the browser to perform data preparation, complete the preparation of all related data before the interface initiates a call, including variable definition, background data update, etc. For example, event number and date can be defined and assigned by encapsulating functions, used to generate test messages, the server deploys a database, and the execution of SQL statements is implemented by encapsulating functions, used to update record status, etc. After completing the data preparation work, the target data is obtained. Thus, the message template code segment is assembled according to the target data to obtain the test message, and the message template code segment is converted into the test message to introduce the test logic in the interface test script. Among them, the message assembly refers to replacing the dynamic data in the message template code segment with the target data to assemble into a test message. For example, the dynamic data can be self-defined format content.

[0063] In step 208, the test message is sent to the test node corresponding to the interface test page to instruct the test node to call the corresponding interface under test to perform interface testing on the interface under test according to the test message.

[0064] Among them, the test node refers to the node corresponding to the interface test page in the distributed system, used to call the interface under test to perform interface testing.

[0065] Since the test node corresponds to the interface test page, such as one interface test page can correspond to one test node, the browser can generate an interface test request according to the test message and send the interface test request to the test node corresponding to the interface test page. The test node parses the interface test request to obtain the test message. The test node is pre-bound with the system under test, and the test service is integrated in the system under test. After receiving the interface test request, the browser can call the pre-bound test service in the system under test to call the interface under test through the test service, and then perform interface testing on the interface under test according to the test message through the test service. Among them, the test service can include test services corresponding to multiple interface types, such as RPC(Remote Procedure Call, Remote Procedure Call) interface service, API(Application Programming Interface, Application Programming Interface) service and general HTTP(Hyper Text Transfer Protocol, Hyper Text Transfer Protocol) based interface service.

[0066] Further, the test node can be deployed according to the system under test, version and environment element identifier, the test targets of different test nodes are different, and the test service of the system under test is registered according to the application software, which needs to be managed separately and logically isolated from other nodes.

[0067] The test node and the to-be-tested system are implemented based on the same architecture, so that the service request cost can be reduced. For example, if the to-be-tested system adopts a Spring Dubbo framework to implement service registration and request, the test node also implements service subscription and service request based on the same architecture.

[0068] The test node can synchronize the configuration information of the test service in the to-be-tested system to set the architecture logic such as cache, data source, and cluster grouping, so as to ensure consistency of the correlation settings.

[0069] In the interface test method, the terminal provides a unified interface test page and a script standard, so as to split the interface test script loaded in the page to obtain a plurality of code segments including a data preparation code segment and a message template code segment, and realize parsing of the custom segmented JavaScript interface test script. The message template code segment is converted into a test message according to the data preparation code segment, so as to introduce test logic in the script to obtain the test message, improve the ability of the R&D personnel to organize efficient test scripts, and improve the R&D efficiency. Then, the terminal sends the test message to the test node for interface test. The specific steps of the interface test are realized by the test node according to the test message, so as to avoid the influence of different interface types or HTTP protocol cross-domain problems, enable interface test of interfaces of various interface types, and reduce the cost of the interface test as a whole.

[0070] In an optional mode of the embodiment, the browser in the terminal can access the test service center and the test node respectively according to functions to complete interface test script management functions, interface test script editing functions, and execution functions. The test service center is configured to provide test service configuration service functions, test script management functions, and function database link pools. The browser can call the test service configuration service functions of the test service center to obtain a configuration page and perform test service configuration on the configuration page. The test service configuration information can include test service types, service identifiers, service names, service interfaces, service versions, and service communication area information. For example, the service identifier can be a service ID (Identity Document, identity).

[0071] The browser can call the test script management functions of the test service center to manage scripts according to service identifiers. Specifically, the scripts can be grouped and managed according to test scenarios or case types, script sharing can be realized through a shared service to improve the work collaboration ability of R&D personnel, script query, saving, and locking functions can be performed, and the like. In addition, the browser can realize script query display, editing, and execution functions in a test script editing area.

[0072] The functional database connection pools provided by the Test Service Center allow for data access functions of public application software outside the system under test. These services or data access functions can be configured within the Test Service Center, differentiated by version and environment, and accessible to test nodes within the same development cycle. For example, if applications A and B both need to access the database of application C during testing, and iteration cycles 1 and 2 belong to two different environments but are developed concurrently, then data connection pools SQLC1 and SQLC2 can be configured in the Test Service Center respectively. Interface test pages access these pools based on version mappings, as follows: A1->SQLC1, B1->SQLC1, A2->SQLC2, B2->SQLC2, thus achieving optimized resource configuration and shared functionality.

[0073] In one optional embodiment, such as Figure 3 As shown, step 206, converting the message template code segment into a test message based on the data preparation code segment, includes:

[0074] Step 302: Prepare the data according to the data preparation code segment to obtain the target data.

[0075] Step 304: Dynamically replace the content to be replaced in the message template code segment according to the target data to obtain the test message.

[0076] The terminal executes the data preparation code segment through the browser to complete all relevant data preparation work before the interface call is initiated, obtaining the target data. The target data may include defined variables, server update data, etc. For example, the data preparation code segment may look like this:

[0077] / / [BEFORE]

[0078] / / Get the transaction date. The date logic is to preferably get the NOS cache date; if the NOS is unavailable, get the machine date.

[0079] var workdate=this.getWorkate();

[0080] / / Unique transaction retrieval number, a random 21-digit number

[0081] var serialno=this.getSerialNo(21);

[0082] / / Retrieve a specific flag from table X in database A

[0083] var someflag=this.sqlSelectCell("Library","select someflagfromxxx.xxxwhere...limit1");

[0084] Wherein, the data preparation code segment is represented by / / [BEFORE]. The implementation of the data preparation code segment can adopt the eval() native function provided by JavaScript. The execution of the code segment needs to pass through internal control logic to ensure that the domains of the code segments are consistent, the objects defined in the execution process are continuously valid, and the execution before and after is connected. At the same time, a custom exception object is defined to control the exception throwing of the memory encapsulation function and the exception catching of the outgoing function, to realize the active exit and assertion exit control effect.

[0085] The data preparation code segment mainly realizes two functions: one is variable definition and real-time data acquisition, such as defining workdate (working date), combining with the requirements of the system to be tested, the machine date can be obtained through new Date(), or the date of the system to be tested can be obtained according to the cache system or the database, and then defining serialno (transaction unique retrieval number) through the random function function getSerialNo(length) to realize the random generation of fixed-length data. The above measures can ensure the uniqueness and validity of the subsequent test message. The other function is data preparation, such as database operation of the system to be tested, which is realized by specifying the environment ID and the statement to realize the database operation, so as to realize the data preparation before the interface test. Among them, the database service module is realized by the test node, and different database link pools and front-end encapsulation functions function sql(env, sql) are configured according to the environment ID. In addition, it is explained that the code segment supports ES5 (ECMAScript 5, the 5th edition of JavaScript language) and above standards. The interface test script is executed in different browsers or ScriptEngines, and the differences of each execution scene need to be paid attention to. The script is written in a common supported syntax to improve the compatibility of the script and the feasibility of transaction reuse.

[0086] After obtaining the target data, the message template code segment can be executed by the browser to assemble the test message. Specifically, the dynamic data part in the message template code segment, i.e. the content to be replaced, is extracted out, and the custom variables are used to replace the content to be replaced through the encapsulation function in the target data, so as to assemble the test message. There is no need for excessive manual maintenance of static content, so as to improve the script reuse efficiency. For example, the message template code segment can be as follows:

[0087]

[0088]

[0089] Wherein, the [MESSAGE] represents a message template code segment. Taking a JSON (JavaScript Object Notation) format message as an example, the message template code segment adopts a ${variable name} format to define the content to be replaced. A loop is created to perform full-text pattern matching through a regular expression / (\${([\s\S]+?)}) / , and the variable value in the target data is used for replacement. If the variable is not defined, it is replaced with an empty string, and the loop ends when the matching fails. For example, the obtained test message can be as follows:

[0090]

[0091] In the embodiment, the data preparation is performed according to the data preparation code segment to obtain the target data, and the content to be replaced in the message template code segment is dynamically replaced according to the target data to obtain the test message, so that the test logic is introduced into the interface test script, the ability of the R&D personnel to organize efficient test scripts is improved, the overall cost of interface testing is reduced, and the R&D efficiency is improved.

[0092] In an optional mode of the embodiment, the method further includes: when it is identified by the test node that the corresponding interface to be tested is a remote call interface, performing instantiation processing on the remote call interface; and calling the remote call interface after the instantiation processing through the test node, and performing interface testing on the remote call interface after the instantiation processing according to the test message.

[0093] The browser can generate an interface test request according to the test message, and send the interface test request to the test node corresponding to the interface test page. The test node analyzes the interface test request to obtain the test message. The test node is pre-bound with the system to be tested, and the test service is integrated in the system to be tested. After receiving the interface test request, the browser can call the test service in the pre-bound system to be tested, call the interface to be tested through the test service, and then perform interface testing on the interface to be tested according to the test message through the test service. The test service can include test services corresponding to multiple interface types.

[0094] When it is identified by the test node that the test service in the pre-bound system to be tested is an RPC interface service, it is determined that the interface to be tested is a remote call interface, i.e., an RPC interface. For example, the system to be tested can be a Spring Dubbo open source distributed system, the test service is implemented to simulate a consumer role, and the test service configuration information is configured to the test service center. The instantiation processing on the remote call interface includes interface instantiation and communication area instantiation.

[0095] As Figure 4As shown, a schematic diagram of RPC interface service calling is shown. Wherein, the to-be-tested system registers the service to the public service registration center after starting, and the test node subscribes the service in the public service registration center. When the test node receives the interface test request, the test service center subscribes the service according to the test service configuration information, and discovers the service. If the service exists, the remote calling interface is instantiated, and the communication area is instantiated. Thus, the RPC interface service calling request is generated according to the test message and the instantiated remote calling interface, and is sent to the to-be-tested system. When the to-be-tested system listens to the RPC interface service calling request, the RPC interface service calling request is parsed to obtain the test message and the instantiated remote calling interface. The corresponding RPC service calls the interface test on the instantiated remote calling interface according to the test message, and returns the interface test result to the test node. The browser receives the interface test result sent by the test node.

[0096] Optionally, the test service center subscribes the service according to the test service configuration information. The service subscription can implement multiple modes. One is full loading mode, which implements full service subscription when the test node starts, and the system overhead is large. Two is lazy loading mode, which implements subscription when the interface is called for the first time, and retains the stub. The subsequent call finds the stub according to the key value to call, and the system overhead is low.

[0097] In this optional mode, the remote calling interface can be called and the interface test can be implemented.

[0098] In an optional mode of the embodiment, the above method further includes: when the corresponding to-be-tested interface is identified by the test node as an application programming interface, obtaining the calling permission of the application programming interface; and calling the application programming interface by the test node according to the calling permission, and performing the interface test on the application programming interface according to the test message.

[0099] When the test service in the pre-bound to-be-tested system is identified by the test node as an API interface service, it is determined that the to-be-tested interface is an application programming interface, that is, an API interface. The calling permission of the terminal to the application programming interface is obtained, so that the application programming interface is called by the test node according to the calling permission, and the interface test on the application programming interface is performed according to the test message.

[0100] Specifically, the system to be tested registers an API interface service and customizes a verification mechanism. The test node loads a dedicated SDK (Software Development Kit) provided by the API platform. After receiving an interface test request, the test node first parses the interface test request by using the loaded SDK to obtain a service identifier, acquires interface service configuration information corresponding to the application programming interface according to the service identifier, and obtains a key to be verified. Second, the test node generates an API interface service call request according to the key to be verified, sends the API interface service call request to the API platform, parses the API interface service call request by using the API platform to obtain the key to be verified, verifies the key, and acquires a call permission of the API interface service when the verification is passed. Then, the test node initiates a service access request by using a browser, and the service access request carries a test message. Finally, the API platform forwards the request to the system to be tested by using an HTTP service, the system to be tested calls the application programming interface by using the API interface service, performs interface testing on the application programming interface according to the test message, returns an interface test result to the test node in the form of text, and forwards the interface test result to the browser by using the test node. As shown in FIG. 8, an example of API interface service calling is shown. Figure 5

[0101] In this optional mode, the application programming interface can be called and interface testing can be performed.

[0102] In an optional mode of the embodiment, the code segment further includes an after-execution code segment; and the method further includes: receiving an interface test result returned by the test node, and performing assertion on the interface test result according to the after-execution code segment.

[0103] The browser in the terminal performs assertion, data checking, and the like on the interface test result returned by the test node according to the after-execution code segment after receiving the interface test result. The assertion can include basic assertion, message content assertion, and logic assertion. The assertion order is not fixed and can be flexibly adjusted. The processing order is dynamically implemented according to the focus of testing and the importance of verification content. For example, the interface test result can be subjected to basic assertion, such as network timeout, network exception, non-standard format of a message, a return code, and the like. Second, the message content can be subjected to assertion, such as whether a field value meets an expectation. Then, a business-related logic assertion is performed. Meanwhile, other auxiliary functions can be arranged, such as database tracking and comparison, logic switch recovery, cache cleaning, log grabbing, and the like. For example, the after-execution code segment can be as follows:

[0104] / / [AFTER]

[0105] / / get return result

[0106] var ret=this.getResult();​

[0107] / / use native JSON object API to parse the message

[0108] var res=JSON.parse(ret);

[0109] / / or return the retcode field of the message field

[0110] var retcode=res.retcode

[0111] / / use the assert function family to assert that the return field retcode is 0

[0112] this.assertEquals("0","0","assert that the return field retcode is 0");

[0113] The script executor encapsulates the function getResult(), which has the function of obtaining the execution message. The interface test result in the above execution code segment is a JSON format message. The code segment first obtains the interface test result message, uses the JSON native object to parse the result message, and performs basic assertion on the result message. If the result message is not in the expected message format, or the specified return field value is not the expected result, then the assertion is failed first.

[0114] Optionally, the verification content of the execution code segment can be solidified to improve the testing efficiency of the R&D personnel.

[0115] Optionally, the interface test script can be iterated to a higher version according to the application, that is, the same interface test script can be repeatedly used with different versions, and the verification content can be continuously increased.

[0116] In this optional way, according to the assertion of the interface test result in the execution code segment, it can be verified whether the interface test result of the to-be-tested interface is accurate, and whether the to-be-tested interface is abnormal can be quickly identified, and the testing efficiency is effectively improved.

[0117] Optionally, the terminal browser can also include an interface test result output area, which can print the result line by line, sequentially output, and structure the output of the table, so as to be referred by the user.

[0118] In another embodiment, as shown in Figure 6 , an interface test method is provided, comprising the following steps:

[0119] Step 602, obtaining a test service configuration request in a configuration page, the test service configuration request carrying test service configuration information.

[0120] At step 604, the test service corresponding to the interface to be tested is configured according to the test service configuration information, and a configured test service is obtained.

[0121] At step 606, the interface test script is loaded on the interface test page.

[0122] At step 608, the interface test script is split to obtain a plurality of code segments; the plurality of code segments include a data preparation code segment, a message template code segment, and an execution code segment.

[0123] At step 610, data is prepared according to the data preparation code segment, and target data is obtained.

[0124] At step 612, the target data is used to dynamically replace content to be replaced in the message template code segment, and a test message is obtained.

[0125] At step 614, the test message is sent to a test node corresponding to the interface test page. When the test node identifies that the corresponding interface to be tested is a remote call interface, step 616 is performed; when the test node identifies that the corresponding interface to be tested is an application programming interface, step 620 is performed.

[0126] At step 616, the remote call interface is instantiated.

[0127] At step 618, the test service is called by the test node, and the instantiated remote call interface is tested according to the test message by the configured test service. Step 624 is performed.

[0128] At step 620, the calling authority of the application programming interface is obtained.

[0129] At step 622, the test service is called by the test node, and the application programming interface is tested according to the test message by the configured test service.

[0130] At step 624, the interface test result returned by the test node is received, and the interface test result is asserted according to the execution code segment.

[0131] The browser can obtain a configuration page by calling a test service configuration service function of the test service center. When a test service configuration request is obtained on the configuration page, the test service configuration request is parsed to obtain test service configuration information, which can include test service type, service identity, service name, service interface, service version, and service communication area information. The service identity can be a service ID (Identity Document). The test service corresponding to the interface under test is configured according to the test service configuration information, and then the test service after the configuration is called by the test node to perform interface testing on the interface under test according to a test message.

[0132] In this embodiment, the test service corresponding to the interface under test is configured, which is conducive to interface testing by calling the configured test service to perform interface testing.

[0133] The custom class functions used in this application are described below. Custom functions are used to encapsulate basic functions and test business functions, which can improve script writing and execution efficiency. Important function families in custom functions can include log function families, assertion function families, date function families, network request function families, database function families, and the like.

[0134] Log function families:

[0135] function alert(pattern); / / print log, output in the current output box

[0136] console.log(); / / redefine browser console log output

[0137] function log(pattern); / / print log, output in the current output box

[0138] function logArray(array,revolve); / / print array table

[0139] function logJson(obj); / / print object to json

[0140] function logList(list,columns,revolve,seqno); / / print list table

[0141] function logObject(obj,revolve,detail); / / print object first layer structure content

[0142] Assertion function families:

[0143] function assert(desc, e); / / Assert (if direct assertion fails)

[0144] function assertEquals(actual, expect, desc); / / Asserts two values ​​as equal.

[0145] function assertExpr(expr, desc); / / Asserts expressions that are true or false

[0146] function assertFalse(actual, desc); / / Asserts the object as false

[0147] function assertNotEquals(actual, unexpected, desc); / / Asserts that two values ​​are not equal.

[0148] function assertNotNull(actual, desc); / / Asserts that the object is not null.

[0149] function assertNull(actual, desc); / / Asserts that the object is null

[0150] function assertRetCode(actual, expected); / / Assert the return code

[0151] function assertTrue(actual, desc); / / Asserts the object as true.

[0152] Date function family:

[0153] function getSysCtrlCache(); / / Retrieves the system cache

[0154] function getSysdate(); / / Get the local system date

[0155] function getSysdate19(); / / Get the local 19-digit system date

[0156] function getSysdate8(); / / Get the local 8-digit system date

[0157] function getTime8(); / / Get local time

[0158] function getWorkdate(refresh); / / get cached system date

[0159] function getWorkdate8(refresh); / / get cached 8-bit system date

[0160] Network request function family:

[0161] function httpGet(url); / / GET request URL (only supports synchronous execution)

[0162] function httpGetCrossDomain(url); / / GET request URL (only supports synchronous execution), supports cross-domain request (switch to request under the test service center, use full path url)

[0163] function httpGetObject(url); / / GET request URL (only supports synchronous execution), and convert the result to an object

[0164] function httpPost(url,content); / / POST request URL (only supports synchronous execution)

[0165] function httpPostCrossDomain(url,content); / / POST request URL (only supports synchronous execution), supports cross-domain request (switch to request under the test service center, use full path url)

[0166] function httpPostObject(url,content); / / POST request URL (only supports synchronous execution), and convert the result to an object

[0167] Database function family:

[0168] function sqlCompare(env1,sql1,env2,sql2,columns,callbacks1,callbacks2);

[0169] / / Compare SQL execution results, support different environment execution comparison, field list parameter is empty when the first SQL table structure is used as the standard

[0170] function sqlEnv(); / / View data query service environment information

[0171] function sqlObject(env,sql); / / execute SQL statement, get result object

[0172] function sqlRevolve(revolve); / / set SQL query result to print vertically

[0173] function sqlSelectCell(env,sql); / / execute SQL statement, get single column field value

[0174] function sqlSelectRow(env,sql); / / execute SQL statement, get first row record

[0175] function sqlSelectRows(env,sql); / / execute SQL statement, get multiple row records

[0176] function sqlSetEnvSite(site); / / set the node where the database operation is performed (access data from other nodes)

[0177] function sqlStatus(); / / view data query service status information

[0178] function sqlText(env,sql); / / execute SQL statement, get result text

[0179] function sqlTrack(env,sql); / / track statements, execute and compare results by environment + statement, and print comparison table

[0180] function sqlTrackCompare(); / / print tracking results

[0181] function sqlTrackKeepResult(keep); / / keep tracking results (multiple executions, combined with page execution / termination buttons to implement manual tracking)

[0182] It should be understood that although the steps in the flowcharts involved in the embodiments described above are shown in sequence according to the arrows, the steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of the steps is not strictly limited in sequence, and the steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts involved in the embodiments described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of the steps or stages is not necessarily sequential, but can be executed in rotation or alternation with at least some of the other steps or the steps or stages in the other steps.

[0183] Based on the same inventive concept, the embodiments of the present application also provide an interface test system for implementing the interface test method described above. The implementation scheme for solving the problem provided by the system is similar to the implementation scheme described in the above method, so the specific limitations in one or more interface test system embodiments provided below can refer to the limitations of the interface test method described above, which will not be repeated here.

[0184] In one embodiment, as shown in Figure 7 An interface test system is provided, comprising a terminal 702 and a test node 704, wherein:

[0185] The terminal 702 is configured to load an interface test script on an interface test page, split the interface test script to obtain a plurality of code segments, wherein the plurality of code segments include a data preparation code segment and a message template code segment, convert the message template code segment into a test message according to the data preparation code segment, and send the test message to a test node corresponding to the interface test page.

[0186] The test node 704 is configured to call a corresponding interface to be tested, and perform interface test on the interface to be tested according to the test message.

[0187] The system used in the embodiment can be a B / S (Browser / Server) structure.

[0188] In the embodiment, the terminal provides a unified interface test page and a script standard, so as to split the interface test script loaded in the page to obtain a plurality of code segments including a data preparation code segment and a message template code segment, and realize parsing of the custom segmented JavaScript interface test script. The message template code segment is converted into a test message according to the data preparation code segment, test logic is introduced in the script to obtain the test message, the ability of the R&D personnel to organize efficient test scripts is improved, and the R&D efficiency is improved. Then, the terminal sends the test message to the test node for interface test, and the specific steps of the interface test are realized by the test node according to the test message, so that the influence of different interface types or HTTP protocol cross-domain problems is avoided, the interface of various interface types can be tested, and the cost of interface test is reduced as a whole.

[0189] In one embodiment, the code segment further includes a post-execution code segment; and the terminal 702 is further configured to receive an interface test result returned by the test node, and perform assertion on the interface test result according to the post-execution code segment.

[0190] In one embodiment, the terminal 702 is further configured to perform data preparation according to the data preparation code segment to obtain target data, and perform dynamic replacement on the to-be-replaced content in the message template code segment according to the target data to obtain a test message.

[0191] In one embodiment, the test node 704 is further configured to, when identifying that the corresponding interface to be tested is a remote call interface, perform instantiation processing on the remote call interface; and the remote call interface after the instantiation processing performs interface test on the remote call interface after the instantiation processing according to the test message.

[0192] In one embodiment, the test node 704 is further configured to, when identifying that the corresponding interface to be tested is an application programming interface, acquire a calling permission of the application programming interface; and the application programming interface according to the calling permission performs interface test on the application programming interface according to the test message.

[0193] In one embodiment, the terminal 702 is further configured to acquire a test service configuration request in the configuration page, the test service configuration request carrying test service configuration information; and configure a test service corresponding to the interface to be tested according to the test service configuration information, so as to instruct the test node to call the configured test service to perform interface test on the interface to be tested according to the test message.

[0194] In one embodiment, the system further comprises a to-be-tested system pre-bound with the test node, and the to-be-tested system has the test service integrated therein; the to-be-tested system is configured to receive the interface test request sent by the test node, the interface test request carrying the test message; the test service is invoked according to the interface test request, and the test service is used to perform interface test on the to-be-tested interface according to the test message.

[0195] In another embodiment, as shown in Figure 8 An interface test system is provided, which comprises a terminal 802, a test node 804, a to-be-tested system 806 and a test service node 808, the terminal 802, the test node 804 and the to-be-tested system 806 can be multiple, the interface test page of the browser in the terminal 802 is matched with the test node, the test node is bound with the to-be-tested system; wherein: the test service center 808 is configured to provide test service configuration service function, test script management function and function database link pool. The browser in the terminal 802 is configured to invoke the test service configuration service function of the test service center, obtain a configuration page and perform test service configuration on the configuration page. The browser in the terminal 802 is further configured to invoke the test script management function of the test service center, and perform script management according to the service identifier. The test node 804 is configured to invoke the function database link pool of the test service center, configure the data access function of the test service center, so that the interface test page of the browser in the terminal is accessed, and configuration resource optimization and function sharing are achieved.

[0196] The modules in the interface test system can be realized by software, hardware and combinations thereof in whole or in part. The modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operations corresponding to the modules.

[0197] In one embodiment, a computer device is provided, which can be a terminal, and the internal structure diagram thereof can be as shown in Figure 9The computer device shown in the figure includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input system. Among them, the processor, the memory and the input / output interface are connected through the system bus, and the communication interface, the display unit and the input system are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals in a wired or wireless manner. The wireless manner can be realized through WIFI, mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by the processor to realize an interface test method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection system or a virtual reality imaging system. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input system of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.

[0198] Those skilled in the art can understand that, Figure 9 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.

[0199] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps in each of the above method embodiments.

[0200] In one embodiment, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to implement the steps in each of the above method embodiments.

[0201] In one embodiment, a computer program product is provided, including a computer program, and the computer program is executed by a processor to implement the steps in each of the above method embodiments.

[0202] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of the country and region.

[0203] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of each method can be included. Any reference to a memory, database or other medium used in the embodiments provided by the present application can include at least one of a non-volatile and volatile memory. The non-volatile memory can include a read-only memory (Read-Only Memory, ROM), a magnetic tape, a floppy disk, a flash memory, an optical storage, a high-density embedded non-volatile memory, a resistive memory (ReRAM), a magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), a ferroelectric memory (Ferroelectric Random Access Memory, FRAM), a phase change memory (Phase Change Memory, PCM), a graphene memory, etc. The volatile memory can include a random access memory (Random Access Memory, RAM) or an external cache memory, etc. As an illustration but not limitation, the RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided by the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided by the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.

[0204] The technical features of the above embodiments can be combined in any way. To make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combinations of the technical features do not exist contradictory, they should be considered as the scope of the present disclosure.

[0205] The above-described embodiments are merely illustrative of several embodiments of the present application, and the description is relatively specific and detailed, but should not be understood as a limitation on the scope of the patent. It should be noted that for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of protection of the present application should be subject to the appended claims.

Claims

1. An interface test method characterized by, The method comprises: loading an interface test script on an interface test page; splitting the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment; converting the message template code segment into a test message according to the data preparation code segment; sending the test message to a test node corresponding to the interface test page to instruct the test node to call a corresponding interface under test and perform interface testing on the interface under test according to the test message; the converting the message template code segment into a test message according to the data preparation code segment comprises: performing data preparation according to the data preparation code segment to obtain target data; and performing dynamic replacement on to-be-replaced content in the message template code segment according to the target data to obtain a test message; the method further comprises: when it is identified through the test node that the corresponding interface under test is a remote call interface, performing instantiation processing on the remote call interface; remotely calling the instantiated remote call interface through the test node and performing interface testing on the instantiated remote call interface according to the test message.

2. The method of claim 1, wherein, The code segment further comprises an after-execution code segment; the method further comprises: receiving an interface test result returned by the test node and performing assertion on the interface test result according to the after-execution code segment.

3. The method of claim 1, wherein, The method further comprises: when it is identified through the test node that the corresponding interface under test is an application programming interface, obtaining a calling permission for the application programming interface; calling the application programming interface through the test node according to the calling permission and performing interface testing on the application programming interface according to the test message.

4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises: obtaining a test service configuration request on a configuration page; the test service configuration request carries test service configuration information; configuring a test service corresponding to the interface under test according to the test service configuration information to instruct the test node to call the configured test service and perform interface testing on the interface under test through the configured test service according to the test message.

5. An interface test system, characterized by The system comprises: a terminal configured to load an interface test script on an interface test page; split the interface test script to obtain a plurality of code segments; the plurality of code segments comprise a data preparation code segment and a message template code segment; convert the message template code segment into a test message according to the data preparation code segment; and send the test message to a test node corresponding to the interface test page; a test node configured to call a corresponding interface under test and perform interface testing on the interface under test according to the test message; the terminal is further configured to perform data preparation according to the data preparation code segment to obtain target data; and perform dynamic replacement on to-be-replaced content in the message template code segment according to the target data to obtain a test message; The test node is further configured to, when identifying that the corresponding interface to be tested is a remote call interface, perform instantiation processing on the remote call interface; and perform interface testing on the remote call interface after the instantiation processing according to the test message. 6.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-5 when the computer program is executed by the processor. The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4.

7. A computer-readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4.

8. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4. The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4.

Citation Information

Patent Citations

  • Interface message test method and device, computer equipment and storage medium

    CA3129150A1

  • Interface-oriented automatic test method for software fault injection

    CN107368408A