API Test Case Generation Method, Device and Readable Storage Medium Based on Neuro-Symbolic Reasoning

Through the neural symbol inference fusion architecture, combined with neural network and symbolic logic, dynamically adjust weights to generate API test cases that meet complex constraints, solving the problems of insufficient processing capabilities of complex constraints and poor adaptability of multiple protocols in the existing technology, and achieving efficient and widely covered API testing.

CN119902991BActive Publication Date: 2025-05-27SHENZHEN SHENGQIANG TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510388805.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-05-27
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

The existing API testing technology has significant flaws in complex constraint processing capabilities, testing efficiency and coverage balance, and multi-protocol compatibility, and cannot effectively generate test cases that meet complex parameter constraints.

Method used

The fusion architecture based on neural symbol reasoning is adopted, and the parameter patterns in unstructured documents are extracted through a neural semantic parser, logical verification is performed in combination with the symbol rule library, and the weights are dynamically adjusted to generate test cases, and RESTful/GraphQL/gRPC multi-protocol adaptation is supported.

Benefits of technology

It significantly improves the ability to handle complex parameter constraints, reduces the generation rate of invalid use cases, improves test efficiency and coverage, reduces resource consumption, and enhances the test coverage ability of API exception scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902991B_ABST
    Figure CN119902991B_ABST
Patent Text Reader

Abstract

The present invention proposes an API test case generation method, apparatus and readable storage medium based on neuro-symbolic reasoning. By extracting parameter patterns through a neural semantic parser, combining with a symbolic rule library to verify complex constraints, and using a dynamic coordinator to dynamically adjust the weights of neural generation and symbolic verification, efficient and compliant test case generation is achieved. When there are constraint conflicts, the reverse reasoning module generates parameters and abnormal data that violate the constraints, and supports nested constraint parsing and dependency analysis of RESTful / GraphQL / gRPC protocols through a multi-protocol adapter. Experiments show that the test case generation speed of the present invention is up to 2100 cases per second at most, the constraint violation detection rate is 98%+, and the CPU occupancy is only 38%, significantly improving the test efficiency and quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the cross - field of software engineering and artificial intelligence, and particularly to an API test case generation method, device, and readable storage medium based on neuro - symbolic reasoning. Background Art

[0002] In the field of software engineering, API testing is a key link to ensure system quality. With the popularization of microservice architectures and the Internet of Things, the number and complexity of APIs have increased exponentially. Existing testing technologies face the following challenges:

[0003] 1. Rule - driven methods (such as Swagger parsing) rely on explicit parameter types, cannot handle implicit business logics such as "discount rate is related to user level", and the parsing success rate for unstructured documents (such as Markdown) is less than 40%.

[0004] 2. Random testing technologies (such as RESTler) generate up to 78% invalid test cases, and the coverage rate for security protocols (such as OAuth2.0) is less than 15%.

[0005] 3. Machine learning methods (such as RNN models) require more than 50,000 labeled samples to achieve an 80% compliance rate and cannot guarantee temporal constraints such as "end time > start time".

[0006] In summary, existing technologies have significant deficiencies in complex constraint handling capabilities, the balance between test efficiency and coverage, and multi - protocol compatibility.

[0007] Therefore, there is an urgent need for an API test case generation method, device, and readable storage medium based on neuro - symbolic reasoning that is applicable to interface testing of microservice architectures, cloud computing platforms, and Internet of Things systems, focusing on test case generation under complex parameter constraints, to solve the problems existing in the prior art. Summary of the Invention

[0008] Embodiments of the present invention provide an API test case generation method, device, and readable storage medium based on neuro - symbolic reasoning, aiming at the problems existing in current technologies, such as the inability to effectively balance the flexibility of neural network - generated test cases and the rule constraints of symbolic logic, resulting in insufficient complex parameter constraint handling capabilities, high invalid test case generation rates, poor multi - protocol adaptability, and dependence on a large amount of labeled data.

[0009] The core technology of the present invention mainly uses a neuro - symbolic reasoning fusion architecture, combines the pattern recognition ability of neural networks with the rule verification ability of symbolic logic, dynamically adjusts weights to generate test cases that meet complex constraints, and supports multi - protocol adaptation of RESTful / GraphQL / gRPC, significantly improving test efficiency and coverage.

[0010] In a first aspect, the present invention provides an API test case generation method based on neuro-symbolic reasoning, and the method includes the following steps:

