API test case generation method and device based on neural symbol reasoning and readable storage medium thereof

Through the neural symbolic inference fusion architecture, combined with the advantages of neural networks and symbolic logic, dynamically adjust the weight 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.

CN119902991AActive Publication Date: 2025-04-29SHENZHEN SHENGQIANG TECH

Patent Information

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

AI Technical Summary

Technical Problem

The existing technology has significant flaws in complex constraint processing capabilities, testing efficiency and coverage balance, and multi-protocol compatibility, and cannot effectively generate API 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, combined with the verification of the symbol rule base, dynamically adjust the weight to generate test cases, and supports RESTful/GraphQL/gRPC multi-protocol adaptation.

Benefits of technology

It significantly improves complex constraint processing capabilities and test coverage, reduces invalid use case generation rate and resource consumption, and enhances API testing efficiency and multi-protocol compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902991A_ABST
    Figure CN119902991A_ABST
Patent Text Reader

Abstract

The invention provides an API test case generation method and device based on neural symbol reasoning and a readable storage medium, and the method and device extract a parameter mode through a neural semantic analyzer, verify complex constraints in combination with a symbol rule base, and dynamically adjust the weight of neural generation and symbol verification through a dynamic coordinator, thereby achieving efficient and compliant test case generation. And when the constraints conflict, the reverse reasoning module generates parameters and abnormal data which violate the constraints, and supports nested constraint analysis and dependency analysis of the RESTfull / GraphQL / gRPC protocol through a multi-protocol adapter. Experiments show that the maximum generation speed of the use case can reach 2100 / s, the constraint violation detection rate is 98% +, the CPU occupation is only 38%, and the test efficiency and quality are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the intersection of software engineering and artificial intelligence, and in particular to a method and device for generating API test cases based on neural symbolic reasoning, and a readable storage medium thereof. Background Art

[0002] In the field of software engineering, API testing is a key link in ensuring system quality. With the popularity of microservice architecture and the Internet of Things, the number and complexity of APIs have increased dramatically, and existing testing technologies face the following challenges: 1. Rule-driven methods (such as Swagger parsing) rely on explicit parameter types and cannot handle implicit business logic such as "discount rate is related to user level", and the parsing success rate for unstructured documents (such as Markdown) is less than 40%.

[0003] 2. Random testing techniques (such as RESTler) generate invalid use cases accounting for as high as 78%, and the coverage of security protocols (such as OAuth2.0) is less than 15%.

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

[0005] In summary, the existing technology has significant defects in complex constraint processing capabilities, test efficiency and coverage balance, and multi-protocol compatibility.

[0006] Therefore, there is an urgent need for an API test case generation method, device and readable storage medium based on neural symbolic reasoning that is suitable for interface testing of microservice architecture, cloud computing platform and Internet of Things system, focusing on test case generation under complex parameter constraints, so as to solve the problems existing in the prior art. Summary of the invention

[0007] The embodiments of the present invention provide a method and device for generating API test cases based on neural symbolic reasoning, and a readable storage medium thereof, which aims to address the problems existing in the current technology that the flexibility of generating test cases by neural networks and the rule constraints of symbolic logic cannot be effectively balanced, resulting in insufficient processing capabilities for complex parameter constraints, high invalid test case generation rate, poor multi-protocol adaptability, and reliance on a large amount of labeled data.

[0008] The core technology of this invention is mainly to use the neural symbolic reasoning fusion architecture, combine the pattern recognition ability of neural networks and the rule verification ability of symbolic logic, dynamically adjust weights to generate test cases that meet complex constraints, and support RESTful / GraphQL / gRPC multi-protocol adaptation, significantly improving test efficiency and coverage.

[0009] In a first aspect, the present invention provides a method for generating API test cases based on neural symbolic reasoning, the method comprising the following steps: S00. Parse the unstructured API document and extract parameter patterns through the neural semantic parser, which 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 parameters are dynamically adjusted based on the historical error rate; S30, when the symbolic logic verification fails, initiating reverse reasoning 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.

