Demand-protocol double-constraint test case generation method based on large model

By using a large-model-based requirement-protocol dual-constraint test case generation method, the problems of low efficiency, insufficient coverage, and maintenance difficulties in control software testing are solved. The method generates directly usable, structured test cases, thereby improving testing efficiency and result consistency.

CN121597576APending Publication Date: 2026-03-03CHONGQING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511757910.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-27
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies are inefficient, costly, have insufficient coverage, rely heavily on experience, and are difficult to maintain across versions in control software testing. Furthermore, existing automated test case generation methods fail to effectively integrate with communication protocols, resulting in test cases that cannot be directly executed or distributed.

Method used

A demand-protocol dual-constraint test case generation method based on a large model is adopted. By constructing a structured protocol knowledge base and a preliminary test case set, protocol dependency labeling and hierarchical retrieval are performed in combination with the large model. Protocol-related fields are supplemented by a few-shot learning method to generate the final test case set.

Benefits of technology

It enables the generation of complete and directly usable test cases without human intervention, improving the completeness, accuracy, and maintainability of test cases, reducing the need for manual interpretation and secondary conversion, and allowing the results to be directly integrated into the testing platform for easy version management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597576A_ABST
    Figure CN121597576A_ABST
Patent Text Reader

Abstract

The invention discloses a demand-protocol double-constraint test case generation method based on a large model. The method comprises the following steps: performing structured modeling on a system communication protocol document and a software demand specification document to respectively generate a structured protocol knowledge base and a structured test case set marked with protocol dependencies; executing hierarchical semantic retrieval based on semantic similarity of protocol dependencies and protocol fields, and obtaining a candidate set through name layer matching, information name layer refining and cross-layer fusion strategies; and organizing the test case with the protocol dependency item, the corresponding instruction candidate set, the few-sample sample and the guide prompt word into a unified input template, inputting a large model to execute protocol field completion, and outputting a structured test case set. The invention provides a joint generation mechanism for carrying out data item binding on the two documents, so that the generated use case has performability, and a result is output by adopting a standardized JSON or equivalent key value structure and can be directly accessed to a test platform or a use case library.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software testing technology, and specifically to a method for automatically generating test cases by combining a Large Language Model (LLM) with software requirements specifications and communication protocol documents. Background Technology

[0002] Software testing is a crucial means of ensuring the correctness and reliability of software functions, directly impacting system security and availability. In control-related software scenarios (such as position control, vehicle chassis control, and robotic arm control), testing activities not only need to verify functional flows but also require strict alignment with communication protocols (instruction sets, frame structures, bit field definitions, value ranges, units, and resolutions) to ensure that software behavior and data interaction between the controlled object conform to the agreed-upon protocols.

[0003] Currently, the testing of control software still largely relies on manually writing test cases, which commonly presents the following problems:

[0004] 1. Low efficiency and high cost: The transformation from requirements to use cases relies on manual sorting and protocol comparison, which is time-consuming and difficult to scale.

[0005] 2. Insufficient coverage: Complex protocols have numerous combinations of enumerated values / bit fields, making it easy for manual intervention to overlook boundary conditions and abnormal combinations;

[0006] 3. High reliance on experience: Testers need to possess domain knowledge and protocol understanding, and results may vary between different personnel.

[0007] 4. Difficulty in maintaining across versions: After the protocol or requirements change, a large number of use cases need to be manually traced back and updated, which can easily introduce inconsistencies.

[0008] Meanwhile, existing automated test case generation methods mostly rely on the software requirements specification as a single information source. The generated results often remain at the level of "test logic / step description," failing to establish binding and constraints between test cases and the communication protocol, a crucial data carrier. The direct consequence is that test cases cannot be directly executed or deployed, requiring manual mapping of the logic to specific protocol fields and values, making it difficult to meet the actual testing needs of control software.

[0009] Therefore, the industry urgently needs an automatic generation solution that can simultaneously utilize requirement semantics and communication protocol information to achieve semantic alignment and structured constraints between the two, so as to improve the completeness, accuracy and maintainability of test cases without the need for a large number of manual rules and examples. Summary of the Invention

