Method for automatically generating test case from product demand document by knowledge base

Through PRD document parsing, knowledge base construction and calling, test case generation and generalization modules, test cases are automatically generated using a large language model, which solves the problems of time-consuming and insufficient coverage of traditional test case design, and realizes efficient and comprehensive test case generation, which is suitable for complex software projects.

CN120723649APending Publication Date: 2025-09-30EAST CHINA NORMAL UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510888717.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-09-30

AI Technical Summary

Technical Problem

Traditional test case design is time-consuming and inefficient, and it is difficult to fully cover normal, boundary, abnormal and concurrent scenarios, resulting in insufficient test coverage. In addition, the test cases generated by existing technologies in large projects are incomplete, repetitive and redundant, and lack the use of historical data, resulting in a high risk of software defects.

Method used

Adopting the four-module approach of PRD document parsing, knowledge base construction and calling, test case generation and generalization, the system automatically generates test cases using a large language model and knowledge base. Through structured function point extraction, multi-threaded parallel processing and asynchronous API calling, it generates comprehensive and diverse test cases.

Benefits of technology

It significantly improves the generation efficiency and coverage of test cases, enhances the accuracy and diversity of test cases, is suitable for complex project requirements, reduces labor costs, and is suitable for functional, boundary, exception and concurrent testing in the software development process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120723649A_ABST
    Figure CN120723649A_ABST
Patent Text Reader

Abstract

The invention discloses a method for automatically generating a test case from a product demand document by a knowledge base, which is characterized by comprising a PRD document analysis and function point extraction module, a knowledge base construction and calling module, a test case generation module and a test case generalization module, the PRD document analysis and function point extraction module is used for converting a PRD document into a structured Markdown format by utilizing a large language model; the knowledge base construction and calling module constructs a structured knowledge base by analyzing historical PRD and test case data; the test case generation module generates test cases covering a normal scene, a boundary scene, an abnormal scene and a concurrent scene; and the test case generalization module is used for generating diversified and non-repeated test cases. Compared with the prior art, the method has the advantages that an efficient and comprehensive solution is provided for software testing automation, the method is particularly suitable for function testing, boundary testing, abnormal testing and concurrent testing in the software development process, and the application prospect is good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software test automation, and in particular to a method for automatically generating test cases from a product requirement document (PRD) by utilizing a large language model and a knowledge base. Background Art

[0002] As software systems continue to increase in complexity, test case design has become a critical step in ensuring software quality. Traditional test case design relies on test engineers manually analyzing product requirement documents (PRDs), which is time-consuming, inefficient, and prone to missing key test scenarios. Especially in large-scale projects, manual design struggles to fully cover normal, edge, abnormal, and concurrent scenarios, resulting in insufficient test coverage and an increased risk of software defects.

[0003] Recent breakthroughs in natural language processing using large language models (such as GPT and Llama) have opened up new possibilities for automated test case generation. However, existing technologies suffer from the following shortcomings: 1) incomplete function point extraction makes it difficult to accurately reflect the core business processes in the PRD; 2) limited test case coverage lacks systematic consideration of boundaries, exceptions, and concurrent scenarios; 3) generated test cases lack diversity and are prone to duplication or redundancy; 4) processing efficiency is low for large PRD documents, making it difficult to meet complex project requirements; and 5) a lack of effective utilization of historical test data results in insufficient accuracy and applicability of generated test cases in complex business scenarios. Summary of the Invention

[0004] The purpose of the present invention is to provide a method for automatically generating test cases from product requirement documents using a knowledge base in response to the deficiencies of the prior art. The method adopts four modules of PRD document parsing, knowledge base construction and calling, test case generation and generalization to automatically generate test cases, automatically complete test case design, reduce labor costs, and improve test coverage and accuracy. The method is based on a method for automatically generating test cases from PRD using a large language model and a knowledge base. Through structured function point extraction, knowledge base construction and calling, systematic test case generation and diversified generalization, the coverage, accuracy and generation efficiency of test cases are significantly improved, providing an efficient and comprehensive solution for software testing automation. The method is particularly suitable for functional testing, boundary testing, exception testing and concurrent testing in the software development process. The method is simple, has high processing efficiency, can fully utilize historical test data, meets complex project requirements, and effectively solves the problems of insufficient accuracy and applicability of test cases in complex business scenarios. It has good application prospects.