[0010] Furthermore, a queue of length m is maintained to calculate the average error rate, and the neural generation error rate e_N is compared with the symbol verification error rate e_S to adjust α and β.

[0011] Furthermore, 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.

[0012] Furthermore, 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.

[0013] Further, in step S40, the parsing step of the multi-protocol adapter further includes: For the old version of the OpenAPI document, extract constraint information from the "description" field; For different versions of the GraphQL specification, maintain a version mapping table to select parsing rules; Perform service dependency graph analysis on the Protocol Buffer file of gRPC to support complex service definitions.

[0014] Further, the specific steps of dynamically adjusting the weight parameters in step S20 include: 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; Adjust the weights according to the error rate comparison result: If e_N > e_S, then α 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 it 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.

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

[0016] In a second aspect, the present invention provides an API test case generation device based on neuro-symbolic reasoning, including: A neuro-semantic parsing module that parses unstructured API documents through a built-in neuro-semantic parser to extract parameter patterns. The neuro-semantic parser uses a multi-layer Transformer model to implement natural language processing; 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; 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: Test case generation = argmax(α * N(x) + β * S(x)) (α + β = 1) The weight parameters are dynamically adjusted according to the historical error rate; 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; 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.

[0017] In a third aspect, the present invention provides an electronic device including a memory and a processor, wherein 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 neural symbolic reasoning.

[0018] In a fourth aspect, the present invention provides a readable storage medium, in which a computer program is stored. The computer program includes a program code for controlling a process to execute the process. The process includes the above-mentioned method for generating API test cases based on neural symbolic reasoning.

[0019] The main contributions and innovations of the present invention are as follows: 1. Enhanced processing capabilities for complex constraints: By extracting explicit / implicit constraints from unstructured documents through a neural semantic parser and combining it with verification of a symbolic rule library, the detection rate of complex logical constraints (such as temporal relationships and business rules) is increased to over 98%.

[0020] 2. Test efficiency and quality optimization: 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 use cases from 78% of the traditional method to 12%, and generates test cases at a speed of up to 2,100 cases per second.

[0021] 3. Improved multi-protocol compatibility: Adapts to RESTful, GraphQL, gRPC and other protocols through a pluggable plug-in architecture, supports nested constraint parsing, type dependency graph construction and service dependency analysis, and covers more than 95% of common interface specifications.

[0022] 4. Resource consumption is significantly reduced: CPU usage is reduced to 38% compared with traditional solutions, test preparation time is shortened by 24 times, and the regression test cycle is compressed to 1 / 5.6 of the original cycle, reducing hardware resource investment.

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

[0024] The details of one or more embodiments of the invention are set forth in the following drawings and description so that other features, objects, and advantages of the invention are more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary 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: Figure 1 is a flowchart of a method for generating API test cases based on neural symbolic reasoning according to an embodiment of the present invention; Figure 2 4 is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0026] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, 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.

[0027] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed 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 be combined into a single step for description in other embodiments.

[0028] Existing technologies either cannot handle implicit constraints due to reliance on explicit rules, or waste resources due to random generation, or have high machine learning labeling costs and cannot guarantee logical constraints. All of these make it difficult to meet the needs of efficient testing in complex scenarios.

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

[0030] Embodiment 1 The present invention aims to propose a method for generating API test cases based on neural symbolic reasoning. Specifically, referring to Figure 1 , the method comprises the following steps: S00. Parse the unstructured API document and extract parameter patterns through the neural semantic parser, which uses a multi-layer Transformer model to implement natural language processing; In this embodiment, the neural semantic parser adopts a 12-layer Transformer model, which has powerful natural language processing capabilities, can efficiently process unstructured documents, and accurately extract parameter patterns from API documents.

[0031] 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; In this embodiment, the symbolic rule library supports three types of constraints: first-order logic, temporal logic, and business rules, providing a rule basis for symbolic logic reasoning and used to verify whether test cases meet various constraints.