[0011] S00. Parse the unstructured API document through a neuro-semantic parser to extract parameter patterns, and the neuro-semantic parser uses a multi-layer Transformer model to implement natural language processing;

[0012] S10. Based on first-order logic, temporal logic, and business rules in the symbolic rule library, perform symbolic logic verification on candidate test cases;

[0013] S20. Generate the final test case by dynamically coordinating the generation confidence N(x) of the neural network and the satisfaction degree S(x) of the symbolic rule; wherein, the dynamic coordinator dynamically adjusts the weight parameters α and β based on a hybrid reasoning algorithm, satisfying:

[0014] Use case generation = argmax(α * N(x) + β * S(x)) (α + β = 1)

[0015] The weight parameters are dynamically adjusted according to the historical error rate;

[0016] S30. When the symbolic logic verification fails, start reverse reasoning to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data;

[0017] S40. Parse different interface specifications through a multi-protocol adapter, including RESTful, GraphQL, and gRPC protocols, to generate protocol-adapted test cases.

[0018] Further, maintain a queue with a length of m to calculate the average error rate, and compare the neural generation error rate e_N and the symbolic verification error rate e_S to adjust α and β.

[0019] Further, in step S30, the steps of reverse reasoning to generate counterexamples include:

[0020] Modify numerical parameters to boundary values or illegal values;

[0021] Modify string parameters to illegal values that violate the length or character set;

[0022] Replace enumerated parameters with illegal enumerated values;

[0023] Generate use cases for abnormal scenarios based on business process simulation and data dependency analysis.

[0024] Further, in step S40, the parsing steps of the multi-protocol adapter include:

[0025] Parse the OpenAPI v3 extension fields of the RESTful interface and recursively parse and process nested constraints;

[0026] Extract the type dependencies in the GraphQL Schema and construct a type dependency graph;

[0027] Parse the Protocol Buffer file of gRPC and construct a service dependency graph;

[0028] Be compatible with interface specifications of different versions through a pluggable plugin architecture.

[0029] Further, in step S40, the parsing step of the multi-protocol adapter further includes:

[0030] For the old version of the OpenAPI document, extract constraint information from the "description" field;

[0031] For different versions of GraphQL specifications, maintain a version mapping table to select parsing rules;

[0032] Perform service dependency graph analysis on the Protocol Buffer file of gRPC to support complex service definitions.

[0033] Further, the specific steps of dynamically adjusting the weight parameters in step S20 include:

[0034] Maintain a historical error rate queue, and calculate the neural network generation error rate e_N and the symbolic logic verification error rate e_S;

[0035] Adjust the weights according to the error rate comparison result:

[0036] If e_N > e_S, then α decreases by Δ and β increases by Δ;

[0037] If e_N < e_S, then α increases by Δ and β decreases by Δ;

[0038] Δ is an adaptive adjustment step size, with an initial value of 0.05, and is dynamically scaled according to the error rate fluctuation amplitude. When the fluctuation amplitude is less than 0.02, the step size is reduced, and when the fluctuation amplitude is greater than 0.05, the step size is increased.

[0039] Further, in step S20, the initial values of the weight parameters α and β are both set to 0.5.

[0040] In a second aspect, the present invention provides an API test case generation device based on neuro-symbolic reasoning, including:

[0041] A neural semantic parsing module that parses unstructured API documents through a built-in neural semantic parser to extract parameter patterns. The neural semantic parser uses a multi-layer Transformer model to implement natural language processing;

[0042] Symbol rule library, which performs symbolic logic verification on candidate test cases based on built-in first-order logic, temporal logic, and business rules;

[0043] Dynamic coordination engine, which fuses the generation confidence N(x) of the neural network and the satisfaction degree S(x) of the symbolic rules through a built-in dynamic coordinator to generate final test cases; among them, the dynamic coordinator dynamically adjusts the weight parameters α and β based on a hybrid inference algorithm, satisfying:

[0044] Test case generation = argmax(α * N(x) + β * S(x)) (α + β = 1)

[0045] The weight parameters are dynamically adjusted according to the historical error rate;

[0046] Multi-protocol adapter, which parses different interface specifications through the multi-protocol adapter, including RESTful, GraphQL, and gRPC protocols, to generate protocol-adapted test cases;

[0047] Reverse inference module, when the symbolic logic verification fails, it starts reverse inference to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data.