[0005] The specific technical solution for achieving the purpose of the present invention is: a method for automatically generating test cases from a product requirement document based on a knowledge base, wherein the method specifically comprises the following steps: 1) Establish PRD document parsing and function point extraction submodule The block processing and dialogue prompt optimization method is used to build a submodule including: PRD document parsing submodule and function point extraction submodule. This module uses a large language model to convert the PRD document into a structured Markdown format and extract the main function, parent function point and child function point. The specific operation process is as follows: 1.1: The PRD document parsing submodule preprocesses the input document (supporting .docx or .txt files), removing extra spaces and line breaks. For large documents, a block-based processing strategy is used, splitting the document into multiple blocks (each approximately 10,000 characters). Block-by-block parsing and merging the results ensures the completeness of function point extraction. The parsing process uses a large language model (based on deepseek-r1-distill-qwen-32b-250120) to generate a Markdown document containing the main function, parent function points, and child function points.

[0006] 1.2: The function point extraction submodule extracts function points based on optimized prompts and PRD content. Prompts explicitly require that parent function points be parallel and that sub-function points be subdivisions of the parent function point. Descriptions should be highly summarized and avoid preconditions, steps, or redundant information. The output Markdown document contains the main function, parent function point, sub-function points, their preconditions, steps, and expected results.

[0007] 2) Establish submodules and call modules for knowledge base construction The large language model semantic analysis and dynamic retrieval method is used to build a knowledge base submodule and a knowledge base call submodule. This module builds a structured knowledge base by analyzing historical PRD and test case data, and dynamically calls it during the test case generation and generalization process. The specific operation process is as follows: 2.1: The knowledge base call submodule extracts function points, test scenarios, and use case patterns from historical PRD documents, Markdown files, and test case JSON files. It uses a large language model for semantic analysis to extract key business patterns (such as user registration processes and data query scenarios). The extracted content includes business processes, scenario types (normal, boundary, abnormal, concurrent), prerequisite templates, and expected result patterns, and is stored as a knowledge base in a structured JSON format.

[0008] 2.2: The Knowledge Base Call submodule dynamically retrieves relevant templates and patterns from the knowledge base based on the current PRD's functional points and business scenarios. For example, for the user login function, it retrieves boundary conditions (such as excessively long passwords) and exception scenarios (such as the number of incorrect password attempts) from historical login scenarios to enhance test case accuracy and coverage. The call process uses a semantic matching algorithm to ensure that the retrieval results are highly relevant to the current PRD.

[0009] 3) Establish a test case generation module A test case generation module consisting of a normal scenario generation submodule, a boundary scenario generation submodule, an abnormal scenario generation submodule, and a concurrent scenario generation submodule is constructed using multi-threaded parallel processing and asynchronous API calling methods. This module generates test cases covering normal scenarios, boundary scenarios, abnormal scenarios, and concurrent scenarios based on the extracted function points, PRD content, and knowledge base. The specific operation process is as follows: 3.1: Use the normal scenario generation submodule to design a representative test case for each core business process (such as user registration, data query, data upload, data deletion, etc.). Combined with the knowledge base template, verify the correctness of the system under standard input. For example, for the user registration function, generate a test case to verify the successful registration scenario with a valid username and password.

[0010] 3.2: Use the boundary scenario generation submodule to generate test cases for minimum, maximum, empty, and out-of-bounds inputs for key fields (such as username, password, and file size), referencing the boundary scenario patterns in the knowledge base. For example, test the system response to usernames with a minimum and maximum length, empty input, and overlong input.