[0010] In view of the above-mentioned technical problems in the background art, the technical problem to be solved by the present invention is: how to automatically obtain complete and directly usable test cases without human intervention.

[0011] To solve the above technical problems, the present invention adopts the following technical solution: a method for generating test cases based on a large model's requirement-protocol dual constraints, comprising the following steps:

[0012] S1: Extract each instruction unit from the system communication protocol document according to the title hierarchy, and build a structured protocol knowledge base K with the help of a large model; extract each functional unit from the software requirements specification document according to the title hierarchy, and generate a structured preliminary test case set T0 with the help of a large model.

[0013] S2: Based on the structured protocol knowledge base K and the structured preliminary test case set T0, the protocol dependencies of each preliminary test case in T0 are marked with a large model to obtain the structured test case set T1 after the protocol dependencies are marked.

[0014] S3: Based on the protocol dependencies in T1, perform hierarchical retrieval of the structured protocol knowledge entries e in K, and output the instruction candidate set C corresponding to each test case.

[0015] S4: Input each test case in T1 and its corresponding instruction candidate set into the large model in sequence, and use few-shot learning to complete the protocol-related fields to generate the final test case set T.

[0016] As an improvement, the process of constructing the structured protocol knowledge base K in step S1 includes: segmenting the system communication protocol document according to the title hierarchy, automatically identifying the title boundaries based on regular expression matching and document hierarchy features, and using the title and its sub-content of the specified level as the segmentation unit, with each segmentation unit corresponding to an instruction unit; constructing protocol structured prompt words, and sequentially using each instruction unit as the input of the large model, the large model extracts the name, data type, information definition and remarks of each instruction unit according to the protocol structured prompt words, generating the corresponding structured protocol knowledge entry e, and finally summarizing all e to obtain K.

[0017] The process of generating a preliminary test case set in step S1 includes: segmenting the software requirements specification document according to the title hierarchy; automatically identifying title boundaries based on regular expression matching and document hierarchy features; using the title and its sub-content of a specified level as the segmentation unit, with each segmentation unit corresponding to a functional unit; constructing test case generation prompts; sequentially using each functional unit as input to the large model; the large model generating structured preliminary test cases corresponding to each functional unit based on the test case generation prompts; and finally summarizing all structured preliminary test cases to form T0.

[0018] As an improvement, the process of obtaining the structured test case set T1 after marking protocol dependencies in step S2 includes: extracting the names of each e and the information names in their information definitions from K to construct an annotation example set; constructing protocol dependency marking prompts; sequentially using each preliminary test case in T0 and the annotation example set as input to the large model; and using the protocol dependency marking prompts to uniformly mark the content in the preliminary test cases that has semantic equivalence, approximation, or correlation with the annotation example set, thereby obtaining the preliminary test case set T1 after marking protocol dependencies.

[0019] As an improvement, the process of obtaining the instruction candidate set C in step S3 includes:

[0020] S31: The protocol dependency is used as the query vector q, which, together with e in K, is input into the embedding model and mapped to the unified semantic space.

[0021] S32: Perform the first-level name matching, calculate the similarity s1(e) of the "name" field between q and e, and perform stratified determination. Use the retention mechanism to obtain the first-level preliminary candidate set C1 and the first-level candidate set. This is the result of the first-level name-level matching.

[0022] The second-level information name layer refined matching is performed. Semantic similarity is calculated for each "information name / field name" of the candidate entries in the name layer, and a hierarchical judgment is made. A retention mechanism is used to obtain the preliminary candidate set C2 and the second-level candidate set. This serves as the matching result for the second-level name layer matching.

[0023] If the protocol entries exist at deeper levels, then in τ low l (e)<τ high In the case of iteratively performing hierarchical determination, a retention mechanism is then used to obtain the initial candidate set C of the l-th layer. l and the initial candidate set of layer l Until the early stopping condition is met or the deepest layer is reached, s l (e) represents the similarity at the l-th layer. This is the matching result of the name layer matching at the l-th level.