[0048] Thirdly, the present invention provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the above-mentioned API test case generation method based on neuro-symbolic reasoning.

[0049] Fourthly, the present invention provides a readable storage medium, in which a computer program is stored. The computer program includes program codes for controlling a process to execute the process, and the process includes the above-mentioned API test case generation method based on neuro-symbolic reasoning.

[0050] The main contributions and innovations of the present invention are as follows:

[0051] 1. Enhanced complex constraint handling ability: By extracting explicit / implicit constraints in unstructured documents through a neuro-semantic parser and combining the verification of the symbol rule library, the detection rate of complex logical constraints (such as temporal relationships and business rules) is increased to more than 98%.

[0052] 2. Optimization of test efficiency and quality: The dynamic coordinator adjusts the weight parameters based on the historical error rate, balances the weights of neural generation and symbolic verification, reduces the proportion of invalid test cases from 78% of the traditional method to 12%, and the test case generation speed can reach 2100 cases per second.

[0053] 3. Improved multi - protocol compatibility: Adapt to protocols such as RESTful, GraphQL, and gRPC through a plug - and - play plugin architecture, support nested constraint resolution, type - dependency graph construction, and service - dependency analysis, covering more than 95% of common interface specifications.

[0054] 4. Significantly reduced resource consumption: The CPU occupancy rate is reduced to 38% compared with traditional solutions, the test preparation time is shortened by 24 times, and the regression test cycle is compressed to 1 / 5.6 of the original cycle, reducing the investment in hardware resources.

[0055] 5. Reverse anomaly generation ability: By modifying boundary values, injecting illegal data, and simulating business processes, the security vulnerability detection rate is increased by 467%, enhancing the test coverage ability for API anomaly scenarios.

[0056] Details of one or more embodiments of the present invention are set forth in the following drawings and description to make other features, objects, and advantages of the present invention more concise and understandable. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0058] Figure 1 is a flowchart of a method for generating API test cases based on neuro - symbolic reasoning according to an embodiment of the present invention;

[0059] Figure 2 is a schematic hardware structure diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0060] Here, exemplary embodiments will be described in detail, and examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. On the contrary, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0061] It should be noted that: In other embodiments, the steps of the corresponding methods are not necessarily executed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step for description in other embodiments.

[0062] The prior art is difficult to meet the efficient testing requirements in complex scenarios. It either cannot handle implicit constraints due to relying on explicit rules, or wastes resources due to random generation, or has high machine learning annotation costs and cannot guarantee logical constraints.

[0063] Based on this, the present invention solves the problems existing in the prior art based on a neuro-symbolic reasoning fusion architecture.

[0064] Embodiment 1

[0065] The present invention aims to propose an API test case generation method based on neuro-symbolic reasoning. Specifically, referring to Figure 1 , the method includes the following steps:

[0066] S00. Parse the unstructured API document through a neuro-semantic parser to extract parameter patterns. The neuro-semantic parser uses a multi-layer Transformer model to implement natural language processing;

[0067] In this embodiment, the neuro-semantic parser uses a 12-layer Transformer model, which has powerful natural language processing capabilities and can efficiently process unstructured documents to accurately extract parameter patterns from the API document.

[0068] S10. Perform symbolic logic verification on candidate test cases based on first-order logic, temporal logic, and business rules in the symbolic rule library;

[0069] In this embodiment, the symbolic rule library supports three constraint types: first-order logic, temporal logic, and business rules, providing a rule basis for symbolic logic reasoning to verify whether the test cases meet various constraint conditions.

[0070] S20. Generate the final test case by fusing the generation confidence N(x) (value range 0 - 1) of the neural network and the satisfaction degree S(x) (value range 0 - 1) of the symbolic rule through a dynamic coordinator; where the dynamic coordinator dynamically adjusts the weight parameters α and β (α + β = 1) based on a hybrid reasoning algorithm, satisfying:

[0071] Test case generation = argmax(α * N(x) + β * S(x))(α + β = 1)

[0072] The weight parameters are dynamically adjusted according to the historical error rate;

[0073] In this embodiment, the dynamic coordinator is based on a game theory-based neuro-symbolic weight allocation algorithm to achieve dynamic fusion of the neural network generation result and the symbolic logic verification result, and flexibly adjusts the weights of the two according to different test scenarios and requirements to generate the optimal test case.