[0011] 3.3 Use the exception scenario generation submodule to generate test cases for format errors (such as incorrect email format), invalid data (such as uploading unsupported file types), and logical exceptions (such as registering an existing username). Combined with the knowledge base, verify the system's fault tolerance and error prompt clarity.

[0012] 3.4: Use the concurrent scenario generation submodule to simulate multiple users performing the same or different operations at the same time (such as multiple users uploading files or querying data at the same time). Refer to the concurrent scenario templates in the knowledge base to verify the system's concurrent processing capabilities and data consistency.

[0013] 3.5: Test cases are output in JSON format. Each test case contains ID, parent function point, child function point, title, prerequisites, operation steps, expected results and use case attributes (positive use case or negative use case). The title follows the rule of "core - system name - business process - role / module - scenario type - test purpose" to ensure clarity and readability.

[0014] 4) Establish a test case generalization module A test case generalization module is constructed using asynchronous processing and multi-threaded parallel optimization methods. This module is based on multi-angle precondition expansion and combines with the knowledge base to generate diverse and non-repetitive test cases. The specific operation process is as follows: 4.1: The generalization submodule analyzes the PRD, Markdown content, and knowledge base to generate differentiated preconditions based on environmental factors (different devices, browsers), data status (data presence or absence), and user permissions (administrator, ordinary user). For example, it generates test cases for the user login function under different network environments and user roles.

[0015] 4.2: Ensure that the title and prerequisites of each test case are unique, avoid synonym generalization, cover all business scenarios, and use variational analysis methods to generate new differentiated use cases based on the prerequisites of existing use cases and knowledge base templates.

[0016] 4.3: Use a thread pool to parallelize test case generalization tasks and optimize generation efficiency. Introduce a retry mechanism and JSON cleanup algorithm to handle format errors in API responses and ensure the correctness and integrity of the output JSON.

[0017] 4.4: The generalized test cases are saved in JSON format, expanding the original test case set and generating a new JSON file (such as test_cases_expanded.json).

[0018] Compared with the prior art, the present invention has the following beneficial technical effects and significant technical progress: 1) Efficiency: Through automated processes, block processing strategies, and thread pool parallel processing, the efficiency of parsing large PRD documents and generating test cases is significantly improved, reducing manual intervention time.

[0019] 2) Comprehensiveness: Covering normal, boundary, abnormal, and concurrent scenarios, combined with the knowledge base to ensure that test cases fully cover core business processes and improve test coverage.

[0020] 3) Accuracy: By building and calling a knowledge base, the business relevance and accuracy of test cases are enhanced, and redundancy and omissions are reduced.

[0021] 4) Diversity: Generate non-repetitive test cases through multi-angle prerequisite expansion and knowledge base templates to meet the testing needs of complex business scenarios.

[0022] 5) Practicality: This method can be integrated into the continuous integration / continuous deployment (CI / CD) process and is applicable to various software development scenarios, such as web applications, mobile applications, and enterprise-level systems, significantly reducing test design costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0024] The present invention will be further described in detail below with reference to specific embodiments and accompanying drawings. The processes, conditions, experimental methods, etc. for implementing the present invention, except for those specifically mentioned below, are common knowledge and common common sense in the art and are not particularly limited by the present invention. Example

[0025] See Figure 1 ,Using the automatic test case generation system composed of input module, preprocessing module, knowledge base module, generative module, post-processing module and output module, the specific steps to realize the knowledge base to automatically generate test cases from product requirement documents are as follows: Step 1: PRD document parsing and function point extraction Input Module: The system receives user-provided PRD documents (supporting .docx or .txt formats) as input data sources. Users can upload PRD documents locally or submit them through the API. Multiple encoding formats (such as UTF-8) are supported, and preliminary file integrity verification is performed to ensure the usability of the input data.

[0026] Preprocessing: This module performs comprehensive preprocessing on incoming PRD documents, including removing redundant spaces, line breaks, and special control characters, and normalizing the content to improve subsequent parsing efficiency. For large documents, an intelligent chunking strategy is employed to segment the document into semantically complete chunks (approximately 10,000 characters per chunk), ensuring logical consistency across chunks using natural language segmentation points (such as titles and paragraph boundaries).