[0024] S33: Integrate the matching results of S32 through a cross-level decision-making strategy to obtain the final candidate set C and output it in sorted order.

[0025] As an improvement, the mathematical definition of the hierarchical determination in S3 is as follows:

[0026] The feature mapping of the l-th layer is f l (e), l = 1, 2, ..., L, similarity s l ​(e) is defined as:

[0027] s l (e) = sim(q, f l (e)) ∈ [0, 1]

[0028] where e ∈ K;

[0029] Let the upper and lower thresholds be τ high > τ low , and define the level decision function δ l (e):

[0030]

[0031] When δ l (e) = ACCEPT, stop early; when δ l (e) = REJECT, discard, when δ l (e) = CANDIDATE, go to the next level for refinement.

[0032] As an improvement, the retention mechanism in S3 is:

[0033] Let i < l, the preliminary candidate set C i at the i-th layer is:

[0034] C i = {e ∈ K | τ low <s i (e) < τ high}},

[0035] The candidate set at the i-th layer is:

[0036]

[0037] where represents sorting the candidate set C i according to the similarity threshold s i (e), and selecting the top k i samples with the highest similarity. The (i + 1)-th layer calculates s (e) on i+1 and makes a decision. Similarly, we get:

[0038]

[0039] where τ low , τ high respectively represent the upper and lower limits of the similarity threshold,

[0040] As an improvement, the cross-layer decision-making strategy in S33 includes:

[0041] Fusion scoring method: When the multi-level matching results are in the uncertainty interval (τ) low l (e)<τ high When calculating the weighted fusion score:

[0042]

[0043] Where α, β, γ, and x are all adjustable weighting coefficients, if If it is determined to be a match, then... Merge as C; The case is determined to be unmatched; otherwise, s will be... l (e), l=1,2,…,L, the first m e corresponding to it are taken as C.

[0044] As an improvement, the process of generating the final test case set T in step S4 includes: constructing protocol field completion prompts; taking each test case in T1 and its corresponding instruction candidate set C as input to the large model; under the constraints of the protocol field completion prompts, the large model completes the missing protocol fields in the test cases, generating corresponding descriptions of missing fields, parameters, or data content, and obtaining the final test case set T; wherein, the protocol field completion prompts are used to indicate the goal and scope of the generation task, constrain the format and hierarchy of the generated content, and emphasize the rationality of semantics and values; the protocol field completion prompts also include few-sample examples, which consist of predefined test cases, their corresponding instruction candidate set C′, and the completed test cases T′.

[0045] Compared with the prior art, the present invention has at least the following beneficial effects: (Very important, please provide detailed information.)

[0046] 1. This invention simultaneously performs structured modeling of the software requirements specification document and the system communication protocol document, and limits the test content from the perspective of requirement semantics and protocol constraints, so that the generated test cases are more in line with the actual test scenarios in terms of semantics and content, thereby improving the usability and engineering adaptability of the results.

[0047] 2. Compared with methods based on full-text retrieval or simple similarity matching, this invention introduces a large-model semantic alignment mechanism, and combines hierarchical similarity judgment, threshold screening and retention mechanisms to refine the protocol entries layer by layer, making the final set of instruction candidate sets more semantically accurate and improving the accuracy and reliability of the retrieval results.

[0048] ​3. This invention inputs test cases marked with protocol dependencies and corresponding instruction candidate sets into a large model. Under hint constraints, it automatically completes the protocol-related fields and their meanings, transforming the generated results from merely describing test logic into structured test cases containing explicit protocol elements. This process reduces the need for manual interpretation and secondary conversion, improving generation efficiency while enhancing the consistency and standardization of result expression. Furthermore, the generated results are output using standardized JSON or equivalent key-value structures, allowing direct integration into testing platforms or test case libraries, facilitating version management and cross-system integration. Attached Figure Description

[0049] Figure 1 This is a sample diagram of the system communication protocol document.

[0050] Figure 2(a) is an example diagram of a structured protocol knowledge base, Figure 2(b) is an example diagram of a structured protocol knowledge base, and Figure 2(c) is an example diagram of a structured protocol knowledge base.