[0032] S20, the dynamic coordinator fuses 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 to generate the final test case; wherein the dynamic coordinator dynamically adjusts the weight parameters α and β (α+β=1) based on the hybrid reasoning algorithm to satisfy: Use case generation = argmax(α*N(x)+β*S(x))(α+β=1) The weight parameters are dynamically adjusted based on the historical error rate; In this embodiment, the dynamic coordinator realizes the dynamic fusion of the neural network generation results and the symbolic logic verification results based on the neural-symbolic weight allocation algorithm of game theory, and flexibly adjusts the weights of the two according to different test scenarios and requirements to generate the optimal test case.

[0033] Preferably, in the hybrid reasoning algorithm "use case generation = argmax(α*N(x)+β*S(x))", the initial values ​​of the dynamic weight parameters α and β should be set to comprehensively consider the reliability of the neural network and symbolic logic reasoning in the initial stage. Due to the lack of historical data support when the test is started, both α and β can be initially set to 0.5. This setting means that at the beginning, the generation confidence N(x) of the neural network and the satisfaction S(x) of the symbolic rule are given the same importance, so as to balance the role of the two in the test case generation process.

[0034] The adjustment step size dynamically adjusted according to the historical error rate is the key factor in controlling the update amplitude of the weight parameter. The present invention adopts an adaptive adjustment step size strategy, and the initial adjustment step size Δ is set to 0.05. In each iteration, the step size is dynamically adjusted according to the change of the historical error rate. The specific rules are as follows: If the current error rate changes less than 0.02 compared to the previous error rate (i.e., the error rate is relatively stable), the adjustment step size will be reduced to 0.8 times the original value, i.e., Δ=Δ×0.8.

[0035] If the change rate of the current error rate compared to the previous error rate is greater than 0.05 (i.e., the error rate fluctuates significantly), then increase the adjustment step size to 1.2 times the original, i.e., Δ = Δ × 1.2.

[0036] Preferably, the specific steps of the algorithm for precisely adjusting according to the historical error rate are as follows: Maintain a historical error rate queue E with a length of m (e.g., m = 10). After each test is completed, the current error rate e_current is added to the queue, and at the same time, the earliest error rate value is removed to ensure that the queue length is always m. Then calculate the average value of the error rates in the queue.

[0037] 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: If e_N > e_S, it indicates that the accuracy of the neural network generation is low, and its weight needs to be reduced while increasing the weight of symbolic logic. At this time, α = α - Δ, β = β + Δ.

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

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

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

[0041] S30. When the symbolic logic verification fails, start reverse inference to generate counterexamples, including modifying parameters to violate constraints or injecting abnormal data; In this embodiment, the S30 step is a constraint conflict resolution process: The neural module first generates a candidate parameter set C.

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

[0043] If C' is an empty set, that is, all candidate cases do not conform to the rules, then start reverse inference to generate counterexamples at this time. 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 in abnormal situations.

[0044] Preferably, the specific strategy for generating counterexamples by reverse reasoning is as follows: 1. Choose appropriate parameters to modify to violate specific constraints Numeric parameters: For numeric parameters with range constraints, select boundary values ​​and values ​​outside the boundary to modify. For example, if the constraint of the parameter "age" is "18<=age<=60", you can modify "age" to 17 or 61. For numeric parameters without clear range constraints, select maximum value, minimum value, and zero value to modify, such as "Integer.MAX_VALUE", "Integer.MIN_VALUE" and 0 in Java.

[0045] String parameters: For string parameters with length constraints, select a string whose length is less than the minimum length and greater than the maximum length to modify. For example, if the length constraint of the string parameter "name" is "3<=length(name)<=20", you can modify "name" to a string with a length of 2 or 21. For string parameters with character set constraints, select a string consisting of characters that are not in the character set to modify.

[0046] Enumeration parameter: Select an illegal value other than the enumeration value to modify. For example, if the enumeration type "Color" contains "RED", "GREEN", and "BLUE", you can modify the parameter to "YELLOW".

[0047] 2. Determine the type and scope of injected abnormal data 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 files .exe), oversized files (exceeding server limits), etc.

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