[0027] Step 2: Knowledge base construction and call Knowledge Base Module: This system analyzes historical PRD documents, Markdown files, and test case JSON files, using a large language model for deep semantic analysis. It extracts functional points, test scenarios, use case patterns, and related business rules to build a structured knowledge base. The knowledge base, stored in JSON format, contains detailed business processes (such as user registration and data query), scenario types (normal, boundary, abnormal, and concurrent), prerequisite templates, expected result patterns, and historical test case success rate statistics. Regular updates ensure the knowledge base remains up-to-date and accurate.

[0028] Step 3: Test case generation Generative Module: Based on preprocessed PRD content and knowledge base data, the Generative Module utilizes a large language model to generate diverse test cases, covering normal scenarios (such as the standard user registration process), edge cases (such as testing for minimum username length), abnormal scenarios (such as invalid email format input), and concurrent scenarios (such as multiple users logging in simultaneously). The generation process integrates knowledge base templates to dynamically adjust the complexity of test cases to ensure coverage of all key functional points and potential risk points.

[0029] Post-processing: This module optimizes the format and removes duplicates from generated test cases. Intelligent algorithms are used to check the uniqueness of titles, prerequisites, and steps to ensure logical coherence and redundancy. Generated test cases are output in a standard JSON format, containing detailed fields (such as ID, parent function point, child function point, title, prerequisites, steps, expected results, and use case attributes). User-defined fields can be expanded to suit different project needs.

[0030] Step 4: Test case generalization and output The Output Module saves processed test cases in JSON format, expanding the existing test case set and generating new JSON files (e.g., test_cases_expanded.json). The Output Module supports multi-file output, generating either segmented or aggregated JSON files based on user needs. It also provides version control to record the version information of each generated test case. The file save path is configurable to ensure data security and traceability.

[0031] The above is only a further explanation of the present invention and is not intended to limit this patent. Any equivalent implementation of the present invention should be included in the scope of the claims of this patent.

Claims