[0074] Preferably, in the hybrid inference algorithm "use case generation = argmax(α*N(x)+β*S(x))", when setting the initial values of the dynamic weight parameters α and β, the reliability of the neural network and symbolic logic reasoning in the initial stage should be comprehensively considered. Since there is a lack of historical data support at the start of the test, α and β can both be initially set to 0.5. This setting means that in the initial stage, the generation confidence N(x) of the neural network and the satisfaction degree S(x) of the symbolic rules are given the same importance, so as to balance the roles of the two in the test case generation process.

[0075] The adjustment step size dynamically adjusted according to the historical error rate is the key factor controlling the update amplitude of the weight parameters. The present invention adopts an adaptive adjustment step size strategy, and the initial adjustment step size Δ is set to 0.05. At each iteration, the step size will be dynamically adjusted according to the change of the historical error rate. The specific rules are as follows:

[0076] If the change amplitude of the current error rate compared with the previous error rate is less than 0.02 (i.e., the error rate is relatively stable), the adjustment step size will be reduced to 0.8 times of the original, that is, Δ = Δ×0.8.

[0077] If the change amplitude of the current error rate compared with the previous error rate is greater than 0.05 (i.e., the error rate fluctuates greatly), the adjustment step size will be increased to 1.2 times of the original, that is, Δ = Δ×1.2.

[0078] Preferably, the specific steps of the algorithm for precisely adjusting according to the historical error rate are as follows:

[0079] Maintain a historical error rate queue E with a length of m (for example, m = 10). After each test is completed, the current error rate e_current will be added to the queue, and at the same time, the earliest error rate value will be removed to ensure that the queue length is always m. Then calculate the average value of the error rates in the queue.

[0080] Let the error rate of the neural network generation result be e_N, and the error rate of the symbolic logic verification result be e_S. Adjust the weight parameters according to the following rules:

[0081] If e_N>e_S, it indicates that the accuracy of the neural network generation is relatively low, and its weight needs to be reduced, while the weight of the symbolic logic needs to be increased. At this time, α = α - Δ, β = β + Δ.

[0082] If e_N<e_S, it means that the accuracy of the symbolic logic verification is relatively low, and its weight needs to be reduced, while the weight of the neural network needs to be increased. That is, α = α + Δ, β = β - Δ.

[0083] If e_N = e_S, the weight parameters remain unchanged.

[0084] In this way, the weight parameter adjustment is applied to dynamic priority scheduling, such as the fault propagation model based on the service call chain, to calculate the API endpoint risk value in real time. Priority = 0.6・Impact + 0.3・Likelihood + 0.1・RecoveryCost. According to the calculation results, high-risk interfaces are preferentially tested to improve the pertinence and effectiveness of testing.

[0085] S30. When the symbolic logic verification fails, start reverse reasoning to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data.

[0086] In this embodiment, step S30 is a constraint conflict resolution process:

[0087] The neural module first generates a candidate parameter set C.

[0088] The symbolic module filters the set C to obtain a compliant subset C'⊆C.

[0089] If C' is an empty set, that is, all candidate cases do not conform to the rules, reverse reasoning is started at this time to generate counterexamples. The specific operations include modifying parameters to violate specific constraints (such as setting age = -1) and injecting abnormal data (such as SQL injection strings) to detect the processing ability of the API under abnormal conditions.

[0090] Preferably, the specific strategy for reverse reasoning to generate counterexamples is as follows:

[0091] 1. Select appropriate parameters to modify to violate specific constraints

[0092] Numeric parameters: For numeric parameters with range constraints, select boundary values and values outside the boundary for modification. For example, if the constraint of the parameter "age" is "18 <= age <= 60", then "age" can be modified to 17 or 61. For numeric parameters without clear range constraints, select the maximum value, minimum value, and zero value for modification, such as "Integer.MAX_VALUE", "Integer.MIN_VALUE", and 0 in Java.

[0093] String parameters: For string parameters with length constraints, select strings with lengths less than the minimum length and greater than the maximum length for modification. For example, if the length constraint of the string parameter "name" is "3 <= length(name) <= 20", then "name" can be modified to a string with a length of 2 or 21. For string parameters with character set constraints, select strings composed of characters not in the character set for modification.

[0094] Enumeration parameter: Modify by selecting an illegal value outside the enumerated values. For example, if the enumeration type "Color" includes "RED", "GREEN", "BLUE", the parameter can be modified to "YELLOW".

