Automatic assertion method, device and equipment for self-defined assertion library and medium
By using a custom assertion library automatic assertion method, the problem of time-consuming manual judgment in interface testing tools is solved, automatic assertion is implemented, testing efficiency is improved and costs are reduced.
Patent Information
- Application Number
- CN202510734666.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-04
- Publication Date
- 2025-09-26
AI Technical Summary
Existing interface testing tools lack custom assertion libraries and automatic assertion capabilities, resulting in time-consuming manual judgment of interface results and increased enterprise costs.
Provides an automatic assertion method for a custom assertion library. Keywords are entered through templates and bound to the user. The data returned by the interface request is obtained and compared with the custom assertion library. The assertion results are determined based on forward and reverse use cases.
It improves the work efficiency of testers, reduces enterprise costs, and saves the process of manually judging whether the interface meets expectations through automatic assertions.
Smart Images

Figure CN120705037A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic test interfaces, and in particular to a method, device, equipment and medium for automatic assertion of a user-defined assertion library. Background Art
[0002] Existing interface testing tools lack their own assertion libraries and automated assertion capabilities. For example, when a user has hundreds or even thousands of interfaces requiring validation, each one must return a corresponding result. Manually reviewing each one is very slow, time-consuming, and increases costs for the enterprise. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for automatic assertion of a custom assertion library, thereby improving the work efficiency of testers and reducing the cost of enterprises.
[0004] In a first aspect, the present invention provides a method for automatically asserting a custom assertion library, comprising the following steps:
[0005] Step 1: Enter the set keywords into the custom assertion library through the template and bind the custom assertion library to the user;
[0006] Step 2: Obtain the return data when the user makes an interface request, and compare the return data with the keywords in the user's custom assertion library one by one;
[0007] Step 3. According to the forward use case and the reverse use case, if it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
[0008] In a second aspect, the present invention provides a device for automatically asserting a custom assertion library, comprising:
[0009] Set up the assertion library module, input the set keywords into the custom assertion library through the template, and bind the custom assertion library to the user;
[0010] A return data acquisition module acquires the return data of the user's interface request and compares the return data with the keywords in the user's custom assertion library one by one;
[0011] The comparison module is based on the forward use case and the reverse use case. If it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
[0012] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.
[0013] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the method described in the first aspect when the program is executed by a processor.
[0014] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:
[0015] The present invention allows different users to set up their own custom error assertion library (equivalent to setting up their own judgment rules). When an interface request returns content, it can automatically assert whether it meets expectations based on its own assertion library, saving the manual process of judging whether the interface meets expectations. Users only need to look at the final summarized results, which greatly facilitates user use and improves user work efficiency.
[0016] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0018] Figure 1 This is a flowchart of the method in Example 1 of the present invention;
[0019] Figure 2 This is a schematic diagram of the structure of the device in Example 2 of the present invention. DETAILED DESCRIPTION
[0020] The embodiments of the present application provide a method, apparatus, device, and medium for automatic assertion of a custom assertion library, thereby facilitating targeted testing for each user and improving testing efficiency.
[0021] The technical solutions in the embodiments of this application have the following general ideas:
[0022] 1. Use the Excel template to write the error assertion library keywords you need, such as fail, error, etc. for import. When importing, it will be bound according to the user's identity information (account, etc.) to achieve data separation, so that different users can have their own error assertion library.
[0023] 2. When the bound user makes any interface request, when the interface data is returned, it will automatically assert whether it meets expectations based on the keywords of the custom error assertion library that the user has previously imported. This can be used in both forward and reverse use cases. In the forward case, the result is retrieved from the error assertion keyword list. If it does not exist, it meets expectations; otherwise, it does not meet expectations. In the reverse use case scenario, the result is retrieved from the error assertion keyword list. If it exists, it meets expectations; otherwise, it does not meet expectations.
[0024] Take a positive use case example: for example, if the interface returns status: 200, message "succeed", there is no imported fail, error, etc., so the assertion is in line with expectations. If it returns status: 400, message "error", the assertion is not in line with expectations.
[0025] 3. If the user is found not to have bound their own custom error assertion library when the interface is requested, the system default error assertion library (the default value hard-coded in the program) will be used to automatically assert whether it meets expectations.
[0026] 4. Summarize the results of automatic assertions, including interface data, into a table for display.
[0027] The present invention is used to implement a Web application with a custom assertion function, specifically as follows:
[0028] In the HTML part:
[0029] 1. Import custom assertion button
[0030] A button is defined, and when the user clicks it, a custom assertion function is triggered.
[0031] The button is styled using Tailwind CSS, with gradient backgrounds, hover effects, shadows, and more.
[0032] The button contains an SVG icon and the text "Import Custom Assertions" inside.
[0033] 2. Custom assertion pop-up window
[0034] A modal pop-up window (customAssertModal) is defined to display the related operations of custom assertions.
[0035] The pop-up window contains a close button, which calls the closeCustomAssertModal() function to close the pop-up window.
[0036] There are two buttons in the pop-up window:
[0037] Download template: Click to call the downloadAssertTemplate() function, which may be used to download the assertion template file.
[0038] Import assertion: Clicking on it triggers a file selector where the user can select an Excel file (via<inputtype="file"id="assertFileInput"accept=".xlsx"> Implementation), and call the handleAssertFileUpload() function to handle file upload.
[0039] In the JavaScript part:
[0040] 1. updateLogEntries() function is used to update the display of request records.
[0041] Function:
[0042] First, add a button to export request records on the page.
[0043] Get the unexpected keyword list (by calling the / get_unexpected_keywords / interface).
[0044] Use the checkBatchResultMeetsExpectation() function to check whether the response content of each request record contains unexpected keywords.
[0045] Based on the inspection results, the request record is inserted into the page in HTML format and displayed whether it meets expectations (green indicates compliance with expectations, red indicates non-compliance).
[0046] If the acquisition of unexpected keywords fails, the request record will still be displayed, but it will not show whether it meets expectations.
[0047] 2. exportRequestLog() function, used to export request records.
[0048] Function:
[0049] Checks whether there are any exportable request records, and prompts the user if not.
[0050] Get the unexpected keyword list (by calling the / get_unexpected_keywords / interface).
[0051] Use the checkBatchResultMeetsExpectation() function to check whether the response content of each request record contains unexpected keywords.
[0052] Encapsulate all request records (including whether they meet the expected results) into a FormData object and send it to the backend / download_request_log / interface through a POST request.
[0053] The backend returns a file (such as an Excel file), and the frontend creates a hidden Tag to trigger the file download.
[0054] 3. updateParameterizationEntries() function is used to update the result display of parameterized test.
[0055] Function:
[0056] Clears the existing display.
[0057] Traverse the history of parameterized tests and set the style based on whether it meets expectations (green means it meets expectations, red means it does not meet expectations).
[0058] Insert each test result into the page in HTML format.
[0059] 4. The checkBatchResultMeetsExpectation() function is used to check whether the response content meets expectations.
[0060] Function:
[0061] Convert the response content to a lowercase string.
[0062] Traverse the unexpected keyword list and return false (indicating that it does not meet expectations) if the response content contains any unexpected keyword.
[0063] If no unexpected keywords are included, it returns true (indicating that it meets expectations).
[0064] 5. File upload processing logic
[0065] When a user uploads an Excel file through the file chooser, the handleAssertFileUpload() function is triggered.
[0066] Function:
[0067] Use FileReader to read the uploaded file content.
[0068] Use the XLSX library to parse Excel files and convert table data into JSON format.
[0069] Traverse each row of data in the table and dynamically generate a new request based on the URL, method and request body in the table.
[0070] Use fetch to send a request and display the result on the page in HTML format.
[0071] The result of each request will display the URL, method, request parameters, status code, response time, response content, and whether it meets expectations.
[0072] 6. fetchUnexpectedKeywords() function is used to obtain a list of unexpected keywords.
[0073] Function:
[0074] Call the / get_unexpected_keywords / interface to obtain a list of unexpected keywords.
[0075] Returns a Promise that resolves to a list of keywords.
[0076] Contains two Python methods:
[0077] defcheck_result_meets_expectation(self,response_data):
[0078]
[0079] return False#Returns False when it contains keywords
[0080] return True#Return True when it does not contain keywords
[0081] except Exception as e:
[0082] print(f"An error occurred while checking whether the batch request results met expectations: {str(e)}")
[0083] return True#When an error occurs, the default return is as expected
[0084] check_result_meets_expectation(): Checks whether the test result meets expectations. If the response content contains unexpected keywords, it returns True (indicating that it does not meet expectations).
[0085] check_batch_result_meets_expectation(): Checks whether the batch request result meets expectations. The logic is opposite to check_result_meets_expectation(). If the response content contains unexpected keywords, it returns False (indicating that it does not meet expectations).
[0086] The present invention is used for:
[0087] 1. Display and process custom assertion functions.
[0088] 2. Update and display request records.
[0089] 3. Export request records to Excel files.
[0090] 4. Process the result display of parameterized test.
[0091] 5. Check whether the response content meets expectations.
[0092] 6. Upload Excel file and generate request dynamically.
[0093] Example 1
[0094] like Figure 1 As shown, this embodiment provides a method for automatically asserting a custom assertion library, including the following steps:
[0095] Step 1: Enter the set keywords into the custom assertion library through the template and bind the custom assertion library to the user;
[0096] Step 2: Obtain the return data when the user makes an interface request, and compare the return data with the keywords in the user's custom assertion library one by one;
[0097] Step 3. According to the forward use case and the reverse use case, if it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
[0098] In this embodiment, preferably, step 2 is specifically as follows: setting up a page for the user to fill in the set basic information, converting the basic information into data in JSON format, wherein the basic information includes: request address, request type and request body; reading the interface request file uploaded by the user, parsing it, and obtaining parsed data; setting the format of the request data according to the type of request, obtaining the corresponding data from the parsed data, and if all the data exist, constructing the interface request data and making the interface request; if some of the data exist, obtaining the corresponding data from the basic information, and constructing the interface request data in combination with the data in the parsed data, and making the interface request; obtaining the return data when the user makes the interface request, and comparing the return data with the keywords in the user's custom assertion library one by one;
[0099] 1. Use the Excel template to write the interfaces you need to request (any number). When writing, you can miss any one or more of the URL, header, request method, request parameters, etc.
[0100] 2. Read the corresponding data by importing the Excel template. When no data can be read (information is missing), the compatibility logic will be triggered. By default, the corresponding missing data will be obtained from the interface of the requesting application. For example, if only the URL is written and nothing else is written, the matching data will be obtained from the URL matching application interface or the specified place to obtain the header, request method, and request parameters corresponding to the URL.
[0101] Specifically:
[0102] 1. Data in Excel file
[0103] The data in the Excel file is dynamic, and each row of data usually contains the following content (according to the code logic):
[0104] URL: The requested address.
[0105] Method: Request method (i.e. request type, such as GET, POST, etc.).
[0106] RequestBody: The content of the request body (usually form data or data in other formats).
[0107] These data are obtained in the code in the following ways:
[0108] javascript
[0109] const[urlValue,methodValue,requestBody]=row;
[0110] urlValue: The request address read from Excel.
[0111] methodValue: The request method read from Excel.
[0112] requestBody: The request body content read from Excel.
[0113] 2. Data in the page form
[0114] The data in the page form are fixed parameters entered by the user on the page. These parameters will be combined with the data in Excel to form the complete request parameters. The code obtains the form data in the following way:
[0115] javascript
[0116] const formData=newFormData(document.getElementById('apiform'));
[0117] The form may contain the following fields:
[0118] address: The default request address (if no URL is specified from Excel).
[0119] method: The default request method (if no method is specified from Excel).
[0120] request_data: The default request body content (if no request body is specified from Excel).
[0121] Other fields: may also include some additional request headers or other parameters.
[0122] 3. Combination of request parameters
[0123] Before sending the request, the code combines the data in Excel with the data in the form to form the final request parameters. The specific combination logic is as follows:
[0124] 3.1 Constructing new form data
[0125] javascript
[0126] constnewFormData=newFormData();
[0127] for(let[key,value]offormData.entries()){
[0128] if(key===='request_data'){
[0129] newFormData.append(key,requestBody); / / Use the request body in Excel
[0130] }else if(key==='address'&&urlValue){
[0131] newFormData.append(key,urlValue); / / Use the URL in Excel
[0132] }else if(key==='method'&&methodValue){
[0133] newFormData.append(key,methodValue); / / Use the method in Excel
[0134] }else{
[0135] newFormData.append(key,value); / / Use the default value in the form
[0136] }
[0137] }
[0138] If requestBody is specified in Excel, the value in Excel is used; otherwise, the default value in the form is used.
[0139] If urlValue is specified in Excel, the value in Excel is used; otherwise, the default value in the form is used.
[0140] If methodValue is specified in Excel, the value in Excel is used; otherwise, the default value in the form is used.
[0141] The other fields use the values directly from the form.
[0142] 3.2 Setting Request Options
[0143] javascript
[0144] let fetchOptions = {
[0145] method:methodValue||formData.get('method'), / / Use the method in Excel or the default method in the form
[0146] headers:{
[0147] 'Accept':'application / json'
[0148] }
[0149] };
[0150] The request method (method) gives priority to the value in Excel, and if there is no value, it uses the default value in the form.
[0151] The Accept: application / json header is set in the request header, indicating that the response is expected to be in JSON format.
[0152] 3.3 Processing request body and query parameters
[0153] javascript
[0154] if(fetchOptions.method.toUpperCase()==='GET'){
[0155] newFormData.forEach((value,key)=>{
[0156] url.searchParams.append(key,value); / / Append form data as query parameters to the URL
[0157]
[0158] If the request method is GET, the form data is appended to the URL as query parameters.
[0159] If it is another method (such as POST), the form data is sent as the request body.
[0160] 4. Summary: Parameters required by the request interface
[0161] According to the above logic, the request interface requires the following parameters:
[0162] Required parameters include:
[0163] URL: The requested address (obtained from Excel or the default value in the form).
[0164] Method: The requested method (obtained from Excel or the default value in the form).
[0165] RequestBody (optional): The content of the request body (obtained from Excel or the default value in the form).
[0166] Optional parameters include:
[0167] Other form fields: Depending on the form design, some additional request headers or other parameters may also be included.
[0168] Query parameters: If the request method is GET, the form data will be appended to the URL as query parameters.
[0169] 5. Examples
[0170] Assume that the Excel file contains the following content:
[0171] URL Method RequestBody https: / / example.com POST {"key":"value"}
[0172] Assume that you have the following fields in your form:
[0173] address: https: / / default.com
[0174] method: GET
[0175] request_data:{"default":"data"}
[0176] Then, the final request parameters are:
[0177] URL: https: / / example.com (from Excel)
[0178] Method: POST (from Excel)
[0179] RequestBody: {"key":"value"} (from Excel)
[0180] If a row of Excel data does not specify a URL or Method, the default value in the form will be used.
[0181] This embodiment preferably further includes step 4: if the user has not bound a custom assertion library, then the return data is judged according to the default assertion library;
[0182] The judgment includes: check_result_meets_expectation method and check_batch_result_meets_expectation method;
[0183] The check_result_meets_expectation method is used to check whether the test result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns True, indicating that it does not meet expectations; otherwise, it returns False, indicating that it meets expectations.
[0184] The check_batch_result_meets_expectation method is used to check whether the request result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns False, indicating that it does not meet expectations; otherwise, it returns True, indicating that it meets expectations.
[0185] This embodiment preferably further includes step 5, aggregating the assertion results and interface data into an Excel spreadsheet, marking the rows that meet expectations and those that do not meet expectations with different colors for display.
[0186] Based on the same inventive concept, this application also provides a device corresponding to the method in Example 1, see Example 2 for details.
[0187] Example 2
[0188] like Figure 2 As shown, in this embodiment, a device for automatically asserting a custom assertion library is provided, including:
[0189] Set up the assertion library module, input the set keywords into the custom assertion library through the template, and bind the custom assertion library to the user;
[0190] A return data acquisition module acquires the return data of the user's interface request and compares the return data with the keywords in the user's custom assertion library one by one;
[0191] The comparison module is based on the forward use case and the reverse use case. If it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
[0192] In this embodiment, preferably, the module for obtaining return data is specifically as follows: setting up a page for users to fill in the set basic information, converting the basic information into data in JSON format, wherein the basic information includes: request address, request type and request body; reading the interface request file uploaded by the user, and parsing it to obtain parsed data; setting the format of the request data according to the type of request, obtaining the corresponding data from the parsed data, if all exist, constructing the interface request data, and making an interface request; if part of it exists, obtaining the corresponding data from the basic information, and constructing the interface request data in combination with the data in the parsed data, and making an interface request; obtaining the return data when the user makes the interface request, and comparing the return data with the keywords in the user's custom assertion library one by one.
[0193] This embodiment preferably further includes a default comparison module. If the user does not bind a custom assertion library, the returned data is judged according to the default assertion library.
[0194] The judgment includes: check_result_meets_expectation method and check_batch_result_meets_expectation method;
[0195] The check_result_meets_expectation method is used to check whether the test result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns True, indicating that it does not meet expectations; otherwise, it returns False, indicating that it meets expectations.
[0196] The check_batch_result_meets_expectation method is used to check whether the request result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns False, indicating that it does not meet expectations; otherwise, it returns True, indicating that it meets expectations.
[0197] This embodiment preferably further includes a display module, which summarizes the assertion results and interface data into an Excel spreadsheet, and marks the rows that meet expectations and those that do not meet expectations with different colors for display.
[0198] Since the device described in the second embodiment of the present invention is used to implement the method of the first embodiment of the present invention, those skilled in the art will be able to understand the specific structure and variations of the device based on the method described in the first embodiment of the present invention, and therefore will not be described in detail here. All devices used in the method of the first embodiment of the present invention fall within the scope of protection of the present invention.
[0199] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details.
[0200] Example 3
[0201] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.
[0202] Since the electronic device described in this embodiment is the device used to implement the method in Example 1 of this application, based on the method described in Example 1 of this application, those skilled in the art will be able to understand the specific implementation of the electronic device of this embodiment and its various variations. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. As long as the device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection to be provided by this application.
[0203] Based on the same inventive concept, this application provides a storage medium corresponding to Example 1, see Example 4 for details.
[0204] Example 4
[0205] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any implementation method in the first embodiment can be implemented.
[0206] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0207] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0208] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0209] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0210] Although the specific embodiments of the present invention are described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A method for automatic assertion of a custom assertion library, characterized by: The steps include: Step 1: Enter the set keywords into the custom assertion library through the template and bind the custom assertion library to the user; Step 2: Obtain the return data when the user makes an interface request, and compare the return data with the keywords in the user's custom assertion library one by one; Step 3. According to the forward use case and the reverse use case, if it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
2. The method for automatic assertion of a custom assertion library according to claim 1, characterized in that: The step 2 is specifically as follows: setting up a page for users to fill in the set basic information, converting the basic information into JSON format data, the basic information including: request address, request type and request body; reading the interface request file uploaded by the user, and parsing it to obtain parsed data; setting the format of the request data according to the type of request, obtaining the corresponding data from the parsed data, if all exist, constructing the interface request data, and making an interface request; if some exist, obtaining the corresponding data from the basic information, and combining the data in the parsed data to construct the interface request data, and making an interface request; obtaining the return data when the user makes the interface request, and comparing the return data with the keywords in the user's custom assertion library one by one.
3. The method for automatic assertion of a custom assertion library according to claim 1, characterized in that: The process also includes step 4: if the user has not bound a custom assertion library, the return data is judged based on the default assertion library; The judgment includes: check_result_meets_expectation method and check_batch_result_meets_expectation method; The check_result_meets_expectation method is used to check whether the test result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns True, indicating that it does not meet expectations; otherwise, it returns False, indicating that it meets expectations. The check_batch_result_meets_expectation method is used to check whether the request result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns False, indicating that it does not meet expectations; otherwise, it returns True, indicating that it meets expectations.
4. The method for automatic assertion of a custom assertion library according to claim 1, characterized in that: It also includes step 5, summarizing the assertion results and interface data into an Excel table, marking the rows that meet expectations and those that do not meet expectations with different colors for display.
5. A device for automatically asserting a custom assertion library, characterized by: include: Set up the assertion library module, input the set keywords into the custom assertion library through the template, and bind the custom assertion library to the user; A return data acquisition module acquires the return data of the user's interface request and compares the return data with the keywords in the user's custom assertion library one by one; The comparison module is based on the forward use case and the reverse use case. If it is a forward test case, if the return data exists in the custom assertion library, it is not in line with expectations; if not, it is in line with expectations; if it is a reverse test case, if the return data exists in the custom assertion library, it is in line with expectations; if not, it is not in line with expectations, and the assertion result is obtained.
6. The device for automatically asserting a user-defined assertion library according to claim 5, characterized in that: The module for obtaining return data specifically includes: setting up a page for users to fill in the set basic information, and converting the basic information into data in JSON format, where the basic information includes: request address, request type and request body; reading the interface request file uploaded by the user, and parsing it to obtain parsed data; setting the format of the request data according to the type of request, and obtaining the corresponding data from the parsed data. If all of the data exist, the interface request data is constructed to make an interface request; if some of the data exist, the corresponding data is obtained from the basic information, and the interface request data is constructed in combination with the data in the parsed data to make an interface request; obtaining the return data when the user makes the interface request, and comparing the return data with the keywords in the user's custom assertion library one by one.
7. The device for automatically asserting a user-defined assertion library according to claim 5, characterized in that: It also includes a default comparison module. If the user does not bind a custom assertion library, the returned data will be judged based on the default assertion library. The judgment includes: check_result_meets_expectation method and check_batch_result_meets_expectation method; The check_result_meets_expectation method is used to check whether the test result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns True, indicating that it does not meet expectations; otherwise, it returns False, indicating that it meets expectations. The check_batch_result_meets_expectation method is used to check whether the request result meets expectations. If the return data exists in the custom assertion library or the default assertion library, it returns False, indicating that it does not meet expectations; otherwise, it returns True, indicating that it meets expectations.
8. The device for automatically asserting a user-defined assertion library according to claim 5, characterized in that: It also includes a display module that summarizes the assertion results and interface data into an Excel spreadsheet, and marks the rows that meet expectations and those that do not meet expectations with different colors for display.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.