1. A method for automatically generating test cases from a product requirement document using a knowledge base, characterized in that the method specifically comprises the following steps: 1) Establish PRD document parsing and function point extraction module The block processing and dialogue prompt optimization method is used to build a submodule including: PRD document parsing submodule and function point extraction submodule. This module uses a large language model to convert PRD documents in docx or txt format into structured Markdown format, and extracts the main function, parent function point and child function point. Its specific operations are as follows: 1.1 Use the PRD document parsing submodule to remove redundant spaces and line breaks through preprocessing, and use the large language model to generate a hierarchical Markdown document containing the main function, parent function point, and child function point. The preprocessing uses regular expressions to replace normalized line breaks and spaces. The chunking process uses the chunk_document function to semantically segment long documents, with each chunk not exceeding 5,000 tokens to ensure semantic integrity. 1.2 The function point extraction submodule is designed based on dialogue prompts and combines the PRD content to extract parent function points and child function points. The dialogue prompts use optimized instructions to forcibly generate the main function title, ensuring that the parent function points are in a parallel relationship and the child function points are subdivisions of the parent function points. The descriptions are highly summarized and there are no redundant operation steps. The extraction process uses the merge_function_points function to merge the block results, remove duplicates, and maintain the hierarchical structure. 2) Establish knowledge base construction submodule and call module The large language model semantic analysis and dynamic retrieval method is used to build a knowledge base submodule and a knowledge base call submodule. This module builds a structured knowledge base by analyzing historical PRD and test case data, and uses the call module to dynamically call relevant templates and patterns during the test case generation and generalization process. The specific operations are as follows: 2.1: Use the knowledge base construction submodule to extract function points, test scenarios, and use case patterns from historical PRD documents, Markdown files, and test case JSON files, and build a knowledge base including business processes, scenario types, and use case templates; 2.2: Use the knowledge base call submodule to dynamically call function points and business scenarios based on the current PRD, and dynamically retrieve relevant templates and patterns in the knowledge base; 3) Establish a test case generation module A test case generation module is constructed using multi-threaded parallel processing and asynchronous API calling methods, including: normal scenario generation submodule, boundary scenario generation submodule, abnormal scenario generation submodule, and concurrent scenario generation submodule. This module generates test cases covering normal scenarios, boundary scenarios, abnormal scenarios, and concurrent scenarios based on the extracted function points, PRD content, and knowledge base. Its specific operations are as follows: 3.1 Use the normal scenario generation submodule to generate a representative test case for each core business process, and combine it with the knowledge base template to verify the correctness of the system under standard input. The generation process uses the generate_test_cases function to parse Markdown and docx content using a large language model to ensure that all key functions are covered. 3.2 Using the boundary scenario generation submodule, referencing the boundary scenario patterns in the knowledge base, we generate test cases for minimum, maximum, empty, and out-of-bounds inputs for key fields including username and file size. This generation process combines the docx content and knowledge base templates through the generate_test_cases function to ensure comprehensive boundary value testing. 3.3 Utilize the exception scenario generation submodule and combine it with the knowledge base to verify the system's fault tolerance and generate test cases for format errors, invalid data, and logical anomalies. The generation process uses the generate_test_cases function to parse the exception scenario prompts to ensure that logical anomalies such as mailbox format errors, invalid data of unsupported file types, and duplicate registrations are covered. 3.4 Use the concurrent scenario generation submodule to simulate multi-user concurrent operations, refer to the concurrent scenario templates in the knowledge base, and verify the system data consistency and concurrent processing capabilities. The generation process simulates multi-user operation scenarios through the generate_test_cases function to ensure the accuracy of concurrent testing; 3.5 Output the test case in JSON format, including the ID, parent function point, child function point, title, prerequisites, operation steps, expected results, and use case attributes, where the use case attributes are positive or negative use cases; the output is sorted by function to remove duplicates and saved as a JSON file; 4) Establish a test case generalization module A test case generalization module is constructed using asynchronous processing and multi-threaded parallel optimization methods. This module combines the knowledge base to generate diverse and non-repetitive test cases. The specific operations are as follows: 4.1: Use the generalization submodule to analyze PRD, Markdown content, and knowledge base, and generate differentiated prerequisites based on environmental factors, data status, and user permissions; 4.2: Ensure that the title and prerequisites of each test case are unique, avoid synonyms and generalization, and avoid covering all business scenarios; 4.3: Use thread pool to parallelize test case generalization tasks and optimize generation efficiency; 4.4: Save the generalized test case in JSON format, expand the original test case set, and generate a new JSON file.

2. The method for automatically generating test cases from product requirement documents using a knowledge base according to claim 1, characterized in that: The PRD document parsing submodule in step 1.1 adopts a block processing strategy. For large PRD documents that exceed the model input limit, the PRD documents are parsed block by block and the results are merged to ensure the integrity of the function point extraction.

3. The method for automatically generating test cases from product requirement documents using a knowledge base according to claim 1, characterized in that: The knowledge base construction submodule in step 2.1 uses a large language model to perform semantic analysis on historical data, extracts key business models including: user registration, user login, data query, data upload, data deletion, user role management, scoring rule processing, concurrent operation processing and boundary value verification, and stores them in a structured JSON format.

4. The method for automatically generating test cases from product requirement documents using a knowledge base according to claim 1, characterized in that: The test case generation module in step 3 uses optimized dialogue prompts and knowledge base templates to clarify scenario types and title rules to ensure the logic and readability of the generated case. The title format is "Core - System Name - Business Process - Role / Module - Scenario Type - Test Purpose".

5. The method for automatically generating test cases from product requirement documents using a knowledge base according to claim 1, characterized in that: The test case generalization module in step 4 introduces a retry mechanism and a JSON cleaning algorithm to handle format errors in API responses and ensure the correctness and integrity of the output JSON.

Citation Information

Cited By

  • Function test method, system and equipment of intelligent electric meter and medium

    CN121541130A