Automatic API test method, system, product and device based on large language model
By automatically generating and executing API test cases using a large language model, the problems of time-consuming, labor-intensive, and incomplete coverage in traditional API testing are solved, achieving efficient and accurate automated testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-29
- Publication Date
- 2026-03-13
AI Technical Summary
Traditional API testing methods are time-consuming, labor-intensive, error-prone, and unable to fully cover all testing scenarios, and they also fail to meet the needs of rapid iteration in development.
It uses a large language model to automatically generate test cases, understands user needs through natural language, and automates the test process, including generating, traversing, and verifying test cases, and performs multi-dimensional automated verification.
It improves testing efficiency, reduces the need for specialized skills, ensures the accuracy and comprehensiveness of testing, and can adapt to frequent API iterations.
Smart Images

Figure CN121658385A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to automated API testing methods, systems, products, and devices based on large language models. Background Technology
[0002] Traditional API testing verifies the functionality and quality of an API by having testers manually execute test cases. Testers manually construct requests based on the API (Application Programming Interface) documentation, send them using tools like Postman, and manually compare the expected results with the actual responses. For example, for an API that queries user information, testers manually enter the URL (Uniform Resource Locator), parameters, select the request method, send the request, and then compare the returned user information with the expected data. This approach relies heavily on the testers' understanding of the API's functionality and their manual operation skills.
[0003] For a large number of APIs and complex test scenarios, manually building requests and comparing results is time-consuming and labor-intensive. For example, in a large project with numerous APIs, each with multiple parameter combinations and business scenarios, manual testing has a long cycle and is difficult to meet the needs of rapid iteration development.
[0004] Manual operation is also prone to input errors or oversights in comparison. For example, incorrect values may be entered when manually inputting parameters, and differences in certain fields may be overlooked when comparing response results, leading to inaccurate test results.
[0005] Furthermore, this testing method cannot fully cover all possible test scenarios, such as boundary values and abnormal situations. Testers may overlook some special cases due to oversight, making potential problems difficult to discover. Summary of the Invention
[0006] In order to address one or more of the deficiencies in the prior art, the present invention aims to provide an automated API testing method, system, product, and apparatus based on a large language model.
[0007] One embodiment of the present invention is an automated API testing method based on a large language model, which includes the following steps:
[0008] S1, Receive API test requests input by users in natural language form, and use the first prompt word to guide the large language model to verify the validity of the test requests;
[0009] S2, when the verification result is valid, the second prompt word guides the large language model to automatically generate multiple test cases covering multiple test scenarios based on the test requirements, and the test cases are output in a structured data format;
[0010] S3, iterate through the generated test cases, verify them using the large language model, and output the logical verification results;
[0011] S4 summarizes the execution results and verification results of all test cases and generates an automated test report.
[0012] In some implementations, the API testing requirements in step S1 include at least one of the following: API endpoint information, parameter descriptions, response descriptions, functional descriptions, logical descriptions, and related resource configuration information.
[0013] In some implementations, in step S2, the second prompt word is used to define the role of the large language model as a test case generation expert and to limit its output to JSON format data containing test case identifiers, descriptions, request data, and expected responses.
[0014] In some implementations, in step S3, the following process is performed for each current test case:
[0015] S31, parse the data and environment requirements of the current test case, and generate a structured test preparation execution plan;
[0016] S32, monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flag according to the execution result;
[0017] S33, if the status flag of the test preparation work execution plan indicates that the execution is completed, then the third prompt word is used to guide the large language model to construct API request parameters that can be directly used for interface calls based on the request information of the current test case;
[0018] S34, Execute the API call using the API request parameters constructed by the large language model, and obtain the actual response result;
[0019] S35, using the fourth prompt word to guide the large language model, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report;
[0020] S36. Using the fifth prompt word to guide the large language model, based on the logical description in the test requirements, automatically generate a verification plan for the implicit business logic, and call the multi-data source inspection tool to execute the verification plan and output the logic verification results.
[0021] In some implementations, step S31, generating a test preparation execution plan, includes: analyzing the current test cases through preset rules, determining the required data generation, history cleanup, and environment configuration steps, and planning the sequence and parameters for tool calls.
[0022] In some implementations, step S32 further includes feeding back the tool execution results to the large language model to drive subsequent planning.
[0023] In some implementations, the multi-dimensional automated verification in step S35 includes comparison verification of the response status code, response structure, and key field values.
[0024] In some implementations, step S36 includes:
[0025] S361, Monitor the task status of the verification plan;
[0026] S362, if the task status indicates that the task is completed, then proceed to step S31 to process the next test case; otherwise, proceed to step S363.
[0027] S363, Perform data checks according to the verification plan scheduling tool;
[0028] S364, Feed the data inspection results back to the large language model to drive subsequent verification decisions, update the task status, and return to step S361.
[0029] Another embodiment of the present invention relates to an automated API testing system based on a large language model, comprising:
[0030] The requirement receiving and verification module is used to receive API test requirements input by users in natural language form, and use the first prompt word to call the large language model to verify the validity of the test requirements;
[0031] The test case generation module is used to call the large language model using the second prompt word when the verification result output by the large language model is valid, and automatically generate multiple test cases covering multiple test scenarios based on the test requirements. The test cases are output in a structured data format.
[0032] The test execution module is used to traverse the generated test cases, verify them using the large language model, and output the logical verification results.
[0033] The test report generation module is used to summarize the execution results and verification results of all test cases and generate automated test reports.
[0034] In some implementations, the test execution module includes:
[0035] The test preparation submodule is used to: parse the data and environment requirements of the current test case, generate a structured test preparation work execution plan; monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flags according to the execution results;
[0036] The request parameter construction submodule is used to: if the status flag of the test preparation work execution plan indicates that the execution is completed, guide the large language model with the third prompt word to construct API request parameters that can be directly used for interface calls based on the request information of the current test case;
[0037] The API call execution submodule is used to execute API calls using API request parameters constructed from the large language model and obtain the actual response results;
[0038] The test result verification submodule is used to: guide the large language model with the fourth prompt word, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report;
[0039] The implicit logic verification submodule is used to: guide the large language model with the fifth prompt word, automatically generate a verification plan for the implicit business logic based on the logic description in the test requirements, call the multi-data source inspection tool to execute the verification plan, and output the logic verification results.
[0040] Furthermore, embodiments of the present invention also relate to a computer program product, which includes a computer program, characterized in that, when executed by a processor, the computer program implements the steps of the method described in any embodiment of the present invention.
[0041] In addition, embodiments of the present invention also provide a computer device comprising:
[0042] A memory on which computer programs are stored;
[0043] A processor that, when executing the computer program, implements the steps of the method described in any embodiment of the present invention.
[0044] According to embodiments of the present invention, implementing the present invention has the following advantages:
[0045] Using the implementation method of this invention, the large language model automatically generates comprehensive test cases and executes the test process, eliminating the need for extensive manual writing of test scripts, greatly shortening the test cycle and improving test efficiency.
[0046] According to embodiments of the present invention, ordinary testers or even non-technical personnel can complete the testing work simply by describing the testing requirements in natural language, thus reducing the requirement for professional programming skills.
[0047] The embodiments of this invention employ a large language model, which can deeply analyze the business logic behind APIs, automatically identify implicit operations such as data persistence, system interaction, and state changes, and perform consistency and integrity verification of multiple data sources, thereby improving the accuracy and reliability of testing.
[0048] Furthermore, according to the embodiments of the present invention, when the API changes, only the test requirements described in natural language need to be modified, and the large language model can be quickly regenerated and the corresponding test process can be executed, thereby adapting to the frequent iteration of the API.
[0049] Various aspects, features, and advantages of the embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Attached Figure Description
[0050] The above aspects, features, advantages, etc. of the present invention will become clearer from the detailed description taken in conjunction with the following accompanying drawings.
[0051] Figure 1 This is a schematic diagram illustrating the main flow of the automated API testing method based on a large language model according to an embodiment of the present invention.
[0052] Figure 2 It is shown Figure 1 A flowchart of an example process for step S3.
[0053] Figure 3 It is shown Figure 2 A flowchart of an example process for step S36.
[0054] Figure 4 This is a block diagram illustrating an example structure of an automated API testing system based on a large language model according to an embodiment of the present invention.
[0055] Figure 5 This is a block diagram illustrating an example structure of a computer device capable of executing an automated API testing method based on a large language model according to embodiments of the present invention. Detailed Implementation
[0056] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. It should be understood that the present invention can be implemented in various forms and is not limited to the specific embodiments described herein or shown in the accompanying drawings.
[0057] The terms “comprising,” “including,” and “having” are used herein to indicate the presence of certain features, steps, operations, elements, and / or components, but do not exclude the presence or addition of other features, steps, operations, elements, components, or combinations thereof. Unless explicitly defined by context, the terms “first,” “second,” and similar terms do not indicate any priority or order, but are used only to distinguish different objects in the description.
[0058] It should be understood that although the method steps of the present invention are described in a certain order and the accompanying reference numerals are used in a certain order, the method of the present invention is not necessarily strictly performed in this order. Depending on the actual application, these orders can be appropriately changed.
[0059] To address the shortcomings of existing API testing technologies, this invention aims to provide an automated API testing solution based on a large language model, thereby improving testing efficiency and achieving rapid and comprehensive testing. This invention leverages the natural language understanding and generation capabilities of a large language model to transform user-defined API testing requirements into a complete testing process. Based on the input test requirement description, including API specifications, functional descriptions, and logical descriptions, the large language model automatically generates test cases, plans and executes test preparation work, constructs API request parameters, performs result verification, and conducts in-depth verification of implicit logic. Throughout the process, the large language model intelligently completes various testing tasks according to the task requirements at different stages, combining its learned knowledge and rules.
[0060] Figure 1 An exemplary embodiment of the present invention, a method for automated API testing based on a large language model, is illustrated. For example... Figure 1 As shown, the method includes the following steps:
[0061] S1, Receive API test requests input by users in natural language form, and use the first prompt word to guide the large language model to verify the validity of the test requests;
[0062] S2, when the verification result is valid, the second prompt word guides the large language model to automatically generate multiple test cases covering multiple test scenarios based on the test requirements, and the test cases are output in a structured data format;
[0063] S3, iterate through the generated test cases, verify them using the large language model, and output the logical verification results;
[0064] S4 summarizes the execution results and verification results of all test cases and generates an automated test report.
[0065] In some implementations, the API testing requirements in step S1 include at least one of the following: API endpoint information, parameter descriptions, response descriptions, functional descriptions, logical descriptions, and related resource configuration information.
[0066] In some implementations, in step S2, the second prompt word is used to define the role of the large language model as a test case generation expert and to limit its output to JSON format data containing test case identifiers, descriptions, request data, and expected responses.
[0067] In some implementations, in step S3, such as Figure 2 As shown, the following process is executed for each current test case:
[0068] S31, parse the data and environment requirements of the current test case, and generate a structured test preparation execution plan;
[0069] S32, monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flag according to the execution result;
[0070] S33, if the status flag of the test preparation work execution plan indicates that the execution is completed, then the third prompt word is used to guide the large language model to construct API request parameters that can be directly used for interface calls based on the request information of the current test case;
[0071] S34, Execute the API call using the API request parameters constructed by the large language model, and obtain the actual response result;
[0072] S35, using the fourth prompt word to guide the large language model, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report;
[0073] S36. Using the fifth prompt word to guide the large language model, based on the logical description in the test requirements, automatically generate a verification plan for the implicit business logic, and call the multi-data source inspection tool to execute the verification plan and output the logic verification results.
[0074] In some implementations, step S31, generating a test preparation execution plan, includes: analyzing the current test cases through preset rules, determining the required data generation, history cleanup, and environment configuration steps, and planning the sequence and parameters for tool calls.
[0075] In some implementations, step S32 further includes feeding back the tool execution results to the large language model to drive subsequent planning.
[0076] In some implementations, the multi-dimensional automated verification in step S35 includes comparison verification of the response status code, response structure, and key field values.
[0077] In some implementations, such as Figure 3 As shown, step S36 includes:
[0078] S361, Monitor the task status of the verification plan;
[0079] S362, if the task status indicates that the task is completed, then proceed to step S31 to process the next test case; otherwise, proceed to step S363.
[0080] S363, Perform data checks according to the verification plan scheduling tool;
[0081] S364, Feed the data inspection results back to the large language model to drive subsequent verification decisions, update the task status, and return to step S361.
[0082] also, Figure 4 An exemplary embodiment of the present invention, an automated API testing system based on a large language model, is illustrated. As shown in the figure, an automated API testing system 1000 based on a large language model may include a requirement receiving and verification module 1001, a test case generation module 1002, a test execution module 1003, and a test report generation module 1004. The processing performed by each module, the functions implemented, or the effects are described below.
[0083] The requirement receiving and verification module 1001 is used to receive API test requirements input by users in natural language form, and use the first prompt word to call the large language model to verify the validity of the test requirements.
[0084] The test case generation module 1002 is used to call the large language model using the second prompt word when the verification result output by the large language model is valid, and automatically generate multiple test cases covering multiple test scenarios based on the test requirements. The test cases are output in a structured data format.
[0085] The test execution module 1003 is used to traverse the generated test cases, verify them using the large language model, and output the logical verification results.
[0086] The test report generation module 1004 is used to summarize the execution results and verification results of all test cases and generate an automated test report.
[0087] In some implementations, the test execution module 1003 may include the following sub-modules.
[0088] The test preparation submodule is used to: parse the data and environment requirements of the current test case, generate a structured test preparation work execution plan; monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flags according to the execution results.
[0089] The request parameter construction submodule is used to: if the status flag of the test preparation work execution plan indicates that the execution is complete, then use the third prompt word to guide the large language model to construct API request parameters that can be directly used for interface calls based on the request information of the current test case.
[0090] The API call execution submodule is used to execute API calls using API request parameters constructed from the large language model and obtain the actual response results.
[0091] The test result verification submodule is used to: guide the large language model with the fourth prompt word, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report.
[0092] The implicit logic verification submodule is used to: guide the large language model with the fifth prompt word, automatically generate a verification plan for the implicit business logic based on the logic description in the test requirements, call the multi-data source inspection tool to execute the verification plan, and output the logic verification results.
[0093] The method and system of the present invention have been described above. To facilitate a deeper understanding of the technical concept and solution of the present invention, a specific example is provided below to illustrate the invention.
[0094] One embodiment of the present invention can be implemented based on Python 3.12 and a large natural language model. In a specific example, the system of the present invention performs the following processing steps.
[0095] (1) The system receives test requirements submitted by testers and verifies their validity. Specifically, it constructs a first prompt word, defines the model role as a test requirement validity review expert, verifies whether the user's test requirements are valid, and includes necessary test information, such as API information, to meet basic automated testing requirements. Examples of corresponding test requirements are as follows:
[0096]
[0097]
[0098] (2) Verify the test results of the test requirements. If the test result is "success (meaning the verification is passed)," continue execution; otherwise, terminate execution and output the reason for termination to the user.
[0099] (3) System assembly testing requirements and the second prompt word. This second prompt word defines the large language model as a test case generation expert, capable of creating functional, non-functional, and security test cases, and standardizing its output of test cases in a standardized JSON format to cover multiple test scenarios, thereby completing the automatic generation of test cases. An example of the large language model's output information is as follows:
[0100]
[0101] (4) The system parses the generated test case data and iterates through it until all test cases are executed and verification is completed, as follows:
[0102] (4-1) Based on the current test cases, the system analyzes their data and environmental requirements and dynamically generates a structured test preparation execution plan. Specifically, the system analyzes test cases through preset rules to determine the required steps such as data generation, historical data cleanup, and environment configuration, and plans the specific tool call sequence and parameters. Furthermore, the system continuously tracks the execution status and progress of the preparation work, and performs interruption checks at key nodes to coordinate the multi-step, multi-dependency preparation workflow. The output information is shown below:
[0103]
[0104]
[0105] (4-2) The system monitors the status flags in the preparation work execution plan. If the flag is true (indicating that the execution is complete), it is determined that the automated execution process needs to be interrupted and the process jumps to step (4-4); otherwise, the subsequent operations continue to be executed sequentially.
[0106] (4-3) The system schedules and executes the corresponding tools according to the action details in the execution plan, feeds back the execution results to the large language model to drive subsequent planning, updates the execution completion status flag, and re-enters the interruption status monitoring process at (4-2).
[0107] (4-4) Based on the current test case content and the preset third prompt (the third prompt sets the task responsibility of the large language model to generate API request parameters and limits its output to standardized JSON format), the system calls the large language model to automatically construct API request parameters. By inputting structured test information, the system drives the model to generate complete HTTP request parameters conforming to the target tool's calling specifications according to preset rules, including URL encoding, request header settings, and request body formatting, ensuring that the parameters can be directly used for interface calls. The output information is as follows:
[0108]
[0109] (4-5) The system schedules API request tool, executes the interface call using the constructed request parameters, and collects the returned response results.
[0110] (4-6) Based on the expected and actual response results of the test cases, and combined with a preset fourth prompt (which sets the large language model to act as a data verification expert, comprehensively verifying and comparing the response results with the expected results), the system assembles the large language model request parameters and requests the large language model service to automatically verify the actual response. Through multi-dimensional comparative analysis, including status codes, response structure, data accuracy, and business logic consistency, and combined with configurable verification levels (strict / lenient), the system determines the results. Finally, a structured, traceable, and standardized test report is generated, containing detailed verification items, problem classifications, and statistical information. The verification results are output as follows:
[0111]
[0112] (4-7) Based on API logic specifications, the system schedules a large language model to perform in-depth verification and analysis of implicit business logic. Using the fifth prompt word, the model role is defined as the implicit logic verification agent, capable of automatically identifying implicit operations such as data persistence and state changes, generating structured verification plans, coordinating multi-data source checking tools, and systematically executing verification tasks such as database persistence data consistency and business side effects, ultimately forming a complete logical verification closed loop. The corresponding output results are shown below:
[0113]
[0114]
[0115]
[0116] Specifically, in steps (4-7), the system monitors the completion status flags in the verification process to monitor the task status of the verification plan. If the task is detected to be completed (status is FINISH, indicating completion), the system automatically jumps to step (4-1) to execute the next test case; otherwise, it continues to execute subsequent verification steps sequentially. For example, the system schedules the corresponding tool to perform data checks according to the verification plan, feeds back the obtained results to the large language model to drive subsequent verification decisions, and re-enters the completion status monitoring loop to achieve closed-loop iterative verification control.
[0117] (5) The system summarizes the results of each step and generates a complete test report.
[0118] It should be understood that the steps, processes, and operations described in the above embodiments can be implemented by computer software programs. Therefore, the embodiments of the present invention also relate to a computer program product, which includes a computer program that, when executed by a processor, implements the steps, processes, or operations of the method described in any embodiment of the present invention. In some embodiments, program code for executing the computer program of the embodiments of the present invention can be written in any combination of one or more programming languages. For example, the computer program can be written using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on a personal computing device, partially on a personal computing device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the personal computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0119] It should also be understood that the computer program product may be stored on a computer-readable storage medium, such as hard disks, floppy disks, magnetic tapes, optical disks, solid-state drives, flash memory, etc.
[0120] Furthermore, it can be understood that the method of any embodiment of the present invention can be executed by a computer device. Accordingly, embodiments of the present invention also relate to a computer device comprising: a memory storing a computer program thereon; and a processor that, when executing the computer program, implements the steps (processing, operations, etc.) of the automated API testing method based on a large language model described in any embodiment of the present disclosure.
[0121] Figure 5 An exemplary structure of a computer device is shown. Figure 5As shown, the computer device 100 may include at least a processor 101 and a memory 102, wherein the memory 102 may be or include a storage medium storing a computer program (or computer-readable instructions). The processor 101 executes the computer program to perform some or all of the operations in the automated API testing method based on a large language model according to any embodiment of this disclosure, including but not limited to: S1, receiving API testing requirements input by the user in natural language form, and using a first prompt word to guide the large language model to verify the validity of the testing requirements; S2, when the verification result is valid, using a second prompt word to guide the large language model to automatically generate multiple test cases covering multiple test scenarios based on the testing requirements, and outputting the test cases in a structured data format; S3, traversing the generated test cases, verifying them using the large language model, and outputting logical verification results; S4, summarizing the execution results and verification results of all test cases and generating an automated test report.
[0122] In some embodiments, the computer device 100 may further include a data storage device 103, a display 104, a speaker 105, and a communication module 106. The processor 101, memory 102, and data storage device 103 communicate with each other via a bus and interact with peripheral devices, such as the display 104 and communication module 106, via the bus and I / O module 107.
[0123] Specifically, data storage device 103 can store applications and their various configuration files and data. Memory 102 stores computer programs. Processor 101 executes the computer programs to perform various processes, operations, or steps of the above-described automated API testing method based on a large language model. Display 104 can be used to display various data, images, etc.
[0124] In optional embodiments, the communication module 106 may be omitted where communication with the other systems, devices, or equipment is not required. In some embodiments, the computer device 100 may further include a speaker 105 for voice output.
[0125] In some implementations, processor 101 may include any suitable semiconductor-based electronic processing unit, chip, microchip, or integrated circuit (IC). Memory 102 is a programmable memory, which may include any suitable electronic storage device configured to store instructions and be reprogrammable. For example, programmable memory may include an erasable programmable read-only memory (EPROM) device. Data storage device 103 may be a persistent storage device, which may include any suitable electronic storage configured to retain stored information as power cycles. For example, data storage device 103 may include a hard disk drive, solid-state drive (SSD), flash memory drive, hybrid drive, etc., or any combination thereof.
[0126] Therefore, processor 101 can control the output of information on I / O module 107 by storing information in memory and / or executing programs / instructions stored in memory. For example, several aspects of the methods described herein can be executed by processor 101 according to programs / instructions stored in memory (e.g., memory 102 and / or data storage device 103).
[0127] Furthermore, the processor 101 can electronically communicate with the I / O module 107 and / or the communication module 106 to receive or send relevant instructions and information. The I / O module 107 may include any suitable mechanical or virtual user interface configured to enable a user to interact with the computer device 100 or to allow the user to perform one or more functions of the computer device 100 itself, such as a graphical user interface (GUI) on a screen or other display. In some instances, the user interface may include a voice interface capable of speech recognition, through which an operator can provide voice commands to the processor.
[0128] The communication module 106 may include any suitable devices and / or structures configured to facilitate information exchange between the computer device 100 and external electronic devices. The communication module 106 may include devices configured to send and / or receive wireless or wired information with other devices. For example, the communication module 106 may include an antenna, a transceiver, a connector for wired reception and / or transmission of data, a data exchange device, etc., or any combination thereof. The communication module 106 may also include ancillary components, such as filtering circuits, encryption / decryption circuits, and / or integrated circuit (IC) chips for processing signals (e.g., (Chip). In some implementations, the communication module 106 may include a WiFi device configured to connect to a local wireless network.
[0129] In some implementations, computer device 100 may include a smartphone, wearable computer, portable / mobile electronic device, tablet computer, smartwatch, personal digital assistant (PDA), personal computer (PC), desktop computer, laptop computer, server, etc. Computer device 100 may include or have installed one or more application programs (APPs), one of which may be configured to perform the automated API testing method based on large language models described herein.
[0130] Although not shown, it should be understood that the computer device 100 also includes a power supply component, which may include any suitable device and / or structure configured to provide an electrical interface between the computer device 100 and a power source. The power source may include any suitable source of electrical energy, such as a battery, socket, capacitor, fuel cell, etc., or any combination thereof. Additionally or optionally, the power source may be included within the power supply component. For example, a battery or battery pack may be included within the computer device 100. In some embodiments, the battery may be rechargeable, for example, charged via a cable or an interface provided by the power supply component. In some embodiments, the power supply component may share features with or repeat features of the communication module 106. For example, a USB or micro-USB cable connector may be included in the computer device 100, so that power supply or data communication is performed by the same component.
[0131] Those skilled in the art should understand that the above disclosure is merely illustrative of embodiments of the present invention, and the scope of patent protection sought in this application is not limited thereto. Various modifications, alterations, substitutions, and other changes can be made to the embodiments disclosed herein without departing from the spirit of the invention, and such changes are within the scope covered by the claims of this application.
Claims
1. An automated API testing method based on a large language model, characterized in that, Includes the following steps: S1, Receive API test requests input by users in natural language form, and use the first prompt word to guide the large language model to verify the validity of the test requests; S2, when the verification result is valid, the second prompt word guides the large language model to automatically generate multiple test cases covering multiple test scenarios based on the test requirements, and the test cases are output in a structured data format; S3, iterate through the generated test cases, verify them using the large language model, and output the logical verification results; S4 summarizes the execution results and verification results of all test cases and generates an automated test report.
2. The method according to claim 1, characterized in that, The API testing requirements in step S1 include at least one of the following: API endpoint information, parameter description, response description, functional description, logical description, and related resource configuration information.
3. The method according to claim 1, characterized in that, In step S2, the second prompt word is used to define the role of the large language model as a test case generation expert, and to limit its output to JSON format data containing test case identifiers, descriptions, request data and expected responses.
4. The method according to claim 1, characterized in that, In step S3, the following process is executed for each current test case: S31, parse the data and environment requirements of the current test case, and generate a structured test preparation execution plan; S32, monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flag according to the execution result; S33, if the status flag indicates that the execution is complete, then the third prompt word is used to guide the large language model to construct API request parameters that can be directly used for interface calls based on the request information of the current test case; S34, Execute the API call using the API request parameters constructed by the large language model, and obtain the actual response result; S35, using the fourth prompt word to guide the large language model, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report; S36. Using the fifth prompt word to guide the large language model, based on the logical description in the test requirements, automatically generate a verification plan for the implicit business logic, and call the multi-data source inspection tool to execute the verification plan and output the logic verification results.
5. The method according to claim 4, characterized in that, In step S31, generating the test preparation work execution plan includes: analyzing the current test cases through preset rules, determining the required data generation, history cleanup, and environment configuration steps, and planning the sequence and parameters of tool calls.
6. The method according to claim 4, characterized in that, Step S32 also includes feeding the tool execution results back to the large language model to drive subsequent planning.
7. The method according to claim 4, characterized in that, The multi-dimensional automated verification in step S35 includes the comparison and verification of the response status code, response structure, and key field values.
8. The method according to claim 4, characterized in that, Step S36 includes: S361, Monitor the task status of the verification plan; S362, if the task status indicates that the task is completed, then proceed to step S31 to process the next test case; otherwise, proceed to step S363. S363, Perform data checks according to the verification plan scheduling tool; S364, Feed the data inspection results back to the large language model to drive subsequent verification decisions, update the task status, and return to step S361.
9. An automated API testing system based on a large language model, characterized in that, include: The requirement receiving and verification module is used to receive API test requirements input by users in natural language form, and use the first prompt word to call the large language model to verify the validity of the test requirements; The test case generation module is used to call the large language model using the second prompt word when the verification result output by the large language model is valid, and automatically generate multiple test cases covering multiple test scenarios based on the test requirements. The test cases are output in a structured data format. The test execution module is used to traverse the generated test cases, verify them using the large language model, and output the logical verification results. The test report generation module is used to summarize the execution results and verification results of all test cases and generate automated test reports.
10. The system according to claim 9, characterized in that, The test execution module includes: The test preparation submodule is used to: parse the data and environment requirements of the current test case, generate a structured test preparation work execution plan; monitor and execute the test preparation work execution plan, call the corresponding tools according to the actions in the plan, and update the status flags according to the execution results; The request parameter construction submodule is used to: if the status flag indicates that the execution is complete, guide the large language model with the third prompt word to construct API request parameters that can be directly used for interface calls based on the request information of the current test case; The API call execution submodule is used to execute API calls using API request parameters constructed from the large language model and obtain the actual response results; The test result verification submodule is used to: guide the large language model with the fourth prompt word, perform multi-dimensional automated verification of the actual response result and the expected result in the test case, and generate a verification report; The implicit logic verification submodule is used to: guide the large language model with the fifth prompt word, automatically generate a verification plan for the implicit business logic based on the logic description in the test requirements, call the multi-data source inspection tool to execute the verification plan, and output the logic verification results.
11. A computer program product comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 8.
12. A computer device, characterized in that, include: A memory on which computer programs are stored; A processor that, when executing the computer program, implements the steps of the method according to any one of claims 1 to 8.