[0049] Preferably, in order to overcome the limitations of the reverse reasoning method for generating counterexamples, the present invention introduces business process simulation and data dependency analysis technology.

[0050] Business process simulation: Analyze the business process of the API and build a business process model. Based on the business process model, simulate abnormal business scenarios. For example, for the order processing API, simulate scenarios such as abnormal order status (such as re-payment for a canceled order) and insufficient inventory (the order quantity exceeds the inventory). In each abnormal scenario, generate corresponding abnormal data and parameter modification solutions.

[0051] Data dependency analysis: Perform dependency analysis on the input and output data of the API and build a data dependency graph. According to the data dependency graph, determine the association between data. When generating counterexamples, consider data dependencies 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 the two APIs at the same time to simulate abnormalities in the data transmission process.

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

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

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

[0055] RESTful: Parse the x-constraints extension field in the OpenAPIv3 specification to obtain the constraint information. For example, the specific implementation scheme is as follows: When parsing the "x-constraints" extension field in the OpenAPIv3 specification, you may encounter special cases and complex structures.

[0056] Nested constraint processing: 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>10ANDparam2<20)OR(param3='value')", it is first split into two sub-constraints "(param1>10ANDparam2<20)" and "(param3='value')", and then each sub-constraint is parsed separately.

[0057] Custom constraint parsing: If "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 function for processing during parsing.

[0058] Compatibility processing: For older versions of the OpenAPI specification that do not support the "x-constraints" extension field, the present invention will extract constraint information from the "description" field. If the "description" contains a constraint description, it will be identified and converted into processable constraints through natural language processing technology. In the OpenAPI specification, the description field is a general field used to provide text descriptions of API elements (such as paths, parameters, responses, etc.). In older versions of OpenAPI (such as version v2), when there is a lack of structured constraint fields (such as x-constraints), the description field may contain a natural language description of business logic or parameter constraints. Example implementation: Input description: "The discount rate is calculated based on the user level. The discount rate for ordinary users is ≤0.8, and the discount rate for VIP users is ≤0.5." Output constraints: if userLevel == "NORMAL": discountRate ≤ 0.8 elif userLevel == "VIP": discountRate ≤ 0.5 GraphQL: Automatically extract type dependencies in the Schema to provide a basis for test case generation. For example, the specific implementation plan is as follows: When automatically extracting type dependencies in a schema, you may encounter complex type definitions and nested structures.

[0059] 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 build a type dependency graph. For example, for a nested object type "{field1:{subField1:Int},field2:[String]}", the DFS algorithm is used to find the dependency between field1 and subField1, and between field2 and String.

[0060] Compatibility processing: For different versions of GraphQL specifications, 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 the new version (such as interface inheritance), the corresponding parsing logic is adopted.

[0061] gRPC: Parse the service dependency graph through Protocol Buffer to achieve effective testing of the gRPC interface.

[0062] Embodiment 2 Based on the same concept, the present invention also proposes an API test case generation device based on neural symbolic reasoning, comprising: 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.

[0063] In this embodiment, the system architecture of the present invention includes the following modules: Neural semantic parsing module: uses 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").

[0064] Symbolic rule library: stores first-order logic (such as "parameter A>0"), temporal logic (such as "end time>start time"), and business rules (such as "user level ≥ VIP access"), which are used to verify the compliance of candidate test cases.

[0065] Dynamic coordination engine: Based on the hybrid reasoning algorithm, the neural network dynamically fuses the confidence (N(x)) and the symbolic rule satisfaction (S(x)) to generate the final use case.

[0066] Reverse reasoning unit: When symbolic verification fails, it generates counterexamples that violate the constraints (such as modifying parameters to illegal values).

[0067] Multi-protocol adapter: supports parsing and adaptation of interface specifications such as RESTful, GraphQL, gRPC, and uses a pluggable plug-in architecture to expand support for new protocols.

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

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

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

[0071] 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 upgrades to existing interface specifications, developers can update the corresponding plug-in to support new features and specifications.

