Interface testing method, device, computer equipment, storage medium and product
By automatically acquiring and processing test cases, generating and sending test requests, the problem of poor timeliness of interface testing is solved and efficient interface testing automation is achieved.
Patent Information
- Application Number
- CN202311519648.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-14
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-11-14
AI Technical Summary
Existing interface testing methods cannot keep up with the rapid software iteration process, resulting in poor test timeliness.
Automated interface testing is implemented by obtaining emails in specific formats, automatically obtaining preconfigured test case tables, traversing test cases, generating and sending test requests, receiving response results, and judging whether the interface test passes or fails based on assertions.
It improves the timeliness and automation of interface testing, reduces operation and maintenance costs, and ensures the timely conduct and accuracy of interface testing.
Smart Images

Figure CN117762772B
Abstract
Description
Technical Field
[0001] The present application relates to the field of testing technology, and in particular to an interface testing method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] With the development of computer technology, software testing technology has emerged. Software testing is the process of evaluating and verifying software systems to discover defects, errors, and non-compliant behaviors in the software to ensure the reliability of the software system. Interface testing, as an important part of software testing, is used to verify each interface in the system to ensure that the interface can work properly. When performing interface testing, usually when the tester receives the notification that the software iteration is completed, the tester manually runs the test script and performs the test according to the test case.
[0003] However, with the acceleration of software update iteration, the previous interface testing methods have been unable to keep up with the current rapid software iteration process, and the timeliness of interface testing is poor. Summary of the invention
[0004] Based on this, it is necessary to provide an interface testing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the timeliness of testing in response to the above technical problems.
[0005] In a first aspect, the present application provides an interface testing method, comprising:
[0006] Obtain an email with the tester's email address as the recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents an adjustment action performed on the system to be tested, and the second keyword represents that the adjustment action is completed;
[0007] Traversing the test cases in the test case table, and obtaining the address of the interface to be tested indicated by the traversed test cases in the system to be tested;
[0008] Generate a test request for testing the interface to be tested according to the address of the interface to be tested, according to the request construction mode indicated by the function indicated by the request function name in the traversed test case;
[0009] Sending the test request to the system to be tested;
[0010] Receiving a response result fed back by the system to be tested in response to the test request;
[0011] When the response result is determined to be normal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has passed.
[0012] In a second aspect, the present application also provides an interface testing device, comprising:
[0013] An acquisition module is used to acquire an email with a tester's email address as a recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, a preconfigured test case table is acquired; the first keyword represents an adjustment action to be performed on the system to be tested, and the second keyword represents that the adjustment action is completed;
[0014] A test request construction module is used to traverse the test cases in the test case table, obtain the address of the interface to be tested indicated by the traversed test case in the system to be tested; generate a test request for testing the interface to be tested according to the address of the interface to be tested according to the request construction method indicated by the function indicated by the request function name in the traversed test case;
[0015] A test request sending module, used for sending the test request to the system to be tested;
[0016] A test request receiving module, used for receiving a response result fed back by the system to be tested in response to the test request;
[0017] The test result determination module is used to determine that the test of the interface to be tested indicated by the traversed test case has passed when the response result is determined to be normal according to the test assertion in the traversed test case.
[0018] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0019] Obtain an email with the tester's email address as the recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents an adjustment action performed on the system to be tested, and the second keyword represents that the adjustment action is completed;
[0020] Traversing the test cases in the test case table, and obtaining the address of the interface to be tested indicated by the traversed test cases in the system to be tested;
[0021] Generate a test request for testing the interface to be tested according to the address of the interface to be tested, according to the request construction mode indicated by the function indicated by the request function name in the traversed test case;
[0022] Sending the test request to the system to be tested;
[0023] Receiving a response result fed back by the system to be tested in response to the test request;
[0024] When the response result is determined to be normal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has passed.
[0025] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0026] Obtain an email with the tester's email address as the recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents an adjustment action performed on the system to be tested, and the second keyword represents that the adjustment action is completed;
[0027] Traversing the test cases in the test case table, and obtaining the address of the interface to be tested indicated by the traversed test cases in the system to be tested;
[0028] Generate a test request for testing the interface to be tested according to the address of the interface to be tested, according to the request construction mode indicated by the function indicated by the request function name in the traversed test case;
[0029] Sending the test request to the system to be tested;
[0030] Receiving a response result fed back by the system to be tested in response to the test request;
[0031] When the response result is determined to be normal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has passed.
[0032] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0033] Obtain an email with the tester's email address as the recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents an adjustment action performed on the system to be tested, and the second keyword represents that the adjustment action is completed;
[0034] Traversing the test cases in the test case table, and obtaining the address of the interface to be tested indicated by the traversed test cases in the system to be tested;
[0035] Generate a test request for testing the interface to be tested according to the address of the interface to be tested, according to the request construction mode indicated by the function indicated by the request function name in the traversed test case;
[0036] Sending the test request to the system to be tested;
[0037] Receiving a response result fed back by the system to be tested in response to the test request;
[0038] When the response result is determined to be normal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has passed.
[0039] In the above-mentioned interface testing method, apparatus, computer equipment, storage medium and computer program product, the function indicated by the request function name in the test case indicates the request construction method, and the request function names of different test cases can be configured with different request construction methods, so that the test request can be flexibly generated; moreover, since the first keyword in the obtained email represents the adjustment action on the system to be tested and the second keyword represents the completion of the adjustment action, it indicates that the system to be tested can be tested, and when the system to be tested needs to be tested, the interface to be tested of the system to be tested can be tested through the obtained email, so the interface test can be carried out in time, thereby solving the problem of poor test timeliness. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 An application environment diagram of an interface testing method in an embodiment;
[0042] Figure 2 A schematic diagram of a flow chart of an interface testing method in an embodiment;
[0043] Figure 3 A simplified flowchart of an interface testing step in an embodiment;
[0044] Figure 4 is a structural block diagram of an interface testing device in an embodiment;
[0045] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] The interface testing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the test server 102 communicates with the mail system 104 and the system to be tested 106 respectively through the network. The data storage system can store the data that the test server 102 needs to process. The data storage system can be integrated on the test server 102, or it can be placed on the cloud or other network servers. The test server 102 can obtain an email with the tester's email address as the recipient's email address from the email system 104, and the test server 102 can obtain a pre-configured test case table, traverse the test cases in the test case table, generate a test request for testing the interface to be tested, send a test request to the system to be tested 106, receive the response result of the system to be tested in response to the test request feedback, and when the response result is determined to be normal according to the test assertion in the traversed test case, it is determined that the test of the interface to be tested indicated by the traversed test case has passed. Among them, the test server 102 can be implemented with an independent server or a server cluster consisting of multiple servers. The mail system 104 can be implemented with an independent server or a server cluster consisting of multiple servers. The system to be tested 106 can be implemented with an independent server or a server cluster consisting of multiple servers.
[0048] In one embodiment, Figure 2 As shown, an interface testing method is provided, which is applied to Figure 1 Taking the test server 102 in the example as an example, the method includes the following steps 202 to 212. Among them:
[0049] Step 202, obtain an email with the tester's email address as the recipient's email address. When the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents the adjustment action on the system to be tested, and the second keyword represents the completion of the adjustment action.
[0050] Among them, email is information sent and received through the email system. The tester email address is the email address used by the tester to receive and send emails. The tester is the person responsible for software testing. The preset email address is a pre-set email address. The preset email address can be the email address of the person responsible for adjusting the system under test, specifically the developer email address or the operation and maintenance personnel email address.
[0051] The system to be tested is the system to be interface tested. The system to be tested can be a business system, such as a financial and tax management system, a merchant management system, etc. Interfaces are used to interact between different programs. Interface testing is the process of verifying whether the functions implemented by the interface are normal. In this application, interface testing can be regression testing.
[0052] Adjustment actions are actions to adjust the program of the system under test. Adjustment actions can be software updates, software iterations, software hot fixes, etc. Software updates are repairs or upgrades to the existing software version of the system under test. Software iteration is a way to gradually improve the functions and performance of the software of the system under test in multiple stages during the development of the system under test. Software hot fixes are a way to repair software defects by patching after the system under test goes online, so that software defects can be repaired without users noticing. The first keyword can specifically be special projects, urgent needs, hot fixes, iterations, technical optimization, or other words that represent adjustment actions. The second keyword can be completion, success, end, or other words that represent the completion of the adjustment action.
[0053] The test case table is a spreadsheet that records test cases. The spreadsheet can be an Excel table (a spreadsheet developed by Microsoft) or a spreadsheet in WPS (office software developed by Kingsoft Software). A test case is a set of data required for interface testing. A test case can consist of test input, expected result judgment conditions and other elements.
[0054] In one embodiment, when it is detected that there is an email received with the tester's email address as the recipient email address in the email system, the test server can obtain the email with the tester's email address as the recipient email address.
[0055] In one embodiment, at every preset time interval, the test server may obtain the field value of the test switch field in the preconfigured database table, and when the field value indicates that the test switch state is the test-on state, obtain an email with the tester's email address as the recipient's email address.
[0056] In one embodiment, the test server may determine the system to be tested, obtain a test case table file address preconfigured for the system to be tested, and obtain the preconfigured test case table according to the obtained test case table file address.
[0057] Step 204, traverse the test cases in the test case table to obtain the address of the interface to be tested indicated by the traversed test cases in the system to be tested.
[0058] The test case table may record at least one test case, and each test case includes field values under preset fields. The field values under preset fields are used to generate test requests. The field values under preset fields may only include request function name, request action, address of the interface to be tested, and test assertion, and may also additionally include request header information, request body information, file path, file name, test case identifier, environment variables, or remarks.
[0059] The function indicated by the request function name is used to indicate the request construction method of the test request. The request action is the operation action specified by the test request on the resource indicated by the interface address to be tested. In some scenarios, the request action can be called a request method. The request action can include POST (indicating that the test request is used to submit data to the resource indicated by the interface address to be tested and process it), GET (indicating that the test request is used to request the page information indicated by the interface address to be tested) or others.
[0060] The address of the interface to be tested is used to access the interface to be tested. The address of the interface to be tested can be a URL (Uniform Resource Locator). The request header information is the part used to transmit additional information about the request in the HTTP protocol (Hypertext Transfer Protocol). The request header information contains the metadata required for communication between the client and the server. The request body information is the data required to be sent for the test request. The request body information can also be called request data. The file path is the access path of the file when the file exists in the request body information required to be sent for the test request. The file name is the name of the file when the file exists in the request body information required to be sent for the test request.
[0061] The test case identifier is used to distinguish different test cases. The test case identifier can be a test case number, a test case sequence number or other. The environment variable represents the software environment where the interface to be tested is located, which can be a test environment, a pre-production environment, or a production environment.
[0062] In one embodiment, the test server may traverse the test cases in the test case table, and obtain the traversed test cases each time the traversal occurs. The traversed test cases include the addresses of the interfaces to be tested in the system to be tested.
[0063] In one embodiment, the test server may read the traversed test cases from the test case table, store the traversed test cases in a preconfigured list, and obtain the address of the interface to be tested in the test system from the test case most recently stored in the list.
[0064] Step 206: Generate a test request for testing the interface to be tested according to the address of the interface to be tested, in accordance with the request construction mode indicated by the function indicated by the request function name in the traversed test case.
[0065] The request construction method is a method for constructing a test request. The request construction method may indicate information required for constructing a test request, a method for obtaining information required for constructing a test request, or a specific method for constructing information required for a test request into test information. The test request may be an HTTP request or an HTTPS (Hypertext Transfer Protocol Secure) request.
[0066] In one embodiment, the test server may generate a test request for testing the interface to be tested according to the request construction mode indicated by the function indicated by the request function name in the traversed test case, the request action in the traversed test case, and the address of the interface to be tested.
[0067] In one embodiment, when the request function name in the traversed test case matches the function name of the preconfigured function, the test server can generate a test request for testing the interface to be tested according to the request construction method indicated by the preconfigured function and the address of the interface to be tested. The function indicated by the request function name can be a preconfigured function whose function name matches the request function name.
[0068] Step 208: Send a test request to the system to be tested.
[0069] In one embodiment, when a communication connection is established between the test server and the system to be tested, the test server may send a test request to the system to be tested through the established communication connection.
[0070] In one embodiment, the test server may initiate a communication connection request to the system under test, establish a communication connection with the system under test upon receiving connection confirmation information fed back by the system under test, and send a test request to the system under test through the established communication connection.
[0071] In one embodiment, the test server may obtain the IP (Internet Protocol) address of the system to be tested indicated by the test request through a domain name server, and establish a communication connection with the system to be tested through the IP address.
[0072] Step 210: receiving a response result fed back by the system to be tested in response to the test request.
[0073] The response result includes a response status code and response data. The response status code can be a status code indicating a successful request, such as 200; a status code indicating that the requested resource has been transferred to another address, such as 301; a status code indicating that the requested resource does not exist, such as 404; or a status code indicating an internal server error, such as 500.
[0074] In one embodiment, when a communication connection is established between the test server and the system to be tested, the test server may receive a response result fed back by the system to be tested in response to the test request through the established communication connection.
[0075] Step 212: When the response result is determined to be normal according to the test assertions in the traversed test case, it is determined that the test of the interface to be tested indicated by the traversed test case has passed.
[0076] Among them, the test assertion is a logical judgment formula used to determine whether the response result is normal.
[0077] In one embodiment, the test server may input the response result into the test assertion in the traversed test case, obtain the output result of the test assertion, and when the output result indicates that the response result is normal, determine that the test of the interface to be tested indicated by the traversed test case has passed. The output result of the test assertion may be a Boolean value, which includes true (Ture) or false (False).
[0078] In one embodiment, when the response status code in the response result is determined to be normal according to the test assertion in the traversed test case, the response result is determined to be normal, and the test of the interface to be tested indicated by the traversed test case is determined to be passed. The test assertion can determine that the response status code is normal when the response status code indicates that the request is successful.
[0079] In one embodiment, when the response status code and response data in the response result are determined to be normal according to the test assertion in the traversed test case, the response result is determined to be normal, and the test of the interface to be tested indicated by the traversed test case is determined to have passed. The test assertion can determine that the response status code is normal when the response status code indicates that the request is successful, and determine that the response data is normal when the response data matches the preset data.
[0080] In the above-mentioned interface testing method, the function indicated by the request function name in the test case indicates the request construction method. The request function names of different test cases can be configured with different request construction methods, and the test request can be flexibly generated; moreover, since the first keyword in the obtained email represents the adjustment action on the system to be tested and the second keyword represents the completion of the adjustment action, it indicates that the system to be tested can be tested. It is possible to identify through the obtained email that the system to be tested needs to be tested and the interface to be tested of the system to be tested needs to be tested, so that the interface test can be carried out in time, thereby solving the problem of poor test timeliness.
[0081] In one embodiment, the step of obtaining an email with the tester's email address as the recipient's email address in step 202 includes: obtaining the field value of the test switch field in the preconfigured database table at every preset time interval; the field value of the test switch field is configured in the web page logged in as the tester; when the field value indicates that the test switch state is the test-on state, obtaining an email with the tester's email address as the recipient's email address.
[0082] The preset time interval is a preset time interval. The preset time interval may be 30 minutes. The test switch field is a field used to record the state of the test switch. For example, when the field value of the test switch field is 1, it indicates that the state of the test switch is a test-on state; when the field value of the test switch field is 0, it indicates that the state of the test switch is a test-off state.
[0083] In this embodiment, the interface testing method can be executed at preset time intervals to realize automatic execution of interface testing, and the test switch status is judged by the field value of the test switch field to determine whether to obtain the email. The field value of the test switch field can be configured by the tester through a web page, so it is more convenient to configure whether the interface testing method can be executed, thereby reducing operation and maintenance costs.
[0084] In one embodiment, the terminal can display a web page for configuring the test switch status, in which a test on control and a test off control are displayed. When the user logs into the web page as a tester, when it is detected that the test on control in the web page is triggered, the field value of the test switch field in the preconfigured database table is set to a first preset value, and an on log is recorded; when it is detected that the test off control in the web page is triggered, the field value of the test switch field in the preconfigured database table is set to a second preset value, and a off log is recorded. The web page for configuring the test switch status can be developed based on Python (an object-oriented interpreted computer programming language) and Django framework (an open source Web framework written in Python). The first preset value indicates that the test switch status is a test on state, which can be 1. The second preset value indicates that the test switch status is a test off state, which can be 0.
[0085] In one embodiment, at every preset time interval, the test server can obtain the field value of the test switch field in the preconfigured database table; when the field value indicates that the test switch state is the test-on state, obtain the email whose receiving time is not greater than the preset time interval from the current time and whose recipient email address is the tester's email address; when the obtained email contains an email whose sender email address is the preset email address, the title contains the first keyword, and the body contains the second keyword, obtain the preconfigured test case table.
[0086] In one embodiment, at every preset time interval, the field value of the test switch field in the preconfigured database table is obtained. When the field value indicates that the test switch state is the test-on state, the emails with the tester's email address as the recipient email address in the current cycle are obtained. When the email receiving time of the latest received target email in the obtained emails is not greater than the preset time interval from the current time, the preconfigured test case table is obtained. Among them, the current cycle is the cycle in which the current time is located. The cycle can be a day or a fixed time period in a day. The fixed time period in a day is such as 8 am to 10 pm. The current cycle can be today. The target email is an email in which the sender's email address is the preset email address, the title contains the first keyword, and the body contains the second keyword.
[0087] In one embodiment, the above-mentioned interface testing method also includes the following steps: when the response result is determined to be abnormal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has failed; through the instant messaging message channel, as a virtual robot, an alarm message indicating that the test of the interface to be tested has failed is sent to a preconfigured notification receiving address.
[0088] The instant messaging message channel is a channel provided by the instant messaging system. The instant messaging system is, for example, a text messaging system, a WeChat system, an enterprise WeChat system, or others. A virtual robot is a virtual identity used to interact with users in the instant messaging system. The notification receiving address can be a WebHook address (the address used by the virtual robot in the instant messaging system to communicate with the outside world through HTTP).
[0089] In this embodiment, when the test result fails, an alarm message indicating that the test interface test failed is sent through the instant messaging message channel, so that when the tester pays attention to the message of the virtual robot, he can pay attention to the abnormal test results in time, so as to correct the abnormality in time and ensure the stability of the system to be tested.
[0090] In one embodiment, when the response status code in the response result is not a status code indicating a successful request, the test assertion in the traversed test case may determine that the response result is abnormal.
[0091] In one embodiment, the above-mentioned interface testing method also includes the following steps: when the test cases in the test case table are tested, and the interfaces to be tested indicated by the test cases in the test case table are tested and passed, the test completion time when the test is completed is obtained; when the test completion time is not within the preset time range, no action is taken; when the test completion time is within the preset time range, a notification message indicating that the test is executed normally is sent to a preconfigured notification receiving address through an instant messaging message channel as a virtual robot.
[0092] The preset time range is a time range within a preset period. For example, the period may be one day, and the preset time range may be 9:00 to 9:30 and / or 18:00 to 18:30 every day.
[0093] In this embodiment, when the test completion time is not within the preset time range, no action is taken, and when the test completion time is within the preset time range, a notification message is sent to indicate that the test is executed normally. This avoids information interference caused by frequent notifications to relevant personnel when all test interfaces have passed the test, and can, to a certain extent, enable relevant personnel to confirm that the interface test is executed normally, thereby improving the efficiency of information acquisition.
[0094] In one embodiment, step 206 includes: when the request function name in the traversed test case matches the function name of the preconfigured function, calling the preconfigured function; when the request construction information of a preset type is obtained according to the request construction method indicated by the preconfigured function, a test request for testing the interface to be tested is generated according to the request construction information of the preset type and the address of the interface to be tested.
[0095] Among them, the preconfigured function is a function preconfigured for the interface to be tested, which is used to indicate the request construction method for constructing the test request corresponding to the interface to be tested. A function is a program segment in a computer program. Different interfaces to be tested may correspond to different preconfigured functions, or may correspond to the same preconfigured functions. Request construction information is information used to construct a test request. The request construction method indicated by the preconfigured function may specify the specific information included in the request construction information of the preset type according to the request action in the test case; specifically, when the request action is an action without carrying a data type, the request construction method indicated by the preconfigured function may specify that the request construction information of the preset type only includes the request header information; when the request action is an action with a data type, the request construction method indicated by the preconfigured function may specify that the request construction information includes the request header information and the request body information. Actions without carrying a data type are such as GET, and actions with a data type are such as POST.
[0096] In this embodiment, when the request function name in the traversed test case matches the function name of the preconfigured function, it indicates that there is a callable preconfigured function for the traversed test case, so that the request construction information of the preset type can be obtained according to the request construction method indicated by the preconfigured function, and then a test request is generated. There is no need to fill in the request construction information of the preset type in the test case table in advance, which can be flexibly configured to reduce operation and maintenance costs.
[0097] In one embodiment, when the request construction method indicated by the preconfigured function indicates that the request construction information required for the test request includes request construction information of a preset type, the test server may obtain the request construction information of the preset type according to the request construction method indicated by the preconfigured function.
[0098] In one embodiment, when the request construction mode indicated by the preconfigured function indicates that the request construction information of the preset type is the preset information, the preset information is obtained as the request construction information of the preset type. The preset information may be, for example, preset request header information and / or preset request body information.
[0099] In one embodiment, when the request construction method indicated by the preconfiguration function indicates that the request construction information required for the test request includes request construction information of a preset type, and the request construction method indicated by the preconfiguration function indicates that the request construction information of the preset type is obtained based on the object identification information, the test server can obtain the request construction information of the preset type corresponding to the object identification information from the database based on the object identification information.
[0100] In one embodiment, the test server may determine the request action in the traversed test case, call the pre-packaged function corresponding to the request action, and generate a test request for testing the interface to be tested according to the request construction information of the preset type and the address of the interface to be tested through the pre-packaged function. Among them, the pre-packaged function may be a function pre-packaged for different request actions. The pre-packaged function may be encapsulated by the Requests module in the Python development tool; through the pre-packaged function, the corresponding request action, the request construction information of the preset type and the address of the interface to be tested may be spliced into a test request. The test request may be in the form of a string.
[0101] In one embodiment, the above-mentioned step of generating a test request for testing the interface to be tested according to the request construction information of the preset type and the address of the interface to be tested includes: when the object identification information is obtained according to the request construction method indicated by the preconfigured function, and the request header information and request body information corresponding to the object identification information are obtained based on the object identification information, the obtained request header information and request body information are determined as the request construction information of the preset type; the request body information is encrypting to generate encrypted request body information; and a test request for testing the interface to be tested is generated according to the request header information, the encrypted request body information and the address of the interface to be tested.
[0102] The object identification information is the identity identification information of the registered object in the system to be tested. The object identification information may be a user's mobile phone number, a user ID (Identity document), etc. For example, when the system to be tested is a merchant system, the object identification information may be a merchant ID.
[0103] In this embodiment, the corresponding request header information and request body information are obtained based on the object identification information. There is no need to fixedly write the request header information and request body information in the test case table. When the request header information and request body information change, there is no need to specially maintain the test case table, thereby reducing operation and maintenance costs.
[0104] In one embodiment, when the request construction method indicated by the preconfigured function indicates that the request construction information required for the test request includes request construction information of a preset type, and the request construction method indicated by the preconfigured function indicates that the request construction information of the preset type is obtained based on object identification information, the test server can obtain the request header information and request body information corresponding to the object identification information from the database based on the object identification information.
[0105] In one embodiment, the test server may concatenate the request header information, the encrypted request body information, the address of the interface to be tested, and the request actions in the traversed test cases to generate a test request for testing the interface to be tested.
[0106] In one embodiment, in a specific application scenario, the above interface testing method can be based on Python development tools and the Requests module in Python development tools (Http library developed based on Python), and the simplified flow chart of the interface testing steps can be as follows: Figure 3 As shown, based on Figure 3 The above interface testing method may specifically include the following steps.
[0107] The test server can receive and store the test case table (which can be a test case Excel table) transmitted by the terminal. Among them, the test case table is obtained through configuration, and different systems to be tested can correspond to different test case tables, and are identified by different test case table names. The test case table can be headered with preset fields and the table body can be multiple test cases. The preset fields include the request function name field, the request action field, the address field of the interface to be tested, the test assertion field, the request header information field, the request body information field, the file path field (file-path), the file name field (file-name), the test case identification field, the environment variable field and the remarks field. When configuring the test case table, field values can be filled in according to the preset fields to form a test case. Each test case may include the field values of all fields in the preset fields; each test case may also include only the field values of some fields in the preset fields. For example, the test case may only include the request function name, request action, address of the interface to be tested, test assertion, request header information, test case identifier and environment variables. Among them, when the system to be tested is a merchant system, the request header information can be dynamically obtained from the database through the merchant ID corresponding to the interface to be tested indicated by the test case.
[0108] The test server can encapsulate pre-packaged functions corresponding to different request actions through the Requests module in the Python development tool. The test server can encapsulate a test case reading function for reading a test case Excel table and a test case writing function for writing data in a test case Excel table.
[0109] Every 30 minutes, the test server can create a test script through Python to perform interface automation testing and execute the test script; specifically, during the execution of the test script, the test server can start a thread and obtain the field value of the test switch field in the pre-configured database table. When the field value indicates that the test switch state is the test-on state (for example, the field value is 1), the With Imbox function (a function provided by Python for reading emails) is used to obtain an email with the email receiving time of today and the tester's email address as the recipient's email address; when there is a target email in the obtained email whose sender's email address is a preset email address (for example, the operation and maintenance personnel's email address), the title contains the first keyword (for example, special project, urgent demand, hot fix, iteration, technical optimization), and the body contains the second keyword (for example, completion), and the email receiving time of the latest target email is no more than 30 minutes from the current time, then the pre-configured test case table is obtained.
[0110] Among them, when the field value represents that the test switch state is the test closed state (for example, the field value is 0), the thread is terminated, or the email with the email receiving time of today and the tester's email address as the recipient email address cannot be obtained, or the target email cannot be obtained, or the email receiving time of the latest target email is greater than 30 minutes from the current time, then the thread is terminated and the Sleep function is used to wait for the next thread to be started (a cycle is every 30 minutes, that is, the thread is started every 30 minutes).
[0111] In the process of obtaining the preconfigured test case table, the test server may determine the system to be tested, obtain the file address of the test case table preconfigured for the system to be tested, and obtain the preconfigured test case table according to the test case table file address.
[0112] The test server can use the xld package (an extension tool for reading Excel tables) provided by Python to read and parse the test case table, and traverse the test cases in the test case table through the Sheet Index function. During the traversal process, the traversed test cases are read from the test case table, and the read test cases are inserted into a preconfigured list (a new list created when traversing the first test case in the test case table). Each test case can at least include a request function name, a request action (which can be called a request method), and an address of the interface to be tested in the system to be tested. The method of inserting test cases in the list can separate the test script from the test case.
[0113] The test server can obtain the request function name from the traversed test cases stored in the list. When the request function name in the traversed test case matches the function name of the preconfigured function, the preconfigured function is called. When the request header information and request body information do not exist in the traversed test case, the object identification information is obtained according to the request construction method indicated by the preconfigured function, and based on the object identification information (merchant ID) and through the PyMySQL library (a tool for performing MySQL database operations in Python), the database is connected to obtain the request header information and request body information corresponding to the object identification information, the obtained request information and request body information are determined as the request construction information of the preset type, the request body information is encrypted to generate encrypted request body information, and the pre-packaged function (do_equests function) corresponding to the request action in the traversed test case is determined. Through the pre-packaged function, a test request for testing the interface to be tested is generated according to the request header information, the encrypted request body information and the address of the interface to be tested.
[0114] Among them, when the request function name in the traversed test case does not match the function name of the pre-configured function, the instant messaging channel provided by the enterprise WeChat system is used as a virtual robot to send a Post request (Http request with the request action as Post) through the Requests module to the pre-configured notification receiving address (webhook address) to send a prompt message indicating the test case exception.
[0115] The test server can send a test request to the system to be tested; receive the response result fed back by the system to be tested in response to the test request; when the response result is determined to be normal according to the test assertion in the traversed test case (for example, the response status code is 200), it is determined that the test of the interface to be tested indicated by the traversed test case has passed, and the response data in JSON (JavaScript Object Notation, JS object notation) format is obtained, the response data and request body information are recorded accordingly, and the next test case in the test case table is continued until the test of the test case in the test case table is completed.
[0116] When the response result is determined to be abnormal according to the test assertions in the traversed test cases (for example, the response status code is not 200, but 404, 301, etc.), the test server can determine that the test of the interface to be tested indicated by the traversed test cases has failed; through the instant messaging channel provided by the WeChat enterprise system, as a virtual robot, send a Post request through the Requests module to the preconfigured notification receiving address, and send an alarm message indicating that the test of the interface to be tested has failed, so as to push the test report to the tester account in WeChat enterprise, and continue to the next test case in the test case table until the test of the test cases in the test case table is completed.
[0117] When the test cases in the test case table are completed and the interfaces to be tested indicated by the test cases in the test case table are all tested and passed, the test server can obtain the test completion time when the test is completed; when the test completion time is not within the preset time range, no action is taken; when the test completion time is within the preset time range, a notification message indicating the normal execution of the test is sent to the pre-configured notification receiving address through the instant messaging channel provided by the enterprise WeChat system as a virtual robot by sending a Post request through the Requests module.
[0118] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0119] Based on the same inventive concept, the embodiment of the present application also provides an interface testing device for implementing the interface testing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more interface testing device embodiments provided below can refer to the limitations on the interface testing method above, and will not be repeated here.
[0120] In one embodiment, Figure 4 As shown, an interface testing device 400 is provided, comprising: an acquisition module 410, a test request construction module 420, a test request sending module 430, a test request receiving module 440 and a test result determination module 450, wherein:
[0121] The acquisition module 410 is used to obtain an email with the tester's email address as the recipient's email address. When the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, a preconfigured test case table is obtained; the first keyword represents the adjustment action performed on the system to be tested, and the second keyword represents the completion of the adjustment action.
[0122] The test request construction module 420 is used to traverse the test cases in the test case table, obtain the address of the interface to be tested indicated by the traversed test cases in the system to be tested; and generate a test request for testing the interface to be tested according to the address of the interface to be tested according to the request construction method indicated by the function indicated by the request function name in the traversed test case.
[0123] The test request sending module 430 is used to send a test request to the system to be tested.
[0124] The test request receiving module 440 is used to receive a response result fed back by the system to be tested in response to the test request.
[0125] The test result determination module 450 is used to determine that the test of the interface to be tested indicated by the traversed test case has passed when the response result is determined to be normal according to the test assertions in the traversed test case.
[0126] In one embodiment, the acquisition module 410 is also used to obtain the field value of the test switch field in the preconfigured database table at every preset time interval; the field value of the test switch field is configured in the web page logged in as a tester; when the field value indicates that the test switch state is the test-on state, an email with the tester's email address as the recipient's email address is obtained.
[0127] In one embodiment, the test result determination module 450 is also used to determine that the test of the interface to be tested indicated by the traversed test case has failed when the response result is determined to be abnormal based on the test assertions in the traversed test case; and to send an alarm message indicating that the test of the interface to be tested has failed to a preconfigured notification receiving address through an instant messaging channel in the capacity of a virtual robot.
[0128] In one embodiment, the above-mentioned interface testing device 400 also includes an execution monitoring module, which is used to obtain the test completion time when the test cases in the test case table are tested and the interfaces to be tested indicated by the test cases in the test case table are tested and passed; when the test completion time is not within the preset time range, no action is taken; when the test completion time is within the preset time range, a notification message indicating that the test is executed normally is sent to a preconfigured notification receiving address through an instant messaging message channel as a virtual robot.
[0129] In one embodiment, the test request construction module 420 is also used to call the preconfigured function when the request function name in the traversed test case matches the function name of the preconfigured function; when the request construction information of a preset type is obtained according to the request construction method indicated by the preconfigured function, a test request for testing the interface to be tested is generated according to the request construction information of the preset type and the address of the interface to be tested.
[0130] In one embodiment, the test request construction module 420 is also used to obtain object identification information according to the request construction method indicated by the preconfigured function, and obtain request header information and request body information corresponding to the object identification information based on the object identification information, determine the obtained request header information and request body information as request construction information of a preset type; encrypt the request body information to generate encrypted request body information; and generate a test request for testing the interface to be tested based on the request header information, the encrypted request body information and the address of the interface to be tested.
[0131] Each module in the above interface test device can be implemented in whole or in part by software, hardware and their combination. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0132] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. 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, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data that needs to be stored when performing the above-mentioned interface test. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an interface testing method is implemented.
[0133] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0134] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0135] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0136] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0137] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0138] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0139] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0140] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An interface testing method, characterized in that: The method comprises: Obtain an email with the tester's email address as the recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, obtain a preconfigured test case table; the first keyword represents an adjustment action performed on the system to be tested, and the second keyword represents that the adjustment action is completed; Traversing the test cases in the test case table, and obtaining the address of the interface to be tested indicated by the traversed test cases in the system to be tested; When the request function name in the traversed test case matches the function name of the preconfigured function, the preconfigured function is called; When request construction information of a preset type is obtained according to the request construction method indicated by the preconfigured function, a test request for testing the interface to be tested is generated according to the request construction information of the preset type and the address of the interface to be tested; Sending the test request to the system to be tested; Receiving a response result fed back by the system to be tested in response to the test request; When the response result is determined to be normal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases has passed.
2. The method according to claim 1, characterized in that The step of obtaining an email with the tester's email address as the recipient's email address includes: At every preset time interval, a field value of a test switch field in a preconfigured database table is obtained; the field value of the test switch field is obtained by configuring in a web page logged in as a tester; When the field value indicates that the test switch state is the test-on state, an email with the tester's email address as the recipient's email address is obtained.
3. The method according to claim 1, characterized in that The method further comprises: When the response result is determined to be abnormal according to the test assertions in the traversed test cases, it is determined that the test of the interface to be tested indicated by the traversed test cases fails; Through the instant messaging channel, as a virtual robot, an alarm message indicating that the test of the interface to be tested has failed is sent to a preconfigured notification receiving address.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When the test cases in the test case table are tested and all the interfaces to be tested indicated by the test cases in the test case table are tested and passed, the test completion time when the test is completed is obtained; When the test completion time is not within the preset time range, no action is taken; When the test completion time is within the preset time range, a notification message indicating that the test is executed normally is sent to a preconfigured notification receiving address through an instant messaging channel as a virtual robot.
5. The method according to claim 1, characterized in that The method further comprises: When the request construction mode indicated by the preconfigured function indicates that the request construction information of the preset type is the preset information, the preset information is obtained as the request construction information of the preset type.
6. The method according to claim 1, characterized in that When the request construction information of a preset type is obtained according to the request construction method indicated by the preconfigured function, a test request for testing the interface to be tested is generated according to the request construction information of the preset type and the address of the interface to be tested, including: When the object identification information is obtained according to the request construction method indicated by the preconfigured function, and the request header information and request body information corresponding to the object identification information are obtained based on the object identification information, the obtained request header information and request body information are determined as request construction information of a preset type; Encrypting the request body information to generate encrypted request body information; A test request for testing the interface to be tested is generated according to the request header information, the encrypted request body information and the address of the interface to be tested.
7. An interface testing device, characterized in that: The device comprises: An acquisition module is used to acquire an email with a tester's email address as a recipient's email address, and when the sender's email address of the email is a preset email address, the title of the email contains a first keyword, and the body of the email contains a second keyword, a preconfigured test case table is acquired; the first keyword represents an adjustment action to be performed on the system to be tested, and the second keyword represents that the adjustment action is completed; A test request construction module is used to traverse the test cases in the test case table, obtain the address of the interface to be tested indicated by the traversed test cases in the system to be tested; when the request function name in the traversed test case matches the function name of the preconfigured function, call the preconfigured function; when the request construction information of a preset type is obtained according to the request construction method indicated by the preconfigured function, generate a test request for testing the interface to be tested according to the request construction information of the preset type and the address of the interface to be tested; A test request sending module, used for sending the test request to the system to be tested; A test request receiving module, used for receiving a response result fed back by the system to be tested in response to the test request; The test result determination module is used to determine that the test of the interface to be tested indicated by the traversed test case has passed when the response result is determined to be normal according to the test assertion in the traversed test case.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
