Method and tool for automatically generating test case
Through methods and tools for automatically generating test cases, the problem of the test speed in the prior art that cannot keep up with the software update speed and does not have the characteristics of the software, and the rapid and accurate test case generation is achieved, which improves the testing efficiency and quality.
Patent Information
- Application Number
- CN202510040178.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, software testers need to manually design the test suite, which causes the test speed to fail to keep up with the software update speed and does not have the characteristics of crossing software. The test suite needs to be redesigned to adapt to new software or applications.
Provides a method and tool for automatically generating test cases, and realizes the automated generation and scripting of test cases through requirements analysis, automated data model, business scenario design, automated test case generation, automated test case script generation, automated test framework execution, and result analysis and optimization.
By automatically generating test cases, testers can generate test cases faster and more accurately, improve the efficiency and quality of test work, ensure the completeness and accuracy of test cases, and have the characteristics that span multiple software, reducing the need for repeated design test suites.
Smart Images

Figure CN119883923A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of software testing, and in particular relates to a method and a tool for automatically generating test cases. Background Art
[0002] In the current context of shortening development cycles for software, web pages, and mobile applications, and increasing iteration speeds for software products, the importance of automated testing is self-evident. Currently, many companies are facing the problem of a lack of testers, and the speed of testing cannot keep up with the speed of updates. Some small companies even skip the testing phase, which can cause greater instability in software products. Software graphical user interface testing is particularly important in software product testing, because it starts from the user's perspective and is also the most direct and effective way to verify product reliability. Whether it is script-based testing or model-based testing, there is complex and arduous code writing work, which requires manual design of test suites and does not have cross-software features, which means that any new software web page or application requires a redesigned test suite. Summary of the invention
[0003] To solve the problems raised in the above background technology, the present invention provides a method and tool for automatically generating test cases, comprising the following steps: Step 1: Requirements analysis; Step 2: Automated data model; Step 3: Business scenario design; Step 4: Automated test case generation; Step 5: Generate automated test case scripts; Step 6: Automated test framework execution; Step 7: Result analysis and optimization.
[0004] As a preferred method and tool for automatically generating test cases of the present invention, the requirement analysis in step 1 analyzes the structured requirement specification and interface document to determine the test scope for automatically generating a data model.
[0005] As a preferred method and tool for automatically generating test cases of the present invention, the automated data model in step 2 further includes the following steps: Based on the results of the requirements analysis, create a data model, including input data and expected output; Design data structures to store these data models. Based on structured requirement documents, automatically generate structured data from data models as test rules and store them in the database.
[0006] As a preferred method and tool for automatically generating test cases of the present invention, the business scenario design in step 3 further includes the following steps: Based on the structured data generated by the model, it is designed according to customized business scenarios.
[0007] The design process is as follows: (1) Obtain data model from database to generate test rules; (2) Configure the service component to create a relationship between the service component and the test rule (associate the name / ID of the service component with the test rule) (3) Configure customized business scenarios; (for example, detection, download, installation, etc., where the name of the business scenario is the name of the service component) (4) After the customized business scenario is configured, it is used to automatically generate test cases in step 4.
[0008] As a preferred method and tool for automatically generating test cases in the present invention, the automated test case generation logic in step 4 is: the test rules stored in the database in step 2 are used to generate specific parameters according to different rules using the test case design method of boundary values, equivalence classes, and decision tables, and the generated parameters are replaced in sequence in the test steps; then, according to the correlation between the steps and the results, the results of the steps are generated in sequence; these test parameters and customized business scenarios are combined to automatically generate test cases; and the database is stored at the same time.
[0009] As a preferred method and tool for automatically generating test cases of the present invention, the automated test case script generation logic in step 5 is: According to the test case generated in step 4, the test steps are derived from the optional steps, among which the optional steps are derived from the test steps required for daily testing. The common parts are extracted and composed into a test step template (the test step template can be continuously updated and iterated). The test step template is imported into the system tool, and the tool loads these step templates and displays them as optional steps. The user selects from the optional steps according to the actual steps required by the case, and the steps that compose the test case are displayed in the selected steps. The optional steps correspond to the test execution methods one by one, and are converted into test scripts in sequence according to the test steps. Then the parameters in the test steps are replaced with the corresponding scripts to complete the generation of the test script.
[0010] As a preferred method and tool for automatically generating test cases of the present invention, the automated test framework execution in step 6 further includes the following steps: Integrate the generated test cases into the pytest automated testing framework and package them into an .exe executable file; By running the .exe tool, you can execute and generate a report with one click.
[0011] As a preferred method and tool for automatically generating test cases of the present invention, the result analysis and optimization in step 7 further includes the following steps: After executing the test cases, analyze the test results and check the differences between the actual results and the expected results; Adjust test cases and test strategies based on test results.
[0012] As a preferred method and tool for automatically generating test cases in the present invention, it includes demand analysis, automated data model, business scenario design, automated test case generation, automated test case script generation, automated test framework execution and result analysis and optimization.
[0013] Compared with the prior art, the present invention has the following beneficial effects: Through parameterization technology, the data to be tested and the expected results are passed into the test script as parameters, and multiple groups of test cases are generated through loops and conditional statements. At the same time, the present invention also adopts a data-driven approach to store the test data and expected results in an external file, and automatically generates test cases by reading the file and parsing the data. In addition, the present invention also provides a test case automatic generation tool, which can automatically plan and design test cases according to system functions and business requirements to ensure the completeness and accuracy of the test cases. Through the application of the present invention, testers can generate test cases more quickly and accurately, thereby improving the efficiency and quality of testing work. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings: Figure 1 A flowchart of a method and tool for automatically generating test cases according to the present invention; Figure 2 It is a demonstration diagram of step 1 of the present invention; Figure 3 It is an interface for re-editing the business rules in step 2 of the present invention; Figure 4 It is the adding step interface in step 2 of the present invention; Figure 5 Adding an interface for the expected result in step 2 of the present invention; Figure 6 Designing an interface for the business scenario in step 3 of the present invention; Figure 7 Generate a use case flow chart for the automation in step 4 of the present invention; Figure 8 It is a demonstration diagram of step 6 of the present invention; Fig. 9 This is a demonstration diagram of step 6 of the present invention. DETAILED DESCRIPTION
[0015] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Example
[0016] like Figure 1 As shown; In this implementation scheme: In order to solve the technical problems existing in this prior art, as disclosed in the background technology above, "whether it is script-based testing or model-based testing, there is complex and arduous code writing work, which requires manual design of test suites, and does not have the characteristics of crossing software, which means that any new software web page or application requires a redesign of the test suite." In terms of actual use, this problem is obviously a real and difficult problem to solve. In view of this, in order to solve this technical problem, a method and tool for automatically generating test cases are provided.
[0017] like Figure 1-Figure 5 As shown; In combination with the above content, the following steps are included: Step 1: Requirements analysis; Step 2: Automated data model; Step 3: Business scenario design; Step 4: Automated test case generation; Step 5: Generate automated test case scripts; Step 6: Automated test framework execution; Step 7: Result analysis and optimization.
[0018] like Figure 2 As shown, in the requirement analysis in step 1, the requirement specification is written according to specific specifications, and the structured requirement specification and interface document are selected and analyzed. Key information is extracted according to the corresponding rules, and the business rule file is generated to determine the test scope. The general library defines the rules for each data type. According to the data type of the business rule library, the data type rules of the same general class are taken out and merged with the business rule. If there is a consistent rule, the business library rule takes precedence. The merged new business rule library is stored in the database for the data model.
[0019] The automated data model in step 2 further comprises the following steps: According to the results of the demand analysis, based on the matching logic of step 1, the data model is automatically created and the data is stored in the database. For the data model rules that have been stored in the database, the rules can be edited again in the tool interface. The specific editing process is as follows: like Figure 3 As shown, the business rules can be edited again by modifying the rules generated in step 1, adding or modifying the corresponding rules; like Figure 4 As shown, the added steps are from the selectable steps, which can be selected from the step library that has been maintained in advance. The step library supports extensibility and automatically re-associates steps and rules.
[0020] like Figure 5 As shown, according to the operation steps and rules in the business rule file, configure the expected results that need to be verified, such as verifying that a certain field does not appear in the Android log within a specified time.
[0021] Design data structures to store these data models. Based on structured requirement documents, automatically generate structured data from data models as test rules and store them in the database.
[0022] In an optional embodiment, the business scenario design in step 3 further includes the following steps: Based on the structured data generated by the model, it is designed according to customized business scenarios.
[0023] The design process is as follows: 1. Obtain data model from database to generate test rules; 2. Configure the service component to create a relationship between the service component and the test rule (associate the name / ID of the service component with the test rule) 3. Configure customized business scenarios; (for example, detection, download, installation, etc., the name of the business scenario is the name of the service component) 4. If Figure 6 As shown, after the customized business scenario is configured, it is used for automatic generation of test cases in step 4.
[0024] like Figure 7 As shown, the automated test case generation logic in step 4 is: the test rules stored in the database in step 2 are used to generate specific parameters according to different rules using the test case design methods of boundary values, equivalence classes, and decision tables, and the generated parameters are replaced in sequence into the test steps; then, according to the correlation between the steps and the results, the results of the steps are generated in sequence; these test parameters and customized business scenarios are combined to automatically generate test cases; and the database is stored at the same time.
[0025] In an optional embodiment, the automated test case script generation logic in step 5 is as follows: according to the test case generated in step 4, the test steps are derived from the optional steps, wherein the optional steps are derived from the test steps required for daily testing, the common parts are extracted, and they are composed into a test step template (the test step template can be continuously updated by iteration), and the test step template is imported into the system tool, and the tool loads these step templates and displays them as optional steps. The user selects from the optional steps according to the actual steps required by the case, and the steps that compose the test case are displayed in the selected steps. The optional steps and the test execution methods correspond one by one, and are converted into test scripts in sequence according to the test steps, and then the parameters in the test steps are replaced into the corresponding scripts to complete the generation of the test script.
[0026] like Figure 8-9 As shown, the automated test framework execution in step 6 also includes the following steps: Integrate the generated test cases into the pytest automated testing framework and package them into an .exe executable file; By running the .exe tool, you can execute and generate a report with one click.
[0027] In an optional embodiment, the result analysis and optimization in step 7 further includes the following steps: After executing the test cases, analyze the test results and check the differences between the actual results and the expected results; Adjust test cases and test strategies based on test results.
[0028] A tool for automatically generating test cases, including requirements analysis, automated data model, business scenario design, automated test case generation, automated test case script generation, automated test framework execution, and result analysis and optimization.
[0029] The present invention uses parameterization technology to pass the data to be tested and the expected results as parameters into the test script, and generates multiple groups of test cases through loops and conditional statements. At the same time, the present invention also adopts a data-driven approach to store the test data and the expected results in an external file, and automatically generates test cases by reading the file and parsing the data. In addition, the present invention also provides a test case automatic generation tool, which can automatically plan and design test cases according to system functions and business requirements to ensure the completeness and accuracy of the test cases. Through the application of the present invention, testers can generate test cases more quickly and accurately, thereby improving the efficiency and quality of testing work.
[0030] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for automatically generating test cases, characterized in that: The following steps are involved: Step 1: Requirements analysis; Step 2: Automated data model; Step 3: Business scenario design; Step 4: Automated test case generation; Step 5: Generate automated test case scripts; Step 6: Automated test framework execution; Step 7: Result analysis and optimization.
2. The method for automatically generating test cases according to claim 1, characterized in that: The requirement analysis in step 1 analyzes the structured requirement specification and interface document to determine the test scope for automatically generating a data model.
3. The method for automatically generating test cases according to claim 1, characterized in that: The automated data model in step 2 further includes the following steps: Based on the results of the requirements analysis, create a data model, including input data and expected output; Design data structures to store these data models, prepare structured requirements specifications and interface documents, and automatically generate structured data from data models as test rules and store them in the database.
4. The method for automatically generating test cases according to claim 1, characterized in that: The business scenario design in step 3 further includes the following steps: Based on the structured data generated by the model, it is designed according to customized business scenarios. The design process is as follows: (1) Obtain data model from database to generate test rules; (2) Configure the service component, create the relationship between the service component and the test rule, and associate the service component name and ID with the test rule; (3) Configure customized business scenarios, detection, download, and installation scenarios. The business scenario name is the name of the service component. (4) After the customized business scenario is configured, it is used to generate automated test cases in step 4.
5. The method for automatically generating test cases according to claim 1, characterized in that: The automated test case generation logic in step 4 is as follows: the test rules stored in the database in step 2 are used to generate specific parameters according to different rules using the test case design methods of boundary values, equivalence classes, and decision tables, and the generated parameters are replaced in turn into the test steps; Then, based on the correlation between steps and results, the results of the steps are generated in sequence; these test parameters and customized business scenarios are combined to automatically generate test cases; and the database is stored at the same time.
6. The method for automatically generating test cases according to claim 1, characterized in that: The automated test case script generation logic in step 5 is: According to the test case generated in step 4, the test steps are derived from the optional steps, among which the optional steps are derived from the test steps required for daily testing. The common parts are extracted and composed into test step templates. The test step templates are imported into the system tool. The tool loads these step templates and displays them as optional steps. The user selects from the optional steps according to the actual steps required by the case, and the steps that compose the test case are displayed in the selected steps. The optional steps and the test execution methods correspond one by one, and are converted into test scripts in sequence according to the test steps. Then the parameters in the test steps are replaced with the corresponding scripts to complete the generation of the test script.
7. The method for automatically generating test cases according to claim 1, characterized in that: The automated testing framework execution in step 6 further includes the following steps: Integrate the generated test cases into the pytest automated testing framework and package them into an .exe executable file; By running the .exe tool, you can execute and generate a report with one click.
8. The method for automatically generating test cases according to claim 1, characterized in that: The result analysis and optimization in step 7 further includes the following steps: After executing the test cases, analyze the test results and check the differences between the actual results and the expected results; Adjust test cases and test strategies based on test results.
9. A tool for automatically generating test cases, characterized in that: According to the method for automatically generating test cases according to any one of claims 1 to 8, the tools for automatically generating test cases include demand analysis, automated data model, business scenario design, automated test case generation, automated test case script generation, automated test framework execution, and result analysis and optimization.
Citation Information
Patent Citations
Test case automatic generation method and apparatus
CN105426309A
Method and system for automatically generating interface testing case
CN105528294A
Testing method and device and computer readable storage medium
CN110162468A
Test case design method based on path depth coverage
CN111694741A
Test case generation method and device, computer equipment and storage medium
CN112256558A