[0095] 2. Determine the type and range of the injected abnormal data

[0096] Abnormal data based on API functions: For APIs involving database operations, inject SQL injection strings (such as "'OR1=1--"), malicious SQL statements (such as "DROPTABLEusers;"), etc. For APIs involving file uploads, inject malicious file types (such as executable file.exe), oversized files (exceeding the server limit), etc.

[0097] Abnormal data based on data format: If the API accepts data in JSON format, inject malformed JSON data, such as "{"key":value}" (missing quotes), "{"key":"value",}" (extra comma), etc. If the API accepts data in XML format, inject malformed XML data, such as " <tag>"content” (missing closing tag), etc.

[0098] Preferably, in order to overcome the limitations of the method of generating counterexamples through backward reasoning, the present invention introduces business process simulation and data dependency analysis techniques.

[0099] Business process simulation: Analyze the business process where the API is located and construct a business process model. Based on the business process model, simulate abnormal business scenarios. For example, for an order processing API, simulate scenarios such as abnormal order status (e.g., paying for a cancelled order again), insufficient inventory (order quantity exceeding inventory), etc. In each abnormal scenario, generate corresponding abnormal data and parameter modification solutions.

[0100] Data dependency analysis: Perform dependency analysis on the input and output data of the API to construct a data dependency graph. According to the data dependency graph, determine the association relationship between data. When generating counterexamples, consider the data dependency relationship to ensure that the generated counterexamples can simulate abnormal situations in real scenarios. For example, if the output data of one API is the input data of another API, when generating counterexamples, modify the relevant parameters of both APIs simultaneously to simulate abnormalities in the data transmission process.

[0101] In this way, through the forward channel, the neural network uses its powerful pattern recognition ability to predict parameter patterns; through the backward channel, the symbolic engine generates boundary condition cases based on rules, realizing two-way knowledge interaction and fusion between the neural network and symbolic logical reasoning.

[0102] S40. Parse different interface specifications through a multi-protocol adapter, including RESTful, GraphQL, and gRPC protocols, to generate protocol-adapted test cases.

[0103] In this embodiment, corresponding parsing and adaptation mechanisms are implemented for different interface specifications.

[0104] RESTful: Parse the x-constraints extension field in the OpenAPIv3 specification to obtain the constraint information therein. For example, the specific implementation solution is as follows:

[0105] When parsing the "x-constraints" extension field in the OpenAPIv3 specification, special situations and complex structures may be encountered.

[0106] Nested Constraint Handling: When there are nested constraints in the "x-constraints" field, the present invention adopts a recursive parsing method. The nested constraints are split into multiple sub-constraints and then parsed layer by layer. For example, for the constraint "(param1>10 AND param2<20) OR (param3='value')", it is first split into two sub-constraints "(param1>10 AND param2<20)" and "(param3='value')", and then each sub-constraint is parsed separately.

[0107] Custom Constraint Parsing: If the "x-constraints" contains custom constraints, the present invention provides a constraint parser registration mechanism. Developers can register custom constraint parsing functions, and the system will call the corresponding parsing functions for processing during parsing.

[0108] Compatibility Handling: For old versions of the OpenAPI specification that do not support the "x-constraints" extension field, the present invention extracts constraint information from the "description" field. If the "description" contains constraint descriptions, they will be identified and converted into processable constraint conditions through natural language processing techniques. In the OpenAPI specification, the description field is a general field for text descriptions of API elements (such as paths, parameters, responses, etc.). In old versions of OpenAPI (such as version 2), when there is a lack of structured constraint fields (such as x-constraints), the description field may contain natural language descriptions of business logic or parameter constraints. Example implementation:

[0109] Input Description: "The discount rate is calculated based on the user level. For ordinary users, the discount rate ≤ 0.8, and for VIP users, the discount rate ≤ 0.5."

[0110] Output Constraint:

[0111] if userLevel == "NORMAL":

[0112] discountRate ≤ 0.8

[0113] elif userLevel == "VIP":

[0114] discountRate ≤ 0.5

[0115] GraphQL: Automatically extract the type dependencies in the Schema to provide a basis for test case generation. For example, the specific implementation solution is as follows:

[0116] When automatically extracting type dependencies in a Schema, complex type definitions and nested structures may be encountered.