[0051] Figure 3(a) is an example of a software requirements specification document, and Figure 3(b) is an example of a software requirements specification document.

[0052] Figure 4(a) shows a preliminary test case diagram, Figure 4(b) shows a preliminary test case diagram, Figure 4(c) shows a preliminary test case diagram, and Figure 4(d) shows a preliminary test case diagram.

[0053] Figure 5(a) is a schematic diagram of test cases after marking protocol dependencies, and Figure 5(b) is a schematic diagram of test cases after marking protocol dependencies.

[0054] Figure 6(a) shows an example of an entry retrieved based on protocol dependencies, and Figure 6(b) shows an example of an entry retrieved based on protocol dependencies.

[0055] Figure 7(a) is a schematic diagram of the final completed test cases, and Figure 7(b) is a schematic diagram of the final completed test cases. Detailed Implementation

[0056] This invention provides a method for generating test cases based on a large model of requirements and protocols with dual constraints. By leveraging the large model, cross-document semantic alignment and structured constraint generation of software requirements specifications and communication protocol documents can be achieved without manual intervention, automatically generating complete and directly usable test cases.

[0057] A method for generating test cases based on a large model's requirement-protocol dual constraints includes the following steps:

[0058] S1: Extract each instruction unit from the system communication protocol document according to the title hierarchy, and build a structured protocol knowledge base K with the help of a large model; extract each functional unit from the software requirements specification document according to the title hierarchy, and generate a structured preliminary test case set T0 with the help of a large model.

[0059] S2: Based on the structured protocol knowledge base K and the structured preliminary test case set T0, the protocol dependencies of each preliminary test case in T0 are marked with a large model to obtain the structured test case set T1 after the protocol dependencies are marked.

[0060] S3: Based on the protocol dependencies in T1, perform hierarchical retrieval of the structured protocol knowledge entries e in K, and output the instruction candidate set C corresponding to each test case.

[0061] S4: Input each test case in T1 and its corresponding instruction candidate set into the large model in sequence, and use few-shot learning to complete the protocol-related fields to generate the final test case set T.

[0062] Specifically, the process of constructing the structured protocol knowledge base K in step S1 includes:

[0063] The system communication protocol document is segmented according to the title hierarchy. Title boundaries are automatically identified based on regular expression matching and document hierarchy features. The title and its sub-content of the specified level are used as the segmentation unit, and each segmentation unit corresponds to an instruction unit. The protocol structure prompt words are constructed. Each instruction unit is used as the input of the large model. The large model extracts the name, data type, information definition (information definition includes information name, data location, data definition) and remarks of each instruction unit according to the protocol structure prompt words, and generates the corresponding structured protocol knowledge item e. Finally, all e are summarized to obtain K.

[0064] The process of generating the preliminary test case set in step S1 includes:

[0065] The software requirements specification document is segmented according to the title hierarchy. Title boundaries are automatically identified based on regular expression matching and document hierarchy features. The title and its sub-content at the specified level are used as the segmentation unit, and each segmentation unit corresponds to a functional unit. Test cases are generated to generate prompts. Each functional unit is used as input to the large model. The large model generates structured preliminary test cases for each functional unit based on the test case prompts. Finally, all structured preliminary test cases are summarized to form T0.

[0066] Specifically, the heading hierarchy should prioritize lower heading levels (H3 / H4); the original order and context of tables, lists, and explanatory text should be preserved during segmentation; the main text and table content under each segment should be extracted as the smallest functional unit; preliminary test cases should be in natural language form (JSON) or an equivalent key-value class structure, with each data entry containing one preliminary test case; the preliminary test case fields should at least include the test case name, test case identifier, tracing relationship, prerequisites and constraints, input and step descriptions (including input data and test steps), and expected results (including post-execution status or output description); protocol dependencies should be indicated using markers such as "【】". The structured protocol knowledge entries should be in JSON or equivalent key-value format, with each entry containing complete protocol information. Each structured protocol knowledge entry should at least include: name (protocol item or command name), data type, information definition, and remarks (optional, used to supplement protocol fields). The information definition should at least include: information name, data location (byte number, bit number, or a combination thereof, such as "B0", "b5b4", etc.), data definition (enumerated values ​​or numerical range, such as "00 = invalid", "01 = GPS powered on", "0~36.00"), and unit and resolution (for numeric types, such as "V", "0.01").