[0072] Embodiment 3 This embodiment also provides an electronic device, referring to Figure 2 , comprises a memory 404 and a processor 402, wherein the memory 404 stores a computer program, and the processor 402 is configured to run the computer program to execute the steps in any of the above method embodiments.

[0073] Specifically, the processor 402 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiment of the present invention.

[0074] Among them, the memory 404 may include a large capacity memory 404 for data or instructions. For example, but 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 disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive, or a combination of two or more of these. In appropriate cases, the memory 404 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 404 may be inside or outside the data processing device. In a specific embodiment, the memory 404 is a non-volatile memory. In a specific embodiment, the memory 404 includes a read-only memory (ROM) and a random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (Programmable Read-Only Memory, PROM for short), an erasable PROM (Erasable Programmable Read-Only Memory, EPROM for short), an electrically erasable PROM (Electrically Erasable Programmable Read-Only Memory, EEPROM for short), an electrically alterable ROM (Electrically Alterable Read-Only Memory, EAROM for short) or a flash memory (FLASH) or a combination of two or more of these. In appropriate circumstances, the RAM may be a static random access memory (SRAM) or a dynamic random access memory (DRAM), wherein the DRAM may be a fast page mode dynamic random access memory 404 (FPMDRAM), an extended data output dynamic random access memory (EDODRAM), a synchronous dynamic random access memory (SDRAM), etc.

[0075] The memory 404 may 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 .

[0076] The processor 402 implements any one of the methods for generating API test cases based on neural symbolic reasoning in the above embodiments by reading and executing computer program instructions stored in the memory 404 .

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

[0078] The transmission device 406 can be used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired or wireless network provided by a communication provider of the electronic device. In one example, the transmission device includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 406 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.

[0079] Input / output devices 408 are used to input or output information.

[0080] Embodiment 4 This embodiment also provides a readable storage medium, in which a computer program is stored. The computer program includes a program code for controlling a process to execute the process. The process includes the method for generating API test cases based on neural symbolic reasoning according to the first embodiment.

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

[0082] In general, various embodiments may be implemented in hardware or dedicated circuits, software, logic, or any combination thereof. Some aspects of the invention may be implemented in hardware, while other aspects may be implemented in firmware or software executed by a controller, microprocessor, or other computing device, but the invention is not limited thereto. Although various aspects of the invention may be shown and described as block diagrams, flow charts, or using some other graphical representation, it should be understood that, as non-limiting examples, the boxes, devices, systems, techniques, or methods described herein may be implemented in hardware, software, firmware, dedicated circuits or logic, general-purpose hardware or controllers or other computing devices, or some combination thereof.

[0083] Embodiments of the present invention may be implemented by computer software that is executable by a data processor of a mobile device, such as in a processor entity, or by hardware, or by a combination of software and hardware. Computer software or programs (also referred to as program products) including software routines, applets and / or macros may be stored in any device-readable data storage medium, and they include program instructions for performing specific tasks. A computer program product may include one or more computer executable components configured to perform an embodiment when the program is run. One or more computer executable components may be at least one software code or a portion thereof. In addition, at this point, it should be noted that, for example, Figure 1 Any block of the logic flow in the program may represent program steps, or interconnected logic circuits, blocks and functions, or a combination of program steps and logic circuits, blocks and functions. The software may 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, etc. Physical media are non-transitory media.

[0084] Those skilled in the art should understand that the technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0085] The above embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present invention. It should be pointed out that, for those of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the attached 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

  • Text processing method and device and electronic equipment

    CN114896973A

  • Learning Rules and Dictionaries with Neuro-Symbolic Artificial Intelligence

    US20220269858A1

  • Explaining neuro-symbolic reinforcement learning reasoning

    US20240320503A1

Cited By

  • Shared library-oriented fuzzy device automatic generation method and device

    CN120872448A

  • Fuzzing method and device for shared library

    CN120872448B

  • Interface testing method and electronic equipment

    CN120892354A

  • An interface testing method and electronic device

    CN120892354B

  • Method and system for providing unified portal integration for enterprise

    CN121456041A