[0117] Complex type processing: For nested types and list types, the present invention uses a depth-first search (DFS) algorithm to traverse the Schema tree and construct a type dependency graph. For example, for a nested object type "{field1:{subField1:Int},field2:[String]}", the DFS algorithm is used to find the dependencies between field1 and subField1 and between field2 and String.

[0118] Compatibility processing: For different versions of the GraphQL specification, the present invention maintains a specification version mapping table. When parsing the Schema, the corresponding parsing rules are selected according to the version information. For example, for new features introduced in a new version (such as interface inheritance), the corresponding parsing logic is adopted.

[0119] gRPC: The service dependency graph is parsed through Protocol Buffer to achieve effective testing of gRPC interfaces.

[0120] Embodiment 2

[0121] Based on the same concept, the present invention also proposes an API test case generation device based on neuro-symbolic reasoning, including:

[0122] A neuro-semantic parsing module that parses unstructured API documents through a built-in neuro-semantic parser to extract parameter patterns, and the neuro-semantic parser uses a multi-layer Transformer model to implement natural language processing;

[0123] A symbolic rule library that performs symbolic logic verification on candidate test cases based on built-in first-order logic, temporal logic, and business rules;

[0124] A dynamic coordination engine that fuses the generation confidence N(x) of the neural network and the satisfaction degree S(x) of the symbolic rules through a built-in dynamic coordinator to generate final test cases; wherein, the dynamic coordinator dynamically adjusts the weight parameters α and β based on a hybrid reasoning algorithm, satisfying:

[0125] Test case generation = argmax(α*N(x)+β*S(x))(α + β = 1)

[0126] The weight parameters are dynamically adjusted according to the historical error rate;

[0127] A multi-protocol adapter that parses different interface specifications through the multi-protocol adapter, including RESTful, GraphQL, and gRPC protocols, to generate protocol-adapted test cases;

[0128] Reverse reasoning module, when the symbolic logic verification fails, start reverse reasoning to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data.

[0129] In this embodiment, the system architecture of the present invention includes the following modules:

[0130] Neural semantic parsing module: Use a 12-layer Transformer model to parse unstructured API documents (such as Markdown), extract explicit parameter types (such as integer) and implicit business constraints (such as "discount rate is related to user level").

[0131] Symbolic rule library: Store first-order logic (such as "parameter A > 0"), temporal logic (such as "end time > start time") and business rules (such as "users with level ≥ VIP can access") to verify the compliance of candidate test cases.

[0132] Dynamic coordination engine: Dynamically fuse the confidence of the neural network generation (N(x)) and the satisfaction of symbolic rules (S(x)) based on a hybrid reasoning algorithm to generate the final test case.

[0133] Reverse reasoning unit: When the symbolic verification fails, generate counterexample test cases that violate the constraints (such as modifying the parameter to an illegal value).

[0134] Multi-protocol adapter: Support the parsing and adaptation of interface specifications such as RESTful, GraphQL, and gRPC, and adopt a pluggable plugin architecture to expand the support for new protocols.

[0135] Preferably, in order to improve the scalability of multi-protocol adaptation, the present invention adopts a pluggable architecture design.

[0136] Plugin interface definition: Define a set of unified plugin interfaces, including the "Parser" interface for parsing interface specifications, the "Adapter" interface for adapting different interface types, and the "Validator" interface for verifying whether the generated test cases meet the specifications. The adapters for each interface specification need to implement these interfaces.

[0137] Plugin management mechanism: Design a plugin management module responsible for the loading, registration, and invocation of plugins. When the system starts, the plugin management module will automatically scan the plugin directory and load all plugins that implement the plugin interfaces. According to the interface specifications of the API, dynamically select the appropriate plugins for parsing and adaptation.

[0138] New interface specification support: When a new interface specification appears, developers only need to implement the plug-in interface, develop the corresponding plug-in, and place the plug-in in the plug-in directory. The system will automatically recognize and use the new plug-in without modifying the core code of the system. For the upgrade of existing interface specifications, developers can update the corresponding plug-ins to support new features and specifications.

[0139] Embodiment 3

[0140] This embodiment also provides an electronic device. Refer to Figure 2 , including a memory 404 and a processor 402. The memory 404 stores a computer program, and the processor 402 is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0141] Specifically, the above processor 402 may include a central processing unit (CPU), or a specific integrated circuit (Application Specific Integrated Circuit, abbreviated as ASIC), or may be configured with one or more integrated circuits implementing the embodiments of the present invention.