[0067] Specifically, the process of obtaining the structured test case set T1 after marking the protocol dependencies in step S2 includes:

[0068] Extract the names of each e from K and the information names in their information definitions to construct an annotated example set; construct protocol dependency tag prompts, and take each preliminary test case in T0 and the annotated example set as input to the large model in turn. The large model uniformly tags the content in the preliminary test cases that has semantic equivalence, approximation, or correlation with the annotated example set according to the protocol dependency tag prompts, and obtains the preliminary test case set T1 after tagging protocol dependencies.

[0069] Specifically, the process of obtaining the instruction candidate set C in step S3 includes:

[0070] S31: Using protocol dependencies as query vectors q, and inputting them together with e in K into the embedding model, mapping them to a unified semantic space;

[0071] S32: Perform the first-level name matching, calculate the similarity s1(e) of the "name" field between q and e, and perform stratified determination. Use the retention mechanism to obtain the first-level preliminary candidate set C1 and the first-level candidate set. This is the result of the first-level name-level matching.

[0072] Perform the refinement matching of the second-layer information name layer, calculate the semantic similarity item by item for the "information name / field name" of the candidate entries in the name layer, and perform hierarchical determination. Adopt the retention mechanism to obtain the first-layer preliminary candidate set C2 and the second-layer candidate set As the matching result of the second-layer name layer matching.

[0073] If there are deeper levels (including but not limited to sub-fields, status flags, or parameter sub-items) in the protocol entry, then at τ low <s l (e) < τ high Iteratively perform hierarchical determination, and then adopt the retention mechanism to obtain the l-th layer preliminary candidate set C l and the l-th layer preliminary candidate set Until the early stopping condition is met or the deepest layer is reached, s l (e) represents the similarity of the l-th layer, As the matching result of the l-th layer name layer matching.

[0074] S33: Integrate the matching results of S32 through the cross-layer decision-making strategy to obtain the final candidate set C and sort and output it.

[0075] Specifically, the mathematical definition of the hierarchical determination in S3 is as follows:

[0076] The l-th layer feature mapping is f l (e), l = 1, 2,..., L, and the similarity s l (e) is defined as:

[0077] s l (e) = sim(q, f l (e)) ∈ [0, 1]

[0078] where e ∈ K;

[0079] Let the upper and lower thresholds be τ high > τ low , define the hierarchical determination function δ l (e):

[0080]

[0081] When δ l (e) = ACCEPT, stop early; when δ l (e) = REJECT, discard it, and when δ l (e) = CANDIDATE, enter the next layer for refinement.

[0082] Specifically, the retention mechanism in S3 is:

[0083] Let i < l, the i-th layer preliminary candidate set C ifor:

[0084] C i ={e∈K|τ low i (e)<τ high},

[0085] Candidate set of level i for:

[0086]

[0087] in This indicates that based on the similarity threshold s i (e) For candidate set C i Sort the data and select the top k with the highest similarity. i For each sample, the (i+1)th layer is... Calculate s i+1 (e) And determine, similarly we get:

[0088]

[0089] Where, τ low ,τ high These represent the upper and lower limits of the similarity threshold, respectively.

[0090] Specifically, the cross-layer decision-making strategy in S33 includes:

[0091] Fusion scoring method: When the multi-level matching results are in the uncertainty interval (τ) low l (e)<τ high When calculating the weighted fusion score:

[0092]

[0093] Where α, β, γ, and x are all adjustable weighting coefficients, if If it is determined to be a match, then... Merge as C; The case is determined to be unmatched; otherwise, s will be... l (e), l=1,2,…,L, the first m e corresponding to it are taken as C.

[0094] Specifically, the process of generating the final test case set T in step S4 includes:

