Interface testing method and device and electronic equipment
Through the automated analysis of interface test requests and the generation and call of agents, the problems of low accuracy and efficiency of manual testing are solved, and the efficiency, accuracy and comprehensive coverage of interface tests are achieved, the testing cost is reduced, and the software quality is improved.
Patent Information
- Application Number
- CN202510385129.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-28
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, the accuracy and efficiency of manual interface function testing is low, making it difficult to effectively cover all test scenarios in software development, and the test results are highly inconsistent.
By receiving interface test requests, analyzing test items and data, selecting appropriate test agents to perform test operations, generating test results, using target documents to parse configuration information to generate agents, using large language models to parse natural language requests, and automatically generate and call test agents for testing.
It improves the accuracy and efficiency of interface testing, ensures the comprehensiveness and consistency of the test, reduces the tedious work of manually writing scripts, reduces the testing cost, and improves the reliability and test quality of the software.
Smart Images

Figure CN120276991A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, device, and electronic device for testing an interface. Background Art
[0002] In modern software development, with the popularization of the microservices architecture, the number of interfaces within and between software systems has increased explosively. In the face of this trend, the complexity and workload of software testing have also increased synchronously. Especially in ensuring the functional correctness, performance, and security of interfaces, the traditional manual testing method has gradually exposed the problem of low efficiency.
[0003] On the one hand, testers need to manually design and execute a large number of test cases. This process is not only time-consuming and laborious, but also often unable to cover all test scenarios due to time constraints in the face of frequent development iterations, thus increasing the risk of software defects. On the other hand, due to the subjectivity and non-standardization of manual testing, even in the same test scenario, different testers may obtain inconsistent test results, affecting the accuracy and repeatability of testing.
[0004] Regarding the problem of low accuracy and efficiency of manual interface function testing in related technologies, no effective solution has been proposed yet. Summary of the Invention
[0005] This application provides a method, device, and electronic device for testing an interface to solve the problem of low accuracy and efficiency of manual interface function testing in related technologies.
[0006] According to one aspect of this application, a method for testing an interface is provided. The method includes: receiving an interface test request sent by a test user; parsing the interface test request to obtain a test item and test data for testing a target interface; determining a target test agent corresponding to the test item from multiple test agents, where the test agent is used to execute an interface test operation; and calling the target test agent to execute the test item according to the test data to obtain a test result for the target interface.
[0007] Optionally, the multiple test agents are determined in the following manner: obtaining a target document for describing the target interface, and parsing the target document to obtain configuration information of the target interface; and generating agents for testing the target interface according to the configuration information to obtain multiple test agents.
[0008] Optionally, parse the target document to obtain the configuration information of the target interface, including: identifying the syntax structure of the target document, converting the target document according to the syntax structure to obtain a converted document; extracting the feature values corresponding to each preset keyword from the converted document to obtain multiple feature values; determining the processing flow for processing the feature values of each preset keyword, and processing the corresponding feature values through each processing flow to obtain the feature information corresponding to each preset keyword; and determining the configuration information of the target interface by associating each preset keyword with the corresponding feature information.
[0009] Optionally, generate agents for testing the target interface according to the configuration information, obtaining multiple test agents, including: obtaining multiple preset test scripts, where each preset test script is used to describe a test item; inputting the configuration information into each preset test script to obtain multiple target test scripts; and instantiating each target test script to obtain multiple test agents.
[0010] Optionally, parse the interface test request to obtain the test items and test data for testing the target interface, including: inputting the test request into the target large language model to obtain the parsed content; and identifying the test items and test data from the parsed content.
[0011] Optionally, the target large language model is trained in the following manner: obtaining multiple sample documents, where each sample document is written in natural language; obtaining the sample parsing results corresponding to each sample document, where the sample parsing results include test items and test data; determining a set of sample documents and sample parsing results as a set of sample data, obtaining multiple sets of sample data, and training the initial large language model with the multiple sets of sample data to obtain the target large language model.
[0012] Optionally, determine the target test agent corresponding to the test item from multiple test agents, including: determining the preset test items of the test scripts corresponding to each test agent; and determining the test agent with the same preset test item as the test item as the target test agent.
[0013] Optionally, call the target test agent to execute the test item according to the test data to obtain the test result of the target interface, including: sending the test data and test item to the target test agent and receiving the test parameters feedback by the target test agent; verifying the test parameters according to the parameter indicators corresponding to the test item to obtain the test result; and in the case where the test result indicates that the test parameters are abnormal, obtaining the abnormal test parameters and determining the cause of the abnormality according to the numerical information of the abnormal test parameters.
[0014] According to another aspect of the present application, a test device for an interface is provided. The device includes: a receiving unit for receiving an interface test request sent by a test user; a parsing unit for parsing the interface test request to obtain test items and test data for testing a target interface; a first determining unit for determining a target test agent corresponding to the test item from a plurality of test agents, where the test agent is used to perform an interface test operation; and a calling unit for calling the target test agent to execute the test item according to the test data to obtain a test result for the target interface.
[0015] According to another aspect of the present invention, a computer program product is also provided, including a computer program which, when executed by a processor, implements a test method for an interface provided in the foregoing embodiments of the present application.
[0016] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory; computer-readable instructions are stored in the memory, and the processor is used to run the computer-readable instructions, where the computer-readable instructions, when running, execute a test method for an interface provided in the foregoing embodiments.
[0017] Through the present application, the following steps are adopted: receiving an interface test request sent by a test user; parsing the interface test request to obtain test items and test data for testing a target interface; determining a target test agent corresponding to the test item from a plurality of test agents, where the test agent is used to perform an interface test operation; and calling the target test agent to execute the test item according to the test data to obtain a test result for the target interface, which solves the problem of low accuracy and efficiency of manual interface function testing in the related art. By parsing the test request to obtain test items when receiving the interface test request, and selecting a corresponding test agent according to the test items, and calling the test agent to execute the corresponding test item for the interface, so as to obtain a test result, thereby achieving the effect of improving the accuracy and test efficiency of interface testing. Description of the Drawings
[0018] The drawings forming a part of the present application are used to provide a further understanding of the present application. The schematic embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0019] Figure 1 is a flowchart of a test method for an interface provided in an embodiment of the present application;
[0020] Figure 2 is a flowchart of an optional test method for an interface provided in an embodiment of the present application;
[0021] Figure 3It is a schematic diagram of a test device for an interface provided according to an embodiment of the present application;
[0022] Figure 4 It is a schematic diagram of an electronic device provided according to an embodiment of the present application. Detailed implementation manners
[0023] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data may be interchanged under appropriate circumstances for the embodiments of the present application described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0026] It should be noted that the test method, device, and electronic device for the interface determined by the present disclosure can be used in the field of computer technology, and can also be used in any field other than the field of computer technology. The application fields of the test method, device, and electronic device for the interface determined by the present disclosure are not limited.
[0027] It should be noted that the information collected, user information (including but not limited to user device information, user personal information, etc.), and data (including but not limited to data for analysis, stored data, displayed data, etc.) used in this application are all information and data authorized by the user or fully authorized by all parties. Moreover, the processing of relevant data, such as collection, storage, use, processing, transmission, provision, disclosure, and application, complies with the relevant laws, regulations, and standards of the relevant regions, adopts necessary confidentiality measures, does not violate public order and good customs, and provides corresponding operation entrances for users to choose to authorize or refuse to use. If the user chooses to refuse, the expert decision-making process will be entered. For example, there is an interface between this system and relevant users or institutions. Before obtaining relevant information, a request for acquisition needs to be sent to the aforementioned users or institutions through the interface, and relevant information can be obtained after receiving the consent information feedback from the aforementioned users or institutions.
[0028] The embodiments or examples of the present disclosure are not exhaustive. They are only illustrations of some embodiments or examples and do not specifically limit the protection scope of the present disclosure. Without contradiction, each step in an embodiment or example can be implemented as an independent embodiment, and the steps can be combined arbitrarily. For example, the solution after removing some steps in an embodiment or example can also be implemented as an independent embodiment, and the order of the steps in an embodiment or example can be arbitrarily exchanged. Additionally, the optional methods or optional examples in an embodiment or example can be combined arbitrarily; furthermore, the embodiments or examples can be combined arbitrarily. For example, some or all of the steps of different embodiments or examples can be combined arbitrarily, and an embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0029] For ease of description, some nouns or terms related to the embodiments of this application are described below:
[0030] Agent: In computer science and automated testing, an agent usually refers to a software entity that can autonomously execute specific tasks. It can independently analyze the environment, make decisions, and take actions according to preset rules or algorithms.
[0031] Swagger document: Swagger is a specification and toolset for describing APIs. A Swagger document is a JSON (JavaScript Object Notation) file used to define the structure of an API in detail, including all possible interaction details such as paths, operations, parameters, responses, etc.
[0032] Interface: In software development, an interface usually refers to an agreement for communication and data exchange between different modules or systems. It defines a set of operations and the format of messages, enabling one system to send requests to another system and receive responses.
[0033] API: Application Programming Interface, which is an application programming interface.
[0034] JSON: JavaScript Object Notation, which is a lightweight data interchange format.
[0035] According to an embodiment of the present application, a method for testing an interface is provided.
[0036] Figure 1 It is a flowchart of the method for testing an interface provided according to an embodiment of the present application. As Figure 1 shown, the method includes the following steps:
[0037] Step S101, receive an interface test request sent by a test user.
[0038] It should be noted that the execution subject of this embodiment can be an automated test system for an interface. A test user refers to an individual or team that hopes to perform functional verification or performance testing on the interface of a certain system or service. An interface test request refers to a request submitted by a test user through a certain method (such as a test platform, command-line tool, or API call), which contains the interface information to be tested and test requirements.
[0039] Specifically, in this step, the front end or entry point of the automated test system receives the interface test request from the test user. The interface test request can be submitted through a graphical interface or by calling the system API through a command-line tool or script. The system ensures that the test requirements are accurately recorded and passed to subsequent processing links by receiving and identifying the interface test request.
[0040] For example, assume that a test user submits a test request for the "user login" interface of System A through a test management platform. The request contains the test priority, target environment (such as a test environment or pre-production environment), and specific test requirements (such as testing the exception handling when the username or password is incorrect). The automated test system can accept the interface test request sent by the test management platform and further process the interface test request in subsequent operations.
[0041] Step S102, parse the interface test request to obtain the test items and test data for testing the target interface.
[0042] It should be noted that the test items are the types and contents of tests to be executed, such as functional tests, performance tests, exception tests, etc. The test data are the specific input values for executing the tests, including the test data for normal scenarios and the data for testing exception situations.
[0043] Specifically, after receiving the interface test request, the automated test system needs to further parse the request content and extract the test items and test data. The above process involves the use of natural language processing or regular expressions, aiming to convert the unstructured or semi-structured test requirements submitted by users into structured data for subsequent agent scheduling and test execution.
[0044] For example, when the system parses the test request for the above "user login" interface, the identified test items are "response test under abnormal scenarios" and "verification of normal login function", and the test data required for these items are extracted, such as incorrect usernames, incorrect passwords, correct combinations of usernames and passwords, etc.
[0045] Step S103: Determine the target test agent corresponding to the test item from multiple test agents, where the test agents are used to perform interface test operations.
[0046] It should be noted that the multiple test agents refer to the set of agents prepared in advance in the system for performing different test tasks. The target test agent refers to the agent that matches a specific test item and is responsible for executing that test item. In this embodiment, the agent is used for automated interface testing, can automatically understand and execute test cases, interact with the target system interface, collect test data, and generate test reports.
[0047] Specifically, after determining the test item, the target test agent for performing the test operation can be selected according to the test item, that is, the most suitable target test agent needs to be selected from the test agent library according to the parsed test item and test data, so as to ensure that the selected agent can execute the above test item.
[0048] It should be noted that when selecting the target test agent, not only the type and function of the test agent need to be considered, but also the availability of resources, the priority of the test, and the dependencies need to be considered, so as to ensure the accuracy of the test operation performed on the interface.
[0049] For example, in the case where the test items are "response test under abnormal scenarios" and "verification of normal login function", two target test agents can be determined from the test agent library, one for abnormal scenario testing and the other for normal function verification, so as to ensure the accuracy and comprehensiveness of the test operation.
[0050] Step S104, call the target test agent to execute the test item according to the test data, and obtain the test result of the target interface.
[0051] It should be noted that the test result refers to the feedback information obtained after the test agent executes the test item, including but not limited to interface response time, response status code, whether the returned data meets the expectations, error logs, etc.
[0052] Specifically, after determining the target test agent, the system can send an execution instruction to the target test agent and simultaneously transmit the test data extracted from the test request. After receiving the instruction and data, the target test agent will send a request to the target interface and execute the preset test process. During the test process, the agent will record all data related to the test, including but not limited to request details, response status, execution time points, etc., so as to evaluate the performance, function, and stability of the interface using the obtained test data. After the test is completed, the agent will feedback the test result to the test system, and then enter the report generation stage.
[0053] Furthermore, in the report generation stage, the system can also generate a test report with a standardized format and detailed content by calling the report output agent to fill the data into the template. The report can be output in multiple formats to meet the needs of different users. Among them, the template can cover the test overview (including test scope, execution time, etc.), detailed test results (display the execution status of each test case classified by interface, including success or failure, specific error information, etc.), test statistical information (such as pass rate, failure rate, average response time, etc.), and the summary and suggestion part, so as to ensure the integrity and accuracy of the report.
[0054] For example, after the target test agent is called, it executes the abnormal scenario and normal function verification tests for the "user login" interface. In the abnormal scenario test, the agent uses incorrect username and password for login attempts and records the error status code and error information returned by the interface. In the normal function verification, the agent uses a set of correct username and password, successfully logs in and records the response time, status code, and returned user information. Finally, these test results are feedback to the test system, providing a data basis for the subsequent report generation.
[0055] The test method for the interface provided by the embodiments of the present application receives an interface test request sent by a test user; parses the interface test request to obtain test items and test data for testing the target interface; determines a target test agent corresponding to the test item from multiple test agents, where the test agent is used to execute the interface test operation; and calls the target test agent to execute the test item according to the test data to obtain the test result of the target interface, which solves the problem of low accuracy and efficiency of manually performing interface function tests in the related art. By parsing the test request to obtain the test item when receiving the interface test request, and selecting the corresponding test agent according to the test item, and calling the test agent to execute the corresponding test item on the interface to obtain the test result, the accuracy and test efficiency of the interface test are improved.
[0056] Optionally, in the test method for the interface provided by the embodiments of the present application, the multiple test agents are determined in the following manner: obtain a target document for describing the target interface, and parse the target document to obtain the configuration information of the target interface; generate agents for testing the target interface according to the configuration information to obtain multiple test agents.
[0057] It should be noted that the target document refers to a document describing the target interface information, such as a swagger document, which contains a detailed description of the interface, including the path, request and response parameter types, data format, etc. The configuration information is parsed from the target document and is the necessary parameters for generating the test agent, including but not limited to the URL (Uniform Resource Locator) of the interface, the request method, the parameter list and data type, the expected response format, etc.
[0058] Specifically, when determining the test agent, the automated test system first accesses a target document containing detailed interface information, such as a swagger document, and performs a syntax analysis on the swagger document through a dedicated parsing module to extract key information such as the interface name, request parameter type, response format, path, etc., so as to obtain the configuration information of the target interface. Among them, the parser needs to be able to understand and convert the syntax in the document and convert it into a data structure that can be understood by the system internally, so as to obtain the configuration information that can be recognized by the system.
[0059] Furthermore, based on the extracted configuration information, the system can generate an agent capable of testing the target interface, so as to use the test agent corresponding to the target document to test the target interface, thereby ensuring the accuracy of the agent's testing of the interface.
[0060] Through the above implementation process, this embodiment enables the automated test system to automatically parse the configuration information of the target interface from the target document (such as the swagger document), and then generate multiple targeted test agents. This automated agent generation mechanism greatly simplifies the work in the test preparation stage, avoids the cumbersome process of manually writing test scripts, and improves the efficiency and accuracy of testing. The creation of multiple test agents also ensures the comprehensiveness of the test, covering both normal and abnormal scenarios, thus ensuring that the software interface can run stably and reliably under various conditions.
[0061] Optionally, in the test method for the interface provided in the embodiment of the present application, parsing the target document to obtain the configuration information of the target interface includes: identifying the syntax structure of the target document, and converting the target document according to the syntax structure to obtain a converted document; extracting the feature values corresponding to each preset keyword from the converted document according to the preset keywords to obtain a plurality of feature values; determining the processing flow for processing the feature values of each preset keyword, and processing the corresponding feature values through each processing flow to obtain the feature information corresponding to each preset keyword; and determining the configuration information of the target interface by combining each preset keyword with the corresponding feature information.
[0062] It should be noted that the target document mainly refers to the specification document for describing the target interface, such as the swagger document, which contains all the details of the interface, such as the path, method, parameters, responses, etc. The syntax structure refers to the writing rules and formats of the target document, such as the JSON format of the swagger document. The preset keywords represent the important attributes of the interface, such as "path", "method", "parameters", and "responses", etc. The feature values are also the specific values related to the preset keywords, which describe specific aspects of the interface, such as the path of the interface, the type of request method, the name and type of parameters, the expected response format, etc. The processing flow refers to the steps for converting and processing the extracted feature values to adapt to the generation requirements of the test agents, such as converting the parameter type into a format recognizable by the test agents. The feature information is also the deeper and more specific detailed information describing the interface obtained after the processing flow, such as the verification rules of the parameters, the error codes of the responses, etc.
[0063] Specifically, when reading the configuration information, it is first necessary to identify the syntax structure of the target document. The system can identify the format of the target document (such as the JSON format of swagger) through a dedicated syntax parser and convert it into a unified and easy-to-process internal representation form (converted document), so as to unify different formats of target documents into an operable framework for subsequent steps to be executed.
[0064] Furthermore, the system can extract eigenvalue related to these keywords from the converted document according to the preset keyword list, so as to obtain the key attribute information constituting the target interface and provide basic data for the generation of the intelligent agent.
[0065] For example, the system can extract the path (" / login"), request method ("POST"), parameters (such as "username", "password") and expected response codes (such as "200", "401") of the "user login" interface from the converted JSON document.
[0066] Furthermore, in the case of obtaining multiple preset keywords and corresponding eigenvalues, the processing flow for processing the eigenvalues of each preset keyword can be determined, and the corresponding eigenvalues are processed through each processing flow to obtain the characteristic information corresponding to each preset keyword. That is, according to the extracted eigenvalues, through specific processing flows set by the system, such as format conversion of parameter values, simulation of abnormal responses, etc., to ensure that the generated test intelligent agent can correctly understand and execute the test, so as to convert the original eigenvalues into the characteristic information required for the generation and execution of the intelligent agent, and ensure the normal recognition and reading of the intelligent agent.
[0067] For example, the system converts the type information (such as string) of the extracted parameters "username" and "password" into a format recognizable by the test intelligent agent, and designs a retry mechanism and error handling process for the abnormal response code "401".
[0068] In the case of obtaining the characteristic information, the system can associate the processed characteristic information with the preset keywords to form the complete configuration information of the target interface, including the path, request method, parameters and verification rules, expected response, etc. of the interface, so as to construct a structured and detailed interface description as the basis for the generation of the test intelligent agent, that is, the configuration information.
[0069] Through the above steps, this embodiment realizes the process of automatically parsing and generating a test intelligent agent from the API document (target document), greatly improving the efficiency and accuracy of the automated test. The system can automatically identify and convert the syntax structure of the API document, extract the key interface configuration information, convert this information into characteristic information through a customized processing flow, and finally form a structured configuration information for generating multiple test intelligent agents. This process eliminates the cumbersome work of manually writing test scripts, ensures that the generation of the test intelligent agent can accurately match the interface requirements, and at the same time provides the necessary data basis for the automatic generation of test reports, enabling the entire test process from the understanding of test requirements to test execution and then to result analysis to be automated, significantly reducing the test cost and improving the test quality and software reliability.
[0070] Optionally, in the interface testing method provided by the embodiments of the present application, generating agents for testing a target interface according to configuration information, and obtaining multiple test agents includes: obtaining multiple preset test scripts, where each preset test script is used to describe a test item; inputting the configuration information into each preset test script to obtain multiple target test scripts; and performing an instantiation operation on each target test script to obtain multiple test agents.
[0071] It should be noted that the preset test script is also a test execution script template that is pre-written and standardized for common test items. These templates cover the basic logic of testing, including but not limited to interface request construction, parameter verification, response analysis, etc., aiming to quickly generate specific test codes by simply filling in configuration information. A test item is a specific test unit or scenario, and each test item focuses on verifying a certain aspect of the interface function, such as function correctness, performance testing, exception handling ability, etc. The configuration information is parsed from a target document (such as swagger) and is used to describe the detailed information of the interface, including but not limited to the interface path, request method, parameter type, and response format, etc. The target test script is a test script specific to a certain interface and test item after being filled with configuration information, and it can be directly used for the generation and test execution of test agents. The instantiation operation refers to the process of converting an abstract or templated test script into specific executable code, that is, converting the configuration information in the target test script into the executable logic of the test agent, so that the test agent can run independently and complete the test task.
[0072] Specifically, when generating test agents, the system first loads the pre-designed test scripts, which cover common test items such as functional testing, performance testing, security testing, etc., ensuring the comprehensiveness and professionalism of the testing. Through the preset scripts, the basic framework for the upcoming test items can be quickly built, reducing the time and workload of writing scripts from scratch every time a test is conducted.
[0073] Furthermore, the system automatically fills the configuration information parsed from the target document into the corresponding fields of the preset test script to generate a test script for a specific interface, and converts the target test script into a specific test agent. Each agent can run independently and perform corresponding test operations according to the filled configuration information, so that the test script is transformed into a test agent with action capabilities. Each agent can automatically complete the interface test, including initiating requests, processing responses, recording results, etc., thus realizing the automation of the test process through the agent.
[0074] In this embodiment, by automatically extracting configuration information from the target document, multiple test agents are quickly generated and instantiated, ensuring the accuracy and automation level of the test agents.
[0075] Optionally, in the interface test method provided by the embodiment of the present application, parsing the interface test request to obtain the test items and test data for testing the target interface includes: inputting the test request into the target large language model to obtain the parsed content; identifying the test items and test data from the parsed content.
[0076] It should be noted that the target large language model refers to a natural language processing model that has been specially trained and can understand and parse test requests in natural language form, accurately identifying the test items (i.e., specific functions or scenarios to be tested) and test data (such as input values for testing) contained therein.
[0077] Specifically, when obtaining the test items and test data, first, the test request sent by the user needs to be input into the target large language model. After receiving these requests, the model uses its natural language understanding and parsing capabilities to process and transform these texts, and extracts structured information from them.
[0078] For example, the request submitted by the test user is described as: "Test the functionality and performance of the user login interface. Log in with the correct username and password, check whether the response time after successful login is less than 2 seconds, and at the same time try the wrong password three times to see if the system can correctly return the 401 status code." The system inputs this request into the target large language model, and the model will parse out the key test requirements, including testing the functions and performance of the "user login" interface, logging in with the correct username and password, checking the response time, trying the wrong password three times, and the system should return the 401 status code, etc.
[0079] Furthermore, based on the parsed content returned by the model, the system can further analyze and extract to identify specific test items (such as function testing, performance testing) and corresponding test data (such as the username and password for login, the expected response time), and then can call the agent to execute the test operation according to the identified test items and test data.
[0080] In this embodiment, the target large language model parses and identifies test requests in natural language form, effectively solving the problems of unclear requirement understanding and cumbersome test case writing in traditional testing. The parsing ability of the model ensures the accurate transformation of test requirements, and the identification of test items and data provides clear guidance for the subsequent scheduling and execution of agents.
[0081] Optionally, in the interface test method provided in the embodiments of the present application, the target large language model is trained in the following manner: Obtain a plurality of sample documents, where each sample document is written in natural language; obtain the sample parsing results corresponding to each sample document, where the sample parsing results include test items and test data; determine a set of sample documents and sample parsing results as a set of sample data, obtain multiple sets of sample data, and train an initial large language model with the multiple sets of sample data to obtain the target large language model.
[0082] It should be noted that before using the target large language model, it is necessary to first train the large language model with sample data to ensure the accuracy of the parsing results generated by the large language model.
[0083] It should be noted that the sample document can be a test requirement document written in natural language, which can be a text describing scenarios such as functional testing, performance testing, and security testing, and is used as example data for input during model training. The sample parsing result refers to the structured information obtained after the sample document is parsed manually or processed by a preset parser, including test items and test data. The initial large language model can be an untrained model. The target large language model: After being trained with data in a specific domain, it can accurately understand and parse test requests written in natural language, extract the test items and test data therein, and be used for the efficient execution of the automated test process.
[0084] Specifically, when training the large language model, first, it is necessary to obtain a plurality of historical sample documents and obtain the parsing results of each sample document. Then, the sample document and the parsing result are used as a set of sample data, and the large language model is trained with multiple sets of sample data to obtain the target large language model.
[0085] This embodiment ensures the accurate parsing of the large language model for the document by training the large language model.
[0086] Optionally, in the interface test method provided in the embodiments of the present application, determining the target test agent corresponding to the test item from multiple test agents includes: determining the preset test items of the test scripts corresponding to each test agent; determining the test agent with the same preset test item as the test item as the target test agent.
[0087] Specifically, when determining the target test agent, first, the system needs to read the preset test items defined in its test script for each test agent in the test agent library, that is, which specific functions or scenarios the agent is designed to test, to form a mapping table between the test agent and the test item.
[0088] After receiving the specific test project requirements, the system searches in the above mapping table to filter out the test agents that match the preset test projects with the test projects in the current requirements as the target test agents for this test, ensuring that the called test agents can accurately cover and execute the current test requirements, avoiding resource waste and test redundancy, and improving the efficiency of the test process and the reliability of the results.
[0089] For example, there are two test agents in the system library. The preset test project of Agent A is "Function verification of user login interface", and the preset test project of Agent B is "Performance test of shopping cart interface". By reading and identifying the comments or specific tags in the test scripts of each agent, the system establishes the association relationship between the agent and the test project. Assuming that the current test requirement is "Function verification of user login interface", the system will search in the mapping table for the test agent with the preset test project of "Function verification of user login interface", that is, Agent A, and determine it as the target test agent to be responsible for executing this test task.
[0090] In this embodiment, by determining the preset test projects of the test agents and comparing them with the actual test requirements, the technical effect of quickly and accurately locating the most suitable target test agent is achieved.
[0091] Optionally, in the interface test method provided in the embodiment of the present application, calling the target test agent to execute the test project according to the test data to obtain the test result of the target interface includes: sending the test data and the test project to the target test agent and receiving the test parameters fed back by the target test agent; verifying the test parameters according to the parameter indicators corresponding to the test project to obtain the test result; in the case where the test result indicates that the test parameters are abnormal, obtaining the abnormal test parameters and determining the cause of the abnormality according to the numerical information of the abnormal test parameters.
[0092] Specifically, when determining the test result, the system needs to send this information to the target test agent after determining the test project to be executed and the specific test data. After receiving the instruction, the target test agent uses the test data to execute the test task according to the requirements of the test project and returns the various parameters recorded during the execution process, including but not limited to interface response time, status code, return data, etc.
[0093] After the system receives the test parameters fed back by the target test agent, it performs verification according to the preset parameter index range. If the parameter value meets the preset conditions, the test result is determined to be successful; otherwise, if the parameter value is abnormal, the test result is marked as failed. If the test result indicates the existence of abnormal test parameters, the system will further analyze the specific values of these parameters and combine the context information of the abnormal test parameters (such as operation steps, system environment status, etc.) to determine the possible causes of the abnormality, thereby completing the process of executing the test task, generating the test result, and the corresponding prompt information.
[0094] For example, when the system wants to perform a performance test on the "user login" interface, the preset test item is "interface response time", and the test data includes "correct username and password". The system sends this information to agent A, and agent A returns the specific response time record after performing the test. The preset parameter index for "interface response time" is that "the response time should be less than 2 seconds". The average response time fed back by agent A after performing the performance test is 1.5 seconds, which meets the preset conditions, and the system determines that the test result is successful. If the average response time fed back by agent A during the performance test of the "user login" interface is 4.1 seconds, far exceeding the preset index, the system will mark the test result as failed, and further obtain the abnormal test parameter "response time" and its value of 4.1 seconds, and analyze the possible abnormal causes in combination with the system log and network monitoring data, such as too high server load or increased network latency, etc.
[0095] In this embodiment, by automatically invoking the test agent, using the test data to execute the test item, and performing verification and anomaly detection on the test result, the efficiency and accuracy of the automated test are ensured. It can quickly locate the cause of the anomaly when the test fails, greatly shortening the problem-solving cycle and reducing the test cost. At the same time, through the detailed analysis of the test result, the system can provide detailed test reports for the testers, including the successful test items and the failed test items and their reasons, providing strong support for software development and maintenance.
[0096] Figure 2 is the flowchart of the test method for the optional interface provided according to the embodiment of the present application. As Figure 2 shown, first, the swagger interface definition operation is performed. The system first accesses the swagger document of the target project, which details the definitions of all API interfaces, including paths, request parameters, response formats, method types, etc. Then, the test agent generation operation is performed. Based on the extracted information, the system generates a test script template for each interface. The template contains basic request construction logic, parameter verification rules, and expected response verification parts, and instantiates the script template to obtain specific test agents.
[0097] It is also necessary to receive the test case document sent by the user, and use the large language model to process the test case document. Input the test case document into the pre-trained large model, and the large model uses its powerful natural language understanding ability to identify key elements such as test objectives, operation steps, and expected results in the document. After that, the agent engine matches the corresponding target test agent in the test agent library according to the test items and test data parsed by the large model, and sends an execution instruction.
[0098] After receiving the instruction and test data, the target test agent performs corresponding test operations according to the preset test process, and records the data during the test in real time, such as request information, response status code, response content, execution time, etc. After the agent completes the test, it sends the recorded test data back to the agent engine or directly to the report output agent. The report output agent collects the data of all test agents, analyzes them, compares the actual results with the expected results, and determines whether the test is successful. According to the analysis results, the report output agent generates a test report, which includes a test overview, detailed test results, test statistical information, and summary and suggestions, thus completing the process of automatically testing the test cases through the agent and generating test results.
[0099] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0100] The embodiment of the present application also provides a test device for an interface. It should be noted that the test device for the interface in the embodiment of the present application can be used to execute the test method for the interface provided by the embodiment of the present application. The following introduces the test device for the interface provided by the embodiment of the present application.
[0101] Figure 3 is a schematic diagram of the test device for the interface provided by the embodiment of the present application. As Figure 3 shown, the device includes: a receiving unit 31, an analysis unit 32, a first determination unit 33, and a calling unit 34.
[0102] The receiving unit 31 is used to receive the interface test request sent by the test user.
[0103] The parsing unit 32 is used to parse the interface test request to obtain the test items and test data for testing the target interface.
[0104] The first determination unit 33 is used to determine the target test agent corresponding to the test item from multiple test agents, where the test agent is used to perform interface test operations.
[0105] The calling unit 34 is configured to call a target test agent to execute a test item according to test data, and obtain a test result for the target interface.
[0106] The interface test device provided by the embodiment of the present application receives an interface test request sent by a test user through the receiving unit 31; the parsing unit 32 parses the interface test request to obtain a test item and test data for testing the target interface; the first determination unit 33 determines a target test agent corresponding to the test item from multiple test agents, where the test agent is used to execute an interface test operation; the calling unit 34 calls the target test agent to execute the test item according to the test data, and obtains a test result for the target interface. This solves the problem that the accuracy and efficiency of manual interface function testing in the related art are relatively low. When an interface test request is received, the test request is parsed to obtain a test item, and a corresponding test agent is selected according to the test item. The corresponding test item is executed on the interface by calling the test agent, so as to obtain a test result, thereby achieving the effect of improving the accuracy and test efficiency of interface testing.
[0107] Optionally, in the interface test device provided by the embodiment of the present application, the multiple test agents are determined in the following manner: a first acquisition unit is configured to acquire a target document for describing the target interface, and parse the target document to obtain configuration information of the target interface; a generation unit is configured to generate agents for testing the target interface according to the configuration information, and obtain multiple test agents.
[0108] Optionally, in the interface test device provided by the embodiment of the present application, the first acquisition unit includes: a first recognition module configured to recognize the syntax structure of the target document, and convert the target document according to the syntax structure to obtain a converted document; an extraction module configured to extract feature values corresponding to each preset keyword from the converted document according to a preset keyword, and obtain multiple feature values; a first determination module configured to determine a processing flow for processing the feature value of each preset keyword, and process the corresponding feature value through each processing flow to obtain feature information corresponding to each preset keyword; a second determination module configured to determine each preset keyword and the corresponding feature information as the configuration information of the target interface.
[0109] Optionally, in the interface test device provided by the embodiment of the present application, the generation unit includes: a first acquisition module configured to acquire multiple preset test scripts, where each preset test script is used to describe a test item; a first input module configured to input the configuration information into each preset test script to obtain multiple target test scripts; an instantiation module configured to perform an instantiation operation on each target test script to obtain multiple test agents.
[0110] Optionally, in the interface test device provided in the embodiments of the present application, the parsing unit 32 includes: a second input module, configured to input a test request into a target large language model to obtain parsed content; and a second recognition module, configured to recognize test items and test data from the parsed content.
[0111] Optionally, in the interface test device provided in the embodiments of the present application, the target large language model is trained in the following manner: a second acquisition unit, configured to acquire a plurality of sample documents, where each sample document is written in natural language; a third acquisition unit, configured to acquire sample parsing results corresponding to each sample document, where the sample parsing results include test items and test data; and a second determination unit, configured to determine a set of sample documents and sample parsing results as a set of sample data, obtain multiple sets of sample data, and train an initial large language model with the multiple sets of sample data to obtain the target large language model.
[0112] Optionally, in the interface test device provided in the embodiments of the present application, the first determination unit 33 includes: a third determination module, configured to determine preset test items of test scripts corresponding to each test agent; and a fourth determination module, configured to determine a test agent with the same preset test items as the test items as the target test agent.
[0113] Optionally, in the interface test device provided in the embodiments of the present application, the calling unit 34 includes: a receiving module, configured to send test data and test items to a target test agent and receive test parameters fed back by the target test agent; a verification module, configured to verify the test parameters according to parameter indicators corresponding to the test items to obtain a test result; and a second acquisition module, configured to, when the test result indicates that the test parameters are abnormal, acquire abnormal test parameters and determine the cause of the abnormality according to the numerical information of the abnormal test parameters.
[0114] The above-mentioned interface test device includes a processor and a memory. The above-mentioned receiving unit 31, parsing unit 32, first determination unit 33, calling unit 34, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to implement corresponding functions.
[0115] The processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and by adjusting the kernel parameters, the problems of low accuracy and efficiency of interface function testing through manual operation in the related art are solved.
[0116] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.
[0117] An embodiment of the present invention provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the test method of the interface is implemented.
[0118] An embodiment of the present invention provides a processor, which is used to run a program, and when the program runs, the test method of the interface is executed.
[0119] Figure 4 is a schematic diagram of an electronic device provided according to an embodiment of the present application, as Figure 4 shown, an embodiment of the present invention provides an electronic device. The electronic device 40 includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, the steps of the test method of the above interface are implemented. The devices herein may be servers, PCs, PADs, mobile phones, etc.
[0120] The present application also provides a computer program product, which is suitable for executing a program for initializing the steps of the test method of the above interface when executed on a data processing device.
[0121] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.
[0122] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows 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 the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate for implementing in the process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks the device for the specified function.
[0123] These computer program instructions can 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 generate a manufactured article including an instruction device, and the instruction device implements in the processFigure 1 one process or multiple processes and / or blocks Figure 1 the functions specified in one block or multiple blocks.
[0124] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 the steps of the functions specified in one block or multiple blocks.
[0125] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0126] The memory may include non-permanent memory in the computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
[0127] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
[0128] It should also be noted that the term "including", "comprising", or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity, or device that includes a series of elements includes not only those elements but also other elements not expressly listed, or elements that are inherent to such process, method, commodity, or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, commodity, or device that includes the element.
[0129] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A test method for an interface, characterized in that including: Receiving an interface test request sent by a test user; Parsing the interface test request to obtain test items and test data for testing a target interface; Determining a target test agent corresponding to the test item from multiple test agents, where the test agent is used to perform interface test operations; Invoking the target test agent to execute the test item according to the test data to obtain a test result for the target interface.
2. The method according to claim 1, characterized in that, The multiple test agents are determined in the following manner: Obtaining a target document for describing the target interface and parsing the target document to obtain configuration information of the target interface; Generating agents for testing the target interface according to the configuration information to obtain multiple test agents.
3. The method according to claim 2, characterized in that, Parsing the target document to obtain the configuration information of the target interface includes: Identifying the syntax structure of the target document and converting the target document according to the syntax structure to obtain a converted document; Extracting feature values corresponding to each preset keyword from the converted document according to the preset keywords to obtain multiple feature values; Determining a processing flow for processing the feature value of each preset keyword and processing the corresponding feature value through each processing flow to obtain feature information corresponding to each preset keyword; Determining each preset keyword and the corresponding feature information as the configuration information of the target interface.
4. The method according to claim 2, characterized in that, Generating agents for testing the target interface according to the configuration information to obtain multiple test agents includes: Obtaining multiple preset test scripts, where each preset test script is used to describe a test item; Inputting the configuration information into each preset test script to obtain multiple target test scripts; Performing an instantiation operation on each target test script to obtain the multiple test agents.
5. The method according to claim 1, wherein Parsing the interface test request to obtain test items and test data for testing a target interface includes: Inputting the test request into a target large language model to obtain parsing content; Identifying the test item and the test data from the parsing content.
6. The method according to claim 5, wherein The target large language model is trained in the following manner: Obtaining multiple sample documents, where each sample document is written in natural language; Obtaining sample parsing results corresponding to each sample document, where the sample parsing results include test items and test data; Determining a set of sample documents and sample parsing results as a set of sample data, obtaining multiple sets of sample data, and training an initial large language model with the multiple sets of sample data to obtain the target large language model.
7. The method according to claim 1, characterized in that Determining a target test agent corresponding to the test item from multiple test agents includes: Determining the preset test items of the test scripts corresponding to each test agent; Determining the test agent with the same preset test item as the test item as the target test agent.
8. The method according to claim 1, characterized in that, Invoking the target test agent to execute the test item according to the test data to obtain a test result for the target interface includes: Send the test data and the test item to the target test agent, and receive the test parameters fed back by the target test agent; Verify the test parameters according to the parameter indexes corresponding to the test item to obtain a test result; When the test result indicates that the test parameters are abnormal, obtain the abnormal test parameters, and determine the cause of the abnormality according to the numerical information of the abnormal test parameters.
9. A test device for an interface, characterized in that, Comprising: A receiving unit, configured to receive an interface test request sent by a test user; An analysis unit, configured to analyze the interface test request to obtain a test item and test data for testing a target interface; A first determination unit, configured to determine a target test agent corresponding to the test item from multiple test agents, wherein the test agent is used to perform an interface test operation; An invocation unit, configured to invoke the target test agent to execute the test item according to the test data to obtain a test result of the target interface.
10. An electronic device, characterized in that, Comprising: A memory, storing an executable program; A processor, configured to run the program, wherein when the program runs, it executes the test method of the interface according to any one of claims 1 to 8.
Citation Information
Cited By
Website testing method and device based on multiple agents and medium
CN121070806A