API interface test data processing method and device and computer readable medium
By configuring dynamic rules and managing session context, combined with AI agent evaluation, the problem of dynamic data processing in API interface testing was solved, achieving efficient and accurate end-to-end testing, reducing maintenance costs and improving the reliability of test results.
Patent Information
- Application Number
- CN202511719398.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-02-13
AI Technical Summary
Existing technologies struggle to handle dynamically changing response data in API interface testing, requiring frequent modifications to test scripts. They also cannot simulate multi-round sessions or verify complex data structures, resulting in high maintenance costs and inaccurate test results.
By configuring dynamic rules, the request body is constructed using file_extractor, random_generator, and response_extractor rules. Combined with session context management, the response data is dynamically constructed and parsed. Semantic evaluation is performed using AI agents to simulate multi-turn interaction behaviors.
It reduces testing and maintenance costs, improves the accuracy and reliability of test results, can handle complex data structures and security data in modern API interfaces, and expands verification capabilities.
Smart Images

Figure CN121524072A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of software engineering and testing technology, and particularly relates to an API interface test data processing method and device and a computer readable medium. BACKGROUND
[0002] With the popularity of microservice architecture and artificial intelligence application, the data structure returned by the backend API interface is becoming more and more complex, often in the form of deeply nested JSON, and a large number of data transmission encryption and multi-round conversation based on context are involved. The current mainstream method for automatically testing such interfaces relies on technical personnel to write static test scripts to perform testing. These scripts face the following defects in testing due to the construction logic of hard-coded request parameters, the extraction path JSONPath of response results, and the assertion conditions of expected values.
[0003] Any change in interface fields or test case format must be traced back and modified in the test script code, which is a large maintenance workload in a fast iteration development environment. Due to the use of fixed assertion conditions, dynamic changes in response data values such as session ID and token cannot be handled, as static scripts lack mechanisms for runtime extraction, storage, and transmission of these values, making it difficult to handle dynamic values such as session ID and token in the response. Additional and complex auxiliary functions are often required to achieve dynamic encryption / decryption of data content, which complicates script writing. Moreover, there is a lack of standard mechanisms to simulate and track the continuous state of the same user in multiple conversations, making it impossible to bind and correlate the conversation context. The verification capability is limited, and the assertion method is based on exact matching, which cannot effectively evaluate the quality of open intelligent responses that require semantic understanding. SUMMARY
[0004] The present application aims to solve the problem of being unable to handle dynamic changes in response data values in the prior art API interface test method, which relies on technical personnel to write static test scripts to perform testing, by providing an API interface test data processing method, device, and computer readable medium.
[0005] To achieve the above-mentioned purpose, the technical solution adopted by the present application is as follows:
[0006] An API interface test data processing method, comprising the following steps:
[0007] S1, updating test case data: setting a timing task to monitor the test case file of the cloud server, and automatically downloading a new test file and storing it in the database after detecting a change in the test file.
[0008] S2, configuring a dynamic rule: a variables_body rule of a configuration parameter of a request body in a predefined JSON configuration file as a dynamic rule, and loading the variables_body rule from the JSON configuration file; the configuration parameter includes a business parameter, a dynamically extracted input value, simulation data, and a session state value; the variables_body rule includes a file_extractor rule, a random_generator rule, and a response_extractor rule;
[0009] The file_extractor rule is used to establish a data mapping channel between the test case file and the request body, and declare to extract a value from a specified column field of a current test case row and fill in a specified position variable; the random_generator rule is used to generate a random value for a specified variable of the request body; and the response_extractor rule is used to declare to extract a specified path value from a previous response body of the same session, and store the specified path value in a context of a current session;
[0010] S3, reading and parsing the test case file through a data cleaning engine; and dynamically constructing the request body according to the dynamic rule and an instruction of the test case file;
[0011] S4, sending the request body to a tested API interface through a request client, and synchronously receiving a returned response body;
[0012] S5, receiving the response body through a response processing engine, and dynamically decrypting; extracting response data of the response body, and verifying the response data according to a verification benchmark of a test case file;
[0013] updating a session context: extracting a target value from the response body as a JSONPath in the dynamic rule; obtaining a SessionContext object of a current session, the SessionContext object including a first key-value pair and a mapping list; taking a specified position variable as a key and a specified path value of the response body as a value to form the first key-value pair; storing the first key-value pair in the mapping list through a Map.put(key, value) operation, and updating the SessionContext object; and taking a sessionKey as a key to save the updated SessionContext object again;
[0014] S6, session management: using the client MAC address, the Group and Rotation fields in the test case, a session key sessionKey is generated; the session key sessionKey is used to obtain or create a SessionContext object, and then a multi-round session is bound.
[0015] The API interface test data processing method provided by the application can replace hard coding by configuring dynamic rules, test logic changes do not need to modify the code, and only need to update the test case file or adjust the JSON configuration file to configure the dynamic rules, so that API interface test can be performed according to the dynamic change value of the response data, not only the maintenance cost is greatly reduced, and the session context is updated through the file_extractor rule, the random_generator rule and the response_extractor rule, the multi-round interaction behavior of the terminal user is accurately simulated, the end-to-end test is realized, and the accuracy of the test result is improved, and the reliability of the API interface test is improved.
[0016] The API interface test data processing method provided by the application, the dynamic construction of the request body further includes the following steps:
[0017] The ReqParam list is traversed, and if an encryption instruction is encountered in the test instruction, a decryption algorithm factory is called, a corresponding tool instance is returned according to a specified encryption and decryption algorithm, the original value of a specified field of the request body is encrypted, and the original value of the specified field is replaced with the ciphertext.
[0018] As a preferred scheme of the application, the built-in dynamic encryption and decryption framework and the complex JSON path parser can efficiently process the security data and complex data structure in the modern API interface, form strong data adaptability, realize the verification of the dynamic encryption content, and further improve the processing of the API interface test data and the universality of the API interface test.
[0019] Preferably, the API interface test data processing method, the verification of the response data specifically includes the following steps:
[0020] For the Expect_ header, the Expect_ header is converted into a JSONPath, the header value is extracted, and the header value is compared with the expected value of the verification reference; if the header value and the expected value are consistent, the verification is passed;
[0021] For the Others column, the cell content of the Others column is parsed into a second key-value pair, and the second key-value pair is recursively searched in the response body; if the second key-value pair does not exist in the response body or the value of the second key-value pair does not match, the verification fails;
[0022] For the AI_distinguishData_table header, the specified path value is extracted and stored and then sent to the AI agent, and the evaluation conclusion is obtained through the AI agent.
[0023] As a preferred scheme of the present application, the test result can be more accurately output by specific verification of different data, further improving the accuracy of the test, and the man-machine collaborative intelligent verification is realized by the participation of the AI agent, the traditional deterministic assertion and the AI AI agent uncertainty evaluation are fused, and the verification range and ability of the automatic test are expanded.
[0024] Preferably, the API interface test data processing method of the present application, the S5 further comprises AI agent collaborative verification:
[0025] If the ExpectAI_.AAA table header is encountered, the value under the path $.AAA is sent to the AI agent, the semantic score is obtained through the AI agent, and the first score is obtained; whether the first score is higher than the experience threshold is judged, and then whether the verification passes or not is judged;
[0026] If the cell value is Expect_prompt word, the Expect_prompt word and the extracted prompt word value are sent to the AI agent, the semantic score is obtained through the agent, the second score is obtained, and whether the second score is less than the preset threshold is judged; if the second score is less than the preset threshold, it is determined that the verification fails;
[0027] The error type and error index of the verification failure are returned through the AI agent.
[0028] As a preferred scheme of the present application, the man-machine collaborative intelligent verification is realized, the traditional deterministic assertion and the AI agent uncertainty evaluation are fused, and the verification range and ability of the automatic test are expanded.
[0029] Preferably, the API interface test data processing method of the present application, the detection file change of the test case is found, which specifically comprises the following steps:
[0030] The timing task is triggered, the SFTP connection with the cloud server is established, the.xlsx file under the specified directory is listed, the first MD5 value of the.xlsx file is calculated, the corresponding second MD5 value in the file_md5_collection collection of the database is queried, and if the first MD5 value and the second MD5 value are inconsistent, it is determined that the detection file is changed.
[0031] As a preferred scheme of the present application, the change of the test case detection file found by the above method can more accurately identify the detection file update or increase, thereby improving the timeliness of data processing, further reducing the error rate of API interface testing, and improving the accuracy of API interface testing.
[0032] Preferably, the API interface test data processing method of the present application comprises the following steps of reading and parsing the test case file:
[0033] Traverse the test case file to be processed in test_cases_collection, read the Group field and Rotation field in each row of the test case file respectively, obtain or generate the client MAC address, and then construct the session key for the test session;
[0034] When the value of the Group field is greater than 1 or the Rotation field contains multiple rounds, a co- prefix is added to the client MAC address; when the value of the Rotation field is 1 and there is no associated round, a test- prefix is added to the MAC address.
[0035] As a preferred scheme of the present application, by reading and parsing the test case file as described above, the multi-round session test and single-round independent test can be intuitively distinguished by the prefix, improving the recognition accuracy of the test category; in the subsequent data analysis and report generation stage, the system can quickly filter and aggregate different types of test data according to the prefix, improving the analysis efficiency; the prefix information provides additional context for session management, assisting the system to optimize resource allocation and scheduling strategy, further optimizing the API interface test data processing method, and further improving the dynamic coordination of the API interface test data processing method.
[0036] Preferably, the API interface test data processing method of the present application further comprises the following steps after S6:
[0037] Generating a test report: traversing the SessionContext object in Redis, sorting the rotationResults list of each session according to the Rotation field, generating a coherent multi-round test report for each session key sessionKey, and forming a final test report;
[0038] Storing and outputting the final test report; cleaning up the expired session context in the database.
[0039] As a preferred scheme of the present application, by the above report generation method and steps, the multi-round report and the error index provided by the agent can help developers quickly locate the specific round and reason of defect occurrence, realizing more accurate positioning of faults.
[0040] To achieve the object of the present application, the present application provides another technical solution:
[0041] An API interface test data processing device, comprising: a test case monitoring module, a database, a rule configuration module, a data cleaning engine, a request client, a response processing engine and a session management module; the test case monitoring module is used for monitoring a test case file of the cloud server; the rule configuration module is used for configuring dynamic rules; the data cleaning engine is used for reading and parsing the test case file, and dynamically constructing a request body; the request client is used for sending a request and accepting returned response data; the response processing engine is used for receiving and decrypting response data, extracting values and checking.
[0042] The API interface test data processing device provided by the present application can realize configuration-driven replacement of hard coding, test logic change without code modification, and greatly reduce maintenance costs; can internally build a dynamic encryption and decryption framework and a complex JSON path parser, realize efficient processing of secure data and complex data structures in modern API interfaces; through MAC, Group and Rotation triple binding and context persistence mechanism, user sessions can be simulated; the multi-round interaction behavior of terminal users can be accurately simulated to realize end-to-end testing.
[0043] To achieve the object of the present application, the present application provides another technical solution:
[0044] A computer readable medium having a computer program stored thereon, the computer program being executed by a processor to implement the API interface test data processing method.
[0045] As described above, due to the adoption of the above technical solutions, the present application has the following beneficial effects:
[0046] 1. By configuring dynamic rules, replacing hard coding, test logic change without code modification, only updating the test case file or adjusting the JSON configuration file to configure dynamic rules, API interface test can be performed according to the dynamic change value of the response data, not only greatly reducing the maintenance cost, but also updating the session context through the file_extractor rule, random_generator rule and response_extractor rule, accurately simulating the multi-round interaction behavior of terminal users, realizing end-to-end testing, improving the accuracy of test results and the reliability of API interface test;
[0047] 2. The configuration drive can replace hard coding, and the test logic change does not need to modify the code, which greatly reduces the maintenance cost; the dynamic encryption and decryption framework and complex JSON path parser can be built-in, which can realize efficient processing of secure data and complex data structure in modern API interface; through MAC, Group, Rotation triple binding and context persistence mechanism, the user session can be simulated; the multi-round interaction behavior of terminal user can be simulated accurately, and end-to-end test can be realized. BRIEF DESCRIPTION OF DRAWINGS
[0048] Figure 1 is a flowchart of the API interface test data processing method of the present application;
[0049] Figure 2 is a module connection diagram of the API interface test data processing device of the present application;
[0050] Figure 3 is a data flow diagram of the API interface test data processing device of the present application
[0051] Figure 4 is a flowchart of the API interface test data processing method of the present application for realizing multi-round session;
[0052] Figure 5 is an execution flowchart of the API interface test of the present application. DETAILED DESCRIPTION
[0053] The present application will be described in detail below with reference to the accompanying drawings.
[0054] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific examples described herein are only used to explain the present application, and are not used to limit the present application.
[0055] Example 1:
[0056] Reference Figure 1 and Figure 4 As shown in the drawings, the present embodiment discloses an API interface test data processing method, comprising the following steps:
[0057] S1, updating test case data: setting a timing task, monitoring the test case file of the cloud server, finding that the test case detection file is changed, then automatically downloading the new detection file and storing it in the database after parsing;
[0058] S2, configuring dynamic rules: predefine the variables_body rules of the configuration parameters of the request body in the JSON configuration file as dynamic rules, and load the variables_body rules from the JSON configuration file; the configuration parameters include business parameters, dynamically extracted input values, simulation data, and session state values; the variables_body rules include file_extractor rules, random_generator rules, and response_extractor rules;
[0059] S3, reading and parsing the test case file through a data cleaning engine; dynamically constructing the request body according to the dynamic rules and the instructions of the test case file;
[0060] S4, sending the request body to the API interface to be tested through a request client, and synchronously receiving the returned response body;
[0061] S5, receiving the response body and dynamically decrypting it through a response processing engine; extracting the response data of the response body, and verifying the response data according to the verification benchmark of the test case file;
[0062] Updating the session context: taking the specified path value in the dynamic rule as a JSONPath to extract a target value from the current response body; obtaining a SessionContext object of the current session, which includes a first key-value pair and a mapping list; taking the specified position variable as a key and the specified path value of the response body as a value to form a first key-value pair; storing the first key-value pair in the mapping list by performing a Map.put(key, value) operation, thereby updating the SessionContext object; and saving the updated SessionContext object again with a sessionKey as a key.
[0063] S6, session management: generating a session key sessionKey using a client MAC address, a Group, and a Rotation field in a test case; the session key sessionKey is used to obtain or create a SessionContext object, thereby binding multiple rounds of sessions.
[0064] The JSON configuration file described in the application is understood as a data carrier defining the dynamic generation strategy of the configuration parameters of the request body, for example, a rule_config.json file, the configuration parameters of the request body mainly function to constitute a data carrier containing the to-be-cleaned numerical content, the request body is to be sent to the API and pass necessary data content to the server, including: fixed business parameters, input values dynamically extracted from test cases, randomly generated simulation data, and session state values extracted from the previous response.
[0065] In the dynamic rule described in the application, variables_body is understood as a key name existing in rule_config.json, which is also a JSON body and a root node, defining a dynamic replacement rule, completing operations such as random value generation, value extraction from a file, and value extraction from a session context, and finally constructing a complete and immediately sendable JSON request body. variables_body is a dictionary composed of all to-be-replaced variables in the request body template, responsible for making the same test case run with multiple sets of data, realizing data driving. Among them, the file_extractor rule is different from the traditional reading of static input values from the test case file, and the file_extractor rule processes dynamically generated session state data, reads values from the test case according to the content of the request body configuration parameter, and fills them into the specified variable position of the request body, thereby realizing the dynamic configuration of the request parameter, randomly generating a MAC address, which can simulate a real client device, because the MAC address of each client device is different, and the random generation of the MAC address can realize this scenario; the file_extractor rule is understood as a test data injection rule, establishing a data mapping channel between the test case file and the API request body. When processing the test case, the system automatically reads data from the TestCase column of the case and injects it into the semantic field of the request body JSON; the random_generator dynamically generates a unique identifier for each test request, such as generating simulation values for the mac and device_id fields, to ensure that each test client has a unique identity.
[0066] Key parameters in the configured variables_body rule: field: "data.conversation_id": defines the exact JSONPath extraction path; default: "": provides a fault-tolerant mechanism to ensure that the process does not interrupt the lifecycle when extraction fails; lifecycle: "persist": declares the cross-request persistence characteristics of the variable corresponding to the data cleaning. This rule realizes the extraction, storage, and reuse of dynamic response data, and is the core mechanism of session context "cleaning" and "maintenance". The response_extractor rule is understood as obtaining the previously persisted value (such as conversation_id) from the extractedVariables Map of the current SessionContext object and filling it in. Application use case instructions: parse JsonKey and JsonValue, use the ObjectMapper of the Jackson library to accurately modify the request body JSON. Parse ReqParam, if it contains encrypt: true, call AES to obtain an encrypted instance, and encrypt the specified field.
[0067] For example: type: file_extractor: declares to extract the value from the specified column field in the current test case row and fill it into the specified variable of the request body; type: random_generator, declares to generate a random value for the specified variable of the request body, such as a random MAC address; type: response_extractor, declares to extract the value from the JSON body of the previous API response in the same session, specifies the path through field, such as data.conversation_id, and persists it in the session context for subsequent requests, realizing the configuration of multi-round session association.
[0068] The data cleaning engine described in the application is used for reading test case files to be cleaned, such as test files in xlsx format, containing specially designed table headers, such as: JsonKey, JsonValue: indicating accurate key value update or addition operation on the request body JSON; ReqParam: providing a list of key value pairs separated by semicolons, such as encrypt: true; algorithm: AES, used to control the request process, such as triggering encryption, Expect_AAA.BBB.CCC, defining the JSON path of the expected value in the response body; AI_distinguishData.domain0.name: defining the data path that needs to be extracted and provided for AI agent analysis; DecryptContent: defining the field path that needs to be decrypted in the response body, such as.AAA indicating the value under the path of $.AAA; Group, Rotation: defining the group number and rotation number in the test case respectively.
[0069] The JSONPath described in the application, such as Expect_data.domain->$.data.domain, is understood as a lightweight query language for JSON documents, and the SessionContext object is understood as a session context object, which is a shared container at thread / task level, used to save and pass state information across functions, components and requests during user session or business graph running, and the Map.put(key, value) is understood as a storage data form of key value mapping; the sessionKey is understood as a session key, which refers to a string or byte array generated by the server within a session and valid only in the session.
[0070] The dynamic construction and encryption processing described in the application, specifically, by operating a basic JSON request body template: for JsonKey / JsonValue, using a JSON library such as Jackson's put() method, updating or adding nodes to the request body according to the path, for example, according to the JSON path expression specified by JsonKey, using the node operation method of JSON, update or add the corresponding field value in the request body JSON.
[0071] Specifically, the dynamic construction of the request body also includes the following steps: traversing the ReqParam list, executing the test instructions, if an encryption instruction is encountered, calling the encryption and decryption algorithm factory, returning the corresponding tool instance according to the specified encryption and decryption algorithm, encrypting the original value of the specified field of the request body, and replacing the original value of the specified field with the ciphertext.
[0072] Specifically, the verification of the response data specifically includes the following steps: for the Expect_table header, the Expect_table header is converted into JSONPath, the table header value is extracted, and the table header value is compared with the expected value of the verification reference. If the table header value and the expected value are consistent, the verification is passed. For the Others column, the cell content of the Others column is parsed into a second key-value pair, and the second key-value pair is recursively searched in the response body. If the second key-value pair does not exist in the response body or the value of the second key-value pair does not match, the verification fails. For the AI_distinguishData_table header, the specified path value is extracted and stored and then sent to the AI agent. The evaluation conclusion is obtained through the AI agent.
[0073] It should be noted that the Expect_table header is understood as a pre-declared set of column name metadata considered correct. The Others column is understood as a column name of an expected value. The engine parses the content of the Others column into multiple key-value pairs, such as the Others column, whose cell content is in the form of AAA:aaa, BBB:bbb, and CCC:ccc. After parsing, the three key-value pairs are obtained, and each key is recursively searched in the entire response JSON. If the key does not exist or the value does not match, it is determined that the verification fails.
[0074] Specifically, the session context is updated, and the configuration trigger condition specifically includes configuring a rule based on S2 rule_config.json, that is, type:response_extractor, indicating that data needs to be extracted from the response JSON body, and the data is determined by the value corresponding to the key field:data.conversation_id. data.conversation_id represents the JSON node path, that is, AAA.BBB.CCC represents the path of the JSON body AAA:{BBB:{CCC:value}}, variable:conversation_id, indicating the node that needs to be replaced, default:, indicating that if the corresponding node is not found in the response JSON body, the default value is used, and lifecycle:persist, which indicates the declaration cycle, that is, the invalidation time of the above replacement rule.
[0075] The request body sends a request and receives a response, for example, using Apache HttpClient or Spring's RestTemplate, and finally constructs a JSON request body to send to the interface API URL in POST mode, synchronously receives the response, records the HTTP status code and the complete response body. The specific steps of processing the response, such as decryption: check the DecryptContent column of the use case, if the value is.data.token, read the value using JsonPath $.data.token, call the AES decryption algorithm to decrypt, and use the decrypted plaintext for subsequent verification. Expected value verification: for the table header Expect_data.intent, use JsonPath $.data.intent to extract the actual value, and perform string comparison with the value "flight_booking" in the use case.
[0076] Specifically, the S5 further includes AI agent collaborative verification: if the ExpectAI_.AAA table header is encountered, the value under the path $.AAA is sent to the AI agent, a semantic score is obtained through the AI agent, and a first score is obtained. Determine whether the first score is higher than the experience threshold, and then determine whether the verification passes or fails; if the cell value is Expect_prompt word, send the Expect_prompt word and the extracted prompt word value to the AI agent, and obtain a second score through the semantic score of the agent. Determine whether the second score is less than the preset threshold, if the second score is less than the preset threshold, determine that the verification fails; the AI agent returns the error type and error index of the verification failure.
[0077] For example, AI agent data extraction: for the table header AI_distinguishData.domain0.name, use JsonPath $.distinguishData.domain[0].name to extract the value "Model_Alpha", and store it in a temporary list, waiting to be sent to the AI; global verification Others, parse the content of the Others column "key1:value1;key2:value2", recursively search key1 and key2 in the entire response JSON, and compare their values.
[0078] The implementation of the cooperation of the AI agent, for example, check whether there is extracted AI data or ExpectAI_table header. If so, build a request body, call the AI intelligent service through HTTP, and the AI service returns a JSON format response: {"score": 0.85, "error_type": "domain_rewrite", "error_index": 2}. According to the score (0.85>0.8), it is determined that this check passes, but a warning is recorded according to the error type. Save the results of this round and update the session: all check results, AI scores, and error information of the current use case are summarized into a TestResult. Append the object to the rotationResults list of the SessionContext object, serialize the updated SessionContext object, write it back to Redis with the sessionKey as the key, and set a reasonable expiration time.
[0079] Specifically, the detection file change of the test case is found, and the specific steps include the following steps: triggering a timing task, establishing an SFTP connection with a cloud server, and listing.xlsx files in a specified directory; calculating the first MD5 value of the.xlsx file, querying the corresponding second MD5 value in the file_md5_collection collection of the database; if the first MD5 value and the second MD5 value are inconsistent, it is determined that the detection file is changed.
[0080] Specifically, the test case file is read and parsed, and the specific steps include the following steps: traversing the test case files to be processed in test_cases_collection, respectively reading the Group field and Rotation field in each row of the test case file, obtaining or generating a client MAC address, and then constructing a session key for a test session; when the value of the Group field is greater than 1 or the Rotation field contains multiple rounds, a co- prefix is added to the client MAC address; when the value of the Rotation field is 1 and there is no associated round, a test- prefix is added before the MAC address.
[0081] The implementation of the session management of the application, for example, uses the client MAC address, the Group and Rotation fields in the test case to generate a unique session key sessionKey. The key is used to obtain or create a SessionContext object in the memory or Redis, which stores all the states of the session, such as persistent variables, the current round result, and the historical result list. By generating a client MAC address, simulating a unique device, combining the Group field in the test case data to define the test group and the Rotation field to define the round within the group, a unique session key is generated through string splicing, such as: MACAddress+“-”+groupid, which is used to identify a test session.
[0082] There are two implementation methods: one is to create a new session. If the Redis does not exist the data corresponding to the key, the system immediately creates a new SessionContext object. The initialization of the object includes: an empty List <testresult>rotationResults, for storing all the test results of all the rounds of the current session in order. Rotation is 5, so there are 5 results. A Map<String, Object> extractVariables, for storing the variables that need to be persisted in the current session lifecycle, such as conversation_id. Two, get the existing session. If there is data corresponding to the key in Redis, the system will deserialize the stored data, such as a JSON string, and rebuild a complete SessionContext object in memory, which contains all the historical results of the rounds and the variables that have been persisted. The state identifier, all the states of a session are completely represented by the instance of the SessionContext object in memory. It contains the historical track, such as the rotationResults list records the detailed test results of the executed rounds. The current context, the extractedVariables mapping table records the dynamic variable values accumulated in the session so far, which can be used to construct the next round of requests.
[0083] Specifically, S6 further includes the following steps: generating a test report: traversing the SessionContext object in Redis, according to the Rotation field, sorting the rotationResults list of each session, generating a coherent multi-round test report for each session key sessionKey, forming a final test report; storing and outputting the final test report; cleaning up expired session contexts in the database.
[0084] The final report is generated, for example, result aggregation: the system traverses all related SessionContext in the Redis database, for example, the key pattern*_G1, sorts the rotationResults list of each session according to the Rotation number. A coherent multi-round test report will be generated for each sessionKey, that is, a set of tests for each simulated user. The report clearly shows the input, output, verification result and context passing of each round. The report is stored and output, and the final report is stored in the test_reports_collection collection of MongoDB. At the same time, the system can notify the user by email or push the report to the specified API. Resource cleaning: clean up expired session contexts in Redis and release resources.
[0085] The data processing method described in the application includes data cleaning and configuration rules, and is applied to API interface testing, as shown in Figure 5 , which can clean and process the data in API interface testing.
[0086] Embodiment 2
[0087] Based on embodiment 1, referring to Figure 2 and Figure 3 The embodiment discloses an API interface test data processing device for realizing the API interface test data processing method as described in embodiment 1, comprising a test case monitoring module, a database, a rule configuration module, a data cleaning engine, a request client, a response processing engine and a session management module; the test case monitoring module is used for monitoring a test case file of the cloud server; the rule configuration module is used for configuring dynamic rules; the data cleaning engine is used for reading and analyzing the test case file and dynamically constructing a request body; the request client is used for sending a request and accepting returned response data; the response processing engine is used for receiving and decrypting response data, extracting values and checking.
[0088] Embodiment 3
[0089] Based on embodiment 1, the embodiment discloses a computer readable medium having a computer program stored thereon, the computer program being executed by a processor to realize the API interface test data processing method as described in embodiment 1.
[0090] The file_extractor rule of the application is used for establishing a data mapping channel between the test case file and the request body, and declaring that values are extracted from specified columns field of the current test case row and filled into specified positions variable; the random_generator rule is used for generating random values for specified variables of the request body; the response_extractor rule is used for declaring that specified path values are extracted from a previous response body of the same session, and the specified path values are stored in the context of the current session;
[0091] Specifically, the implementation steps of dynamically constructing the request body include: operating a basic JSON request body template; for JsonKey / JsonValue, using the put() method of the JSON library (such as Jackson) to update or add nodes to the request body according to the path, that is, using the node operation method of JSON to update or add corresponding field values in the request body JSON according to the JSON path expression specified by JsonKey.
[0092] The above only describes the preferred embodiments of the application and is not used to limit the application, and any modification, equivalent replacement and improvement made within the spirit and principle of the application should be included in the protection scope of the application.< / testresult>
Claims
1. An API interface test data processing method, characterized by, The method comprises the following steps: S1, updating test case data: setting a timing task, monitoring the test case file of the cloud server, finding the detection file change of the test case, automatically downloading the new detection file, and parsing and storing it to the database; S2, configuring dynamic rules: predefining the variables_body rules of the request body configuration parameters in the JSON configuration file as dynamic rules, and loading the variables_body rules from the JSON configuration file; the configuration parameters include business parameters, dynamically extracted input values, simulation data, and session state values; the variables_body rules include: file_extractor rules, random_generator rules, and response_extractor rules; S3, reading and parsing the test case file through the data cleaning engine; dynamically constructing the request body according to the dynamic rules and the instructions of the test case file; S4, sending the request body to the API interface to be tested through the request client, and synchronously receiving the response body returned; S5, receiving the response body and dynamically decrypting through the response processing engine; extracting the response data of the response body, and verifying the response data according to the verification benchmark of the test case file; Updating the session context: taking the specified path value in the dynamic rule as JSONPath to extract the target value from the current response body; obtaining a SessionContext object of the current session, which includes a first key-value pair and a mapping list; taking the specified position variable as the key and the specified path value of the response body as the value to form the first key-value pair; storing the first key-value pair in the mapping list by performing the Map.put(key, value) operation, thereby updating the SessionContext object; and saving the updated SessionContext object again with sessionKey as the key. S6, session management: using the client MAC address, Group, and Rotation fields in the test case to generate a session key sessionKey; the session key sessionKey is used to obtain or create a SessionContext object, and then bind multiple rounds of sessions.
2. The API interface test data processing method of claim 1, wherein, The dynamic construction of the request body further comprises the following steps: Iterating the ReqParam list, executing the test instructions, and if an encryption instruction is encountered, calling an encryption algorithm factory to return a corresponding tool instance according to the specified encryption algorithm, encrypting the original value of the specified field of the request body, and replacing the original value of the specified field with the ciphertext.
3. The API interface test data processing method of claim 1, wherein, The verification of the response data specifically comprises the following steps: For the Expect_ header, the Expect_ header is converted into JSONPath, the header value is extracted, and the header value is compared with the expected value of the verification benchmark. If the header value and the expected value are consistent, the verification passes. For the Others column, the cell content of the Others column is parsed into a second key-value pair, and the second key-value pair is recursively searched in the response body. If the second key-value pair does not exist in the response body or the value of the second key-value pair does not match, the verification fails. For the AI_distinguishData_ header, the specified path value is extracted and stored before being sent to the AI agent. The evaluation conclusion is obtained through the AI agent.
4. The API interface test data processing method of claim 1, wherein, The S5 further includes AI agent collaborative verification: If the ExpectAI_.AAA header is encountered, the value under the path $.AAA is sent to the AI agent, and a first score is obtained through semantic scoring by the AI agent. It is determined whether the first score is higher than an experience threshold, and then it is determined whether the verification passes or fails. If the cell value is an Expect_ prompt word, the Expect_ prompt word and the extracted prompt word value are sent to the AI agent, and a second score is obtained through semantic scoring by the AI agent. It is determined whether the second score is less than a preset threshold. If the second score is less than the preset threshold, it is determined that the verification fails. The AI agent returns the error type and error index of the failed verification.
5. The API interface test data processing method according to any one of claims 1-4, characterized in that, The detection file change of the test case is found, including the following steps: A timing task is triggered to establish an SFTP connection with a cloud server, list.xlsx files in a specified directory, calculate a first MD5 value of the.xlsx files, query a second MD5 value corresponding to the file_md5_collection collection in the database, and determine that the detection file has changed if the first MD5 value and the second MD5 value are inconsistent.
6. The API interface test data processing method according to any one of claims 1-4, characterized in that, The test case file is read and parsed, including the following steps: The test case files in the test_cases_collection collection are iterated to read the Group field and the Rotation field in each row of the test case file, obtain or generate a client MAC address, and then build a session key for a test session. When the value of the Group field is greater than 1 or the Rotation field contains multiple rounds, a co- prefix is added to the client MAC address. When the value of the Rotation field is 1 and there is no associated round, a test- prefix is added to the MAC address.
7. The API interface test data processing method according to any one of claims 1-4, characterized by, The S6 further includes the following steps: A test report is generated: the SessionContext objects in Redis are iterated, the rotationResults list of each session is sorted according to the Rotation field, a coherent multi-round test report is generated for each session key sessionKey, and a final test report is formed; The final test report is stored and output, and expired session contexts in the database are cleaned up.
8. An API interface test data processing apparatus characterized by comprising: The application discloses an API interface test data processing method and a computer program product.
9. A computer readable medium having stored thereon a computer program, characterized in that The computer program is executed by a processor to realize the API interface test data processing method.