[0095] ​​A protocol field completion prompt is constructed. Each test case in T1 and its corresponding instruction candidate set C are used as input to the large model. Under the constraints of the protocol field completion prompt, the large model completes the missing protocol fields in the test cases, generating corresponding descriptions of missing fields, parameters, or data content, resulting in the final test case set T. The protocol field completion prompt is used to indicate the goal and scope of the generation task, constrain the format and hierarchy of the generated content, and emphasize the rationality of semantics and values. The protocol field completion prompt also includes few-sample examples, which consist of a predefined test case, its corresponding instruction candidate set C′, and the completed test case T′.

[0096] Specifically, the various prompt words described in this invention include:

[0097] The prompts appeared a total of four times: ① Protocol structure prompts, ② Test case generation prompts, ③ Protocol dependency marking prompts, and ④ Protocol field completion prompts.

[0098] Protocol structure prompts guide large language models to generate structured protocol knowledge entries based on input instruction units. Their main function is to define the generation task, standardize the output format, and constrain the content scope. These prompts include the following core elements:

[0099] (1) Role and task setting: By defining the role of the model, it is clear that it completes the protocol structuring task as a "protocol structuring assistant";

[0100] (2) Structured output constraints: The model is required to output results according to a predefined JSON or equivalent key-value structure, and include fixed fields such as name, data type, information definition, and remarks;

[0101] (3) Format legality constraints: It is emphasized that the output content must conform to the standard JSON or equivalent key-value structure syntax specifications, and there must be no extra symbols, missing fields or placeholder content.

[0102] Test case generation prompts guide the large language model to generate structured preliminary test cases based on the input functional units. Their main function is to define the generation task, standardize the output format, and constrain the content scope. These prompts contain the following core elements:

[0103] (1) Role and task setting: By defining the role of the model, it is clear that it completes the task of generating test cases as a "software test case generation expert";

[0104] (2) Structured output constraints: The model is required to output results according to a predefined JSON or equivalent key-value structure, and include fixed fields such as use case name, use case identifier, tracing relationship, premise and constraint, input and step description, and expected result. When there are multiple use cases, they are uniformly encapsulated in the form of an array.

[0105] (3) Step completeness requirement: The test process must be described in step form to ensure that the operation process and expected results are expressed completely and clearly;

[0106] (4) Format legality constraints: It is emphasized that the output content must conform to the standard JSON or equivalent key-value structure syntax specifications, and there must be no extra symbols, missing fields or placeholder content.

[0107] Protocol dependency tagging prompts guide the large language model to automatically identify and uniformly tag communication protocol-related content in initial test cases. Their main function is to establish a semantic connection between test cases and protocol knowledge, providing a basis for subsequent instruction candidate set retrieval. These prompts primarily contain the following core elements:

[0108] (1) Tagging task setting: The model is required to analyze the "input and step description" content in the test cases, identify the fields, instructions, data definitions or operation behaviors related to the protocol, and complete the corresponding tagging;

[0109] (2) Reference information constraint: Provide the model with a set of labeled examples extracted from the protocol knowledge base as a reference set, requiring the model to only label content that has semantic equivalence, approximation or relevance to this set, so as to avoid irrelevant information being incorrectly labeled and prevent information omission;

[0110] (3) Comprehensiveness and consistency constraints: All relevant content that meets the conditions in the test cases must be fully labeled to avoid omissions or only partial labeling, so as to ensure the integrity and stability of the subsequent retrieval and matching process.

[0111] Protocol field completion prompts guide the large language model to complete missing or incomplete protocol-related field information based on test cases with tagged protocol dependencies and the corresponding instruction candidate set. Its main function is to further transform test logic into structured test cases containing protocol elements. These prompts primarily include the following core elements:

[0112] (1) Role and task setting: By defining the role of the model, it is clear that the model is a "test engineer". Based on the initial test cases, combined with the protocol candidate set, the fields, data content or status descriptions related to the communication protocol in the test cases are completed.