[0142] Among them, the memory 404 may include a mass storage 404 for data or instructions. By way of example and not limitation, the memory 404 may include a hard disk drive (HDD), a floppy disk drive, a solid state drive (SSD), a flash memory, an optical disc, a magneto-optical disc, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of these. In a suitable case, the memory 404 may include removable or non-removable (or fixed) media. In a suitable case, the memory 404 may be internal or external to the data processing device. In a particular embodiment, the memory 404 is a non-volatile memory. In a particular embodiment, the memory 404 includes a read-only memory (ROM) and a random access memory (RAM). In a suitable case, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically alterable ROM (EAROM), or a flash memory (FLASH), or a combination of two or more of these. In a suitable case, the RAM may be a static random access memory (SRAM) or a dynamic random access memory (DRAM), where the DRAM may be a fast page mode dynamic random access memory (FPMDRAM), an extended date out dynamic random access memory (EDODRAM), a synchronous dynamic random access memory (SDRAM), etc.

[0143] The memory 404 can be used to store or cache various data files required for processing and / or communication, as well as possible computer program instructions executed by the processor 402.

[0144] The processor 402 reads and executes the computer program instructions stored in the memory 404 to implement any one of the API test case generation methods based on neuro-symbolic reasoning in the above embodiments.

[0145] Optionally, the above electronic device may further include a transmission device 406 and an input / output device 408. Among them, the transmission device 406 is connected to the above processor 402, and the input / output device 408 is connected to the above processor 402.

[0146] The transmission device 406 can be used to receive or send data via a network. Specific examples of the above network may include wired or wireless networks provided by the communication provider of the electronic device. In one example, the transmission device includes a network adapter (abbreviated as NIC), which can be connected to other network devices through a base station and thus communicate with the Internet. In one example, the transmission device 406 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0147] The input / output device 408 is used to input or output information.

[0148] Embodiment 4

[0149] This embodiment also provides a readable storage medium. The readable storage medium stores a computer program, and the computer program includes program code for controlling a process to execute the process. The process includes the API test case generation method based on neuro-symbolic reasoning according to Embodiment 1.

[0150] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation manners, and will not be repeated here.

[0151] Generally, various embodiments can be implemented in hardware or special circuits, software, logic, or any combination thereof. Some aspects of the present invention can be implemented in hardware, while other aspects can be implemented by firmware or software executed by a controller, a microprocessor, or other computing devices, but the present invention is not limited thereto. Although various aspects of the present invention can be shown and described as block diagrams, flowcharts, or using some other graphical representations, it should be understood that, as a non-limiting example, the blocks, devices, systems, technologies, or methods described herein can be implemented in hardware, software, firmware, special circuits or logic, general hardware or a controller, or other computing devices, or some combination thereof.

[0152] Embodiments of the present invention can be implemented by computer software, which can be executed by a data processor of a mobile device, such as in a processor entity, or implemented by hardware, or implemented by a combination of software and hardware. A computer software or program (also referred to as a program product), including software routines, applets, and / or macros, can be stored in any device-readable data storage medium, and they include program instructions for performing specific tasks. The computer program product can include one or more computer-executable components configured to execute the embodiments when the program runs. One or more computer-executable components can be at least one software code or a part thereof. Additionally, at this point, it should be noted that any box in the logical flow, as Figure 1 described, can represent a program step, or interconnected logic circuits, boxes, and functions, or a combination of program steps and logic circuits, boxes, and functions. The software can be stored on physical media such as memory chips or storage blocks implemented within a processor, magnetic media such as hard disks or floppy disks, and optical media such as, for example, DVDs and their data variants, CDs. The physical media are non-transitory media.

[0153] Those skilled in the art should understand that the technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered to be within the scope described in this specification.

[0154] The above embodiments only represent several implementation manners of the present invention. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the present invention. It should be pointed out that for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.< / tag>

Claims

1. A method for generating API test cases based on neural symbolic reasoning, characterized in that: The following steps are involved: S00, parsing the unstructured API document by a neural semantic parser to extract parameter patterns, wherein the neural semantic parser uses a multi-layer Transformer model to implement natural language processing; S10, based on the first-order logic, temporal logic and business rules in the symbolic rule library, perform symbolic logic verification on the candidate test cases; S20, generating a final test case by fusing the generation confidence N(x) of the neural network and the satisfaction S(x) of the symbolic rule through a dynamic coordinator; wherein the dynamic coordinator dynamically adjusts the weight parameters α and β based on a hybrid reasoning algorithm to satisfy: Use case generation = argmax(α*N(x)+β*S(x))(α+β=1) The weight parameter is dynamically adjusted according to the historical error rate; S30, when the symbolic logic verification fails, reverse reasoning is initiated to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data; S40. Parse different interface specifications, including RESTful, GraphQL, and gRPC protocols, through a multi-protocol adapter to generate test cases for protocol adaptation.