[0113] (2) Semantic and field consistency requirements: It is emphasized that the completion process must strictly match the field definition, bit meaning description and semantic information in the instruction candidate set to ensure that the completed content is semantically consistent with the protocol definition and avoid ambiguous expressions or field descriptions that are inconsistent with the protocol.

[0114] (3) Structured output constraints: The completed results are required to maintain the same structure and format as the original test cases. Only the protocol fields and their meanings are added in the corresponding positions to ensure that the final test cases are structurally complete and standardized, which is convenient for subsequent use.

[0115] (4) Few Sample Constraints: A small number of known samples are introduced into the prompt words. The samples consist of pre-constructed preliminary test cases, corresponding instruction candidate sets, and completed standard results. They are used to demonstrate the way, granularity, and writing style of completing protocol fields to the model, thereby guiding the model to generate completed results with consistent style and structure.

[0116] Example: Figure 1 This is an example of a communication protocol document for a control software system. The structured protocol knowledge base example obtained through S1 protocol processing (the selected header level here is instruction header level H3) is as follows: Figure 2(a) , 2(b) As shown in 2(c); Figure 3(a) , 3(b) This is an example of a processed software requirements specification document for a control software, with preliminary test cases (partial) obtained through S1 structured modeling, as shown below. Figure 4(a) , 4(b) As shown in 4(c) and 4(d); structured testing after S2 tagging protocol dependencies is used for example... Figure 5(a) , 5(b) As shown, the instruction candidate set obtained after retrieving protocol dependencies via S3 is as follows: Figure 6(a) , 6(b) As shown; finally, after completion by S4, the test is used for example. Figure 7(a) , 7(b) As shown.

Claims

1. A method for generating test cases based on a large model's requirement-protocol dual constraints, characterized in that, Includes the following steps: S1: Extract each instruction unit from the system communication protocol document according to the title hierarchy, and build a structured protocol knowledge base K with the help of a large model; extract each functional unit from the software requirements specification document according to the title hierarchy, and generate a structured preliminary test case set T0 with the help of a large model; S2: Based on the structured protocol knowledge base K and the structured preliminary test case set T0, the protocol dependencies of each preliminary test case in T0 are marked with a large model to obtain the structured test case set T1 after the protocol dependencies are marked. S3: Based on the protocol dependencies in T1, perform hierarchical retrieval of the structured protocol knowledge entries e in K, and output the instruction candidate set C corresponding to each test case; S4: Input each test case in T1 and its corresponding instruction candidate set into the large model in sequence, and use few-shot learning to complete the protocol-related fields to generate the final test case set T.

2. The method for generating test cases based on a large model and dual constraints of requirements and protocols as described in claim 1, characterized in that, The process of constructing the structured protocol knowledge base K in step S1 includes: The system communication protocol document is segmented according to the title hierarchy. Title boundaries are automatically identified based on regular expression matching and document hierarchy features. The title and its sub-content of the specified level are used as the segmentation unit, and each segmentation unit corresponds to an instruction unit. The protocol structure prompt words are constructed. Each instruction unit is used as the input of the large model. The large model extracts the name, data type, information definition and remarks of each instruction unit according to the protocol structure prompt words, and generates the corresponding structured protocol knowledge item e. Finally, all e are summarized to obtain K. The process of generating the preliminary test case set in step S1 includes: The software requirements specification document is segmented according to the title hierarchy. Title boundaries are automatically identified based on regular expression matching and document hierarchy features. The title and its sub-content at the specified level are used as the segmentation unit, and each segmentation unit corresponds to a functional unit. Test cases are generated to generate prompts. Each functional unit is used as input to the large model. The large model generates structured preliminary test cases for each functional unit based on the test case prompts. Finally, all structured preliminary test cases are summarized to form T0.

3. A method for generating test cases based on a large model and dual constraints of requirements and protocols, as described in claim 1 or 2, is characterized in that... The process of obtaining the structured test case set T1 after marking the protocol dependencies in step S2 includes: Extract the names of each e from K and the information names in their information definitions to construct an annotated example set; construct protocol dependency tag prompts, and take each preliminary test case in T0 and the annotated example set as input to the large model in turn. The large model uniformly tags the content in the preliminary test cases that has semantic equivalence, approximation, or correlation with the annotated example set according to the protocol dependency tag prompts, and obtains the preliminary test case set T1 after tagging protocol dependencies.

4. The method for generating test cases based on a large model and dual constraints of requirements and protocols as described in claim 3, characterized in that, The process of obtaining the instruction candidate set C in step S3 includes: S31: Using protocol dependencies as query vectors q, and inputting them together with e in K into the embedding model, mapping them to a unified semantic space; S32: Perform the first-level name matching, calculate the similarity s1(e) of the "name" field between q and e, and make a layer-by-layer determination. The first preliminary candidate set C1 and the first-level candidate set are obtained by using a retention mechanism. As the matching result of the first level of name layer matching; The second-level information name layer refined matching is performed. Semantic similarity is calculated for each "information name / field name" of the candidate entries in the name layer, and a hierarchical judgment is made. A retention mechanism is used to obtain the preliminary candidate set C2 and the second-level candidate set. As the matching result of the second-level name layer matching; If the protocol entries exist at deeper levels, then in τ low l (e)<τ high In the case of iteratively performing hierarchical determination, a retention mechanism is then used to obtain the initial candidate set C of the l-th layer. l and the initial candidate set of layer l Until the early stopping condition is met or the deepest layer is reached, s l (e) represents the similarity at the l-th layer. As the matching result of the name layer matching at level l;​ S33: Integrate the matching results of S32 through a cross-level decision-making strategy to obtain the final candidate set C and output it in sorted order.

5. The method for generating test cases based on a large model and dual constraints of requirements and protocols according to claim 4, characterized in that, The mathematical definition of the stratification determination in S3 is as follows: The feature mapping of the l-th layer is f l (e), l = 1, 2, ..., L, similarity s l (e) is defined as: s l (e) = yes(q,f l (e))∈[0,1] Where e∈K; Let the upper and lower thresholds be τ. high >τ low Define the hierarchical decision function δ l (e): When δ l (e) = ACCEPT, early stop; when δ l Discard when (e) = REJECT, when δ l When (e) = CANDIDATE, proceed to the next level of refinement.

6. The method for generating test cases based on a large model and dual constraints of requirements and protocols according to claim 5, characterized in that, The retention mechanism in S3 is as follows: Let \(i < l\), the initial candidate set \(C\) of the \(i\)-th layer i is C i ={e∈K|τ low i (e)<τ high },​ Candidate set of level i for: in This indicates that based on the similarity threshold s i (e) For candidate set C i Sort the data and select the top k with the highest similarity. i For each sample, the (i+1)th layer is... Calculate s i+1 (e) And determine, similarly we get: Where, τ low ,τ high These represent the upper and lower limits of the similarity threshold, respectively.

7. The method for generating test cases based on a large model and dual constraints of requirements and protocols according to claim 6, characterized in that, The cross-layer decision-making strategy in S33 includes: Fusion scoring method: When the multi-level matching results are in the uncertainty interval (τ) low l (e)<τ high When calculating the weighted fusion score:​ Where α, β, γ, and x are all adjustable weighting coefficients, if If it is determined to be a match, then... Merge as C; The case is determined to be unmatched; otherwise, s will be... l (e), l=1,2,…,L, the first m e corresponding to it are taken as C.

8. The method for generating test cases based on a large model and dual constraints of requirements and protocols as described in claim 7, characterized in that, The process of generating the final test case set T in step S4 includes: A protocol field completion prompt is constructed. Each test case in T1 and its corresponding instruction candidate set C are used as input to the large model. Under the constraints of the protocol field completion prompt, the large model completes the missing protocol fields in the test cases, generating corresponding descriptions of missing fields, parameters, or data content, resulting in the final test case set T. The protocol field completion prompt is used to indicate the goal and scope of the generation task, constrain the format and hierarchy of the generated content, and emphasize the rationality of semantics and values. The protocol field completion prompt also includes few-sample examples, which consist of a predefined test case, its corresponding instruction candidate set C′, and the completed test case T′.