2. The method for generating API test cases based on neural symbolic reasoning according to claim 1, characterized in that: Maintain a queue of length m to calculate the average error rate, and compare the neural generation error rate e_N with the symbol verification error rate e_S to adjust α and β.

3. The method for generating API test cases based on neural symbolic reasoning according to claim 1, characterized in that: In step S30, the step of generating a counterexample by reverse reasoning includes: Modify the numerical parameter to a boundary value or an illegal value; Modify the string parameter to an illegal value that violates the length or character set; Replace enumeration parameters with illegal enumeration values; Generate exception scenario use cases based on business process simulation and data dependency analysis.

4. The method for generating API test cases based on neural symbolic reasoning according to claim 1, characterized in that: In step S40, the parsing step of the multi-protocol adapter includes: Parse OpenAPI v3 extension fields for RESTful interfaces and handle nested constraints through recursive parsing; Extract type dependencies in GraphQL Schema and build a type dependency graph; Parse the gRPC Protocol Buffer file and build a service dependency graph; Compatible with different versions of interface specifications through pluggable plug-in architecture.

5. The method for generating API test cases based on neural symbolic reasoning according to claim 4, characterized in that: In step S40, the parsing step of the multi-protocol adapter further includes: For old OpenAPI documents, extract constraint information from the "description" field; Maintain the version mapping table to select parsing rules for different versions of GraphQL specifications; Perform service dependency graph analysis on gRPC's Protocol Buffer files to support complex service definitions.

6. The method for generating API test cases based on neural symbolic reasoning according to claim 2, characterized in that: The specific steps of dynamically adjusting the weight parameters in step S20 include: Maintain the historical error rate queue, calculate the neural network generation error rate e_N and the symbolic logic verification error rate e_S; Adjust the weights based on the error rate comparison results: If e_N > e_S, α decreases by Δ and β increases by Δ; If e_N < e_S, then α increases by Δ and β decreases by Δ; Δ is the adaptive adjustment step size, with an initial value of 0.05, and is dynamically scaled according to the error rate fluctuation amplitude. The step size is reduced when the fluctuation amplitude is less than 0.02, and the step size is increased when the fluctuation amplitude is greater than 0.

05.

7. A method for generating API test cases based on neural symbolic reasoning according to any one of claims 1 to 6, characterized in that: In step S20, the initial values ​​of weight parameters α and β are both set to 0.

5.

8. An API test case generation device based on neural symbolic reasoning, characterized in that: include: The neural semantic parsing module parses unstructured API documents and extracts parameter patterns through a built-in neural semantic parser. The neural semantic parser uses a multi-layer Transformer model to implement natural language processing. The symbolic rule library performs symbolic logic verification on candidate test cases based on built-in first-order logic, temporal logic, and business rules; The dynamic coordination engine generates the final test case by fusing the generation confidence N(x) of the neural network and the satisfaction S(x) of the symbolic rule through the built-in dynamic coordinator. The dynamic coordinator dynamically adjusts the weight parameters α and β based on the hybrid reasoning algorithm to meet the following requirements: Use case generation = argmax(α*N(x)+β*S(x))(α+β=1) The weight parameters are dynamically adjusted based on the historical error rate; Multi-protocol adapter, which parses different interface specifications, including RESTful, GraphQL, and gRPC protocols, and generates test cases for protocol adaptation; The reverse reasoning module starts reverse reasoning to generate counterexamples when the symbolic logic verification fails, including modifying parameters to violate constraints or injecting abnormal data.

9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the API test case generation method based on neural symbolic reasoning as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that: The readable storage medium stores a computer program, which includes a program code for controlling a process to execute a process, and the process includes the API test case generation method based on neural symbolic reasoning according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Learning Rules and Dictionaries with Neuro-Symbolic Artificial Intelligence

    US20220269858A1

  • Explaining neuro-symbolic reinforcement learning reasoning

    US20240320503A1