Test case generation method and device, equipment, medium and product

By performing format and syntax verification on the target source code file, identifying and generating test cases for shell scripts, the problems of low efficiency and incomplete coverage in the existing technology are solved, and efficient and accurate test case generation is achieved.

CN120653556APending Publication Date: 2025-09-16CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510711534.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-29
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Existing technologies are inefficient and incomplete in generating test cases, and are unable to fully record user input and output, resulting in insufficient test accuracy and flexibility, especially in shell script testing, where there are obvious limitations.

Method used

By performing file verification and code parsing on the target source code file, the method or command to be called is identified and test cases are generated, including format verification, syntax verification, parameter parsing and branch path analysis, and test cases are generated dynamically.

Benefits of technology

It improves the efficiency, completeness and flexibility of test case generation, ensures the accuracy of test results of code files, covers all functional scenarios, and reduces human errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653556A_ABST
    Figure CN120653556A_ABST
Patent Text Reader

Abstract

The invention discloses a test case generation method and device, equipment, a medium and a product, and relates to the technical field of software tests.The method comprises the steps that in response to a received target source code file, file verification is conducted on the target source code file; under the condition that the target source code file passes file verification, code analysis is carried out on the target source code file, and a method or a command to be called is determined; and generating a test case corresponding to the target source code file based on the to-be-called method or command, analyzing the target source code file passing file verification without depending on experience of a tester, determining the to-be-called method or command, and generating a corresponding test case according to the to-be-called method or command. The efficiency, integrity and flexibility of generating the test case can be improved, and then the accuracy of the test result of the code file is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software testing technology, and in particular to a test case generation method, apparatus, device, medium and product. Background Art

[0002] In the current software testing landscape, testing code files (such as shell scripts) presents several pain points and limitations. Traditional testing methods rely on testers to thoroughly read and understand the code, then manually list all branches and develop them into test cases. However, this approach presents challenges for shell language beginners, as understanding the complex source code of shell operation and maintenance scripts can be challenging, leading to slow tester learning and low testing efficiency. Furthermore, manually designing test cases is not only time-consuming and labor-intensive, but also prone to omissions, resulting in incomplete test coverage and an inability to fully guarantee code quality and functional integrity.

[0003] While some automated testing tools and methods currently exist, most have limitations. For example, some tools can only record user operation steps, but not fully record user input and output. This results in incomplete generated test case code, impacting test accuracy and reliability. Other tools can only generate fixed test case code, lacking flexibility, which in turn affects test efficiency and effectiveness. Furthermore, some tools can only record user operation steps within a graphical user interface, resulting in incomplete generated test case code and limiting the accuracy of test results.

[0004] Therefore, it is necessary to propose a solution to improve the efficiency, completeness and flexibility of generating test cases in order to improve the accuracy of the test results of code files.

[0005] The above content is only used to assist in understanding the technical solution of this application and does not constitute an admission that the above content is prior art. Summary of the Invention

[0006] The main purpose of this application is to provide a test case generation method, device, equipment, medium and product, aiming to propose a solution to improve the efficiency, completeness and flexibility of generating test cases, so as to improve the accuracy of the test results of code files.

[0007] To achieve the above objectives, the present application provides a test case generation method, the method comprising:

[0008] In response to receiving the target source code file, performing file verification on the target source code file;

[0009] If the target source code file passes the file verification, performing code parsing on the target source code file to determine the method or command to be called;

[0010] Generate a test case corresponding to the target source code file based on the method or command to be called.

[0011] In one embodiment, the step of performing file verification on the target source code file includes:

[0012] Performing format verification on the target source code file to determine whether the target source code file is in the target format;

[0013] If the target source code file is in a target format, performing syntax check on the target source code file to determine whether the target source code file has syntax errors or logical anomalies;

[0014] If the target source code file does not have any syntax errors or logic anomalies, it is determined that the target source code file passes the file verification.

[0015] In one embodiment, the step of parsing the target source code file to determine the method or command to be called includes:

[0016] Read the script content in the target source code file;

[0017] Perform parameter parsing on the script content to determine whether the script content requires input parameters;

[0018] If the script content requires input parameters, then select or determine branch functions corresponding to different input parameters, and determine the method or command to be called according to the branch functions;

[0019] If the script content does not require input parameters, the target function is determined according to the script content, and the method or command to be called is determined according to the target function.

[0020] In one embodiment, the step of determining the method or command to be called according to the branch function or the target function includes:

[0021] Matching the method or command corresponding to the branch function or target function through an associative array and / or a pre-configured file;

[0022] The methods or commands corresponding to the branch functions or target functions are sorted based on a preset calling logic to determine the method or command to be called.

[0023] In one embodiment, the step of generating a test case corresponding to the target source code file based on the method or command to be called includes:

[0024] Call the methods or commands to be called one by one through a loop structure, and record the judgment conditions, operation steps and output results corresponding to the methods or commands to be called;

[0025] The preset test case template is filled in according to the determination conditions, operation steps and output results corresponding to the method or command to be called to obtain the test case corresponding to the target source code file.

[0026] In one embodiment, the step of calling the methods or commands to be called one by one through a loop structure and recording the determination conditions, operation steps, and output results corresponding to the methods or commands to be called further includes:

[0027] Determine each branch path according to the input parameters, corresponding branch functions or target functions used in the calling process of the method or command to be called;

[0028] Paths are listed according to the branch paths to generate a full test path diagram, wherein the full test path diagram is used to adjust the test cases corresponding to the target source code file.

[0029] In addition, to achieve the above-mentioned purpose, the present application also proposes a test case generation device, the test case generation device comprising:

[0030] A response module, configured to perform file verification on the target source code file in response to receiving the target source code file;

[0031] A parsing module, configured to parse the target source code file and determine a method or command to be called if the target source code file passes file verification;

[0032] A generation module is used to generate a test case corresponding to the target source code file based on the method or command to be called.

[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes a test case generation device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the test case generation method described above.

[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the steps of the test case generation method described above are implemented.

[0035] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the test case generation method described above are implemented.

[0036] One or more technical solutions proposed in this application have at least the following technical effects:

[0037] In response to receiving a target source code file, the target source code file is subjected to file verification; if the target source code file passes the file verification, the target source code file is subjected to code parsing to determine the method or command to be called; and a test case corresponding to the target source code file is generated based on the method or command to be called. This method does not rely on the experience of the tester, and the target source code file that passes the file verification is parsed to determine the method or command to be called, and a corresponding test case is generated according to the method or command to be called. This method can fully record input parameters and output results, and dynamically generate test cases according to different input parameters, thereby improving the efficiency, completeness and flexibility of generating test cases, and further improving the accuracy of the test results of the code file. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0040] Figure 1 A flowchart of the first embodiment of the test case generation method of this application is provided;

[0041] Figure 2 A flowchart of the second embodiment of the test case generation method of this application is provided;

[0042] Figure 3 Schematic diagram of the overall processing flow according to the second embodiment of the present application;

[0043] Figure 4 Schematic diagram of the code parsing process according to the second embodiment of the present application;

[0044] Figure 5 A flowchart of the third embodiment of the test case generation method of this application is provided;

[0045] Figure 6 Schematic diagram of a test case according to the third embodiment of the present application;

[0046] Figure 7 Schematic diagram of a full test path diagram according to the third embodiment of the present application;

[0047] Figure 8 This is a schematic diagram of the module structure of the test case generation device according to an embodiment of the present application;

[0048] Figure 9 Schematic diagram of the device structure of the hardware operating environment involved in the test case generation method in the embodiment of the present application.

[0049] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.

[0051] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0052] The main solution of the embodiment of the present application is: in response to receiving a target source code file, performing file verification on the target source code file; if the target source code file passes the file verification, performing code parsing on the target source code file to determine the method or command to be called; generating a test case corresponding to the target source code file based on the method or command to be called, without relying on the experience of the tester, parsing the target source code file that passes the file verification, determining the method or command to be called, and generating a corresponding test case based on the method or command to be called, which can improve the efficiency, completeness and flexibility of generating test cases, and thereby improve the accuracy of the test results of the code file.

[0053] In this embodiment, for ease of description, the following description is made with the test case generating device as the execution subject.

[0054] In the current software testing field, shell script testing faces several pain points and limitations. Traditional shell operation and maintenance script testing methods rely primarily on testers to thoroughly read and understand the code, then manually list all branches and expand them into test cases. However, this approach presents challenges for shell language beginners, as they struggle to understand the complex shell operation and maintenance script source code, resulting in slow tester learning and low testing efficiency. Furthermore, manually designing test cases is not only time-consuming and labor-intensive, but also prone to omissions, resulting in incomplete test coverage and an inability to fully guarantee code quality and functional integrity. While some automated testing tools and methods exist, most have limitations. For example, some tools only record user operation steps, but not their input and output. This results in incomplete generated test case code, impacting test accuracy and reliability. Other tools only generate fixed test case code, lacking flexibility and unable to dynamically generate test case code based on user input and output, further impacting test efficiency and effectiveness. Furthermore, some tools only record user operation steps in the graphical user interface (GUI), but not in the command line interface (CLI), resulting in incomplete generated test case code and limiting test coverage and depth. Therefore, there is an urgent need for a shell script testing solution that can effectively solve the above problems to improve the efficiency, accuracy and flexibility of shell script testing.

[0055] This application provides a solution based on a standard single shell source code file, which can accurately identify the input and output, method calls, etc. in the source code, quickly and intelligently generate script logic diagrams and test cases, and does not rely heavily on the understanding and experience of the tester, thereby improving the efficiency and quality of test case design.

[0056] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, mobile phone, etc., or an electronic device capable of implementing the above functions, a test case generation device, etc. The following uses the test case generation device as an example to illustrate this embodiment and the following embodiments.

[0057] Based on this, the present invention provides a method for generating a test case. Figure 1 , Figure 1 This is a flowchart of the first embodiment of the test case generation method of this application.

[0058] In this embodiment, the test case generation method includes steps S10 to S30:

[0059] Step S10, in response to receiving the target source code file, performing file verification on the target source code file;

[0060] Exemplarily, the target source code file includes a script file for generating a test case, and may include various programming language source code files or script language source code files. In the embodiment of the present application, Shell source code files are used as an example for description.

[0061] Exemplarily, the step of performing file verification on the target source code file includes:

[0062] Performing format verification on the target source code file to determine whether the target source code file is in the target format;

[0063] If the target source code file is in a target format, performing syntax check on the target source code file to determine whether the target source code file has syntax errors or logical anomalies;

[0064] If the target source code file does not have any syntax errors or logic anomalies, it is determined that the target source code file passes the file verification.

[0065] For example, the file format can be determined by examining characteristic information such as the file extension, file header identifier, or file magic number. For example, shell script files typically have a .sh extension, and checking the file extension can provide a preliminary determination of the file type. This ensures that the target source code file is a script file in the expected format, improving the efficiency and accuracy of subsequent processing steps.

[0066] For example, syntax checking is the process of checking the contents of the target source code file to identify syntax errors or logical anomalies in the file and ensure that the file can be executed correctly. Only files in the target format are checked in this step to ensure that subsequent steps are based on correct syntax and logic.

[0067] For example, in the embodiment of the present application, a corresponding interpreter or syntax analysis tool can be called to load the target source code file content, parse it according to the syntax rules of the script language, capture and record error information during the parsing process, and finally determine whether the file has syntax errors or logical anomalies based on the error information. For example, using commands such as bash-n to perform syntax checking on Shell scripts can effectively find syntax errors in the script, and no additional tools need to be installed. It is convenient and fast and suitable for syntax verification of Shell scripts. Third-party syntax analysis tools can also be used: such as ShellCheck, which can provide more detailed syntax and logical analysis to find potential logical problems. In the embodiment of the present application, the built-in syntax check of Shell is first used to quickly find obvious syntax errors, and then a third-party tool is used to deeply check the logical problems, which can fully guarantee the syntax and logical correctness of the script and ensure that the script can run normally.

[0068] For example, a comprehensive judgment is made based on the results of format verification and syntax verification. If the format verification passes and the syntax verification finds no errors, the file is considered to meet the requirements; otherwise, the file is considered to not meet the requirements. This solution first conducts a comprehensive verification of the file to discover and exclude these problem files in advance, avoiding the subsequent steps of wasting resources on non-compliant files and improving the efficiency and quality of the entire testing process. At the same time, it also prevents potential risks caused by file problems, such as generating incorrect test cases that lead to insufficient script testing or misjudgment of script functions, thereby ensuring the accuracy and reliability of script testing.

[0069] Step S20: If the target source code file passes the file verification, code parsing is performed on the target source code file to determine the method or command to be called;

[0070] For example, code parsing is the process of reading and analyzing the contents of the target source code file, with the aim of understanding the logical structure and functional implementation of the script file. The method or command to be called refers to the function, system command or tool that implements a specific function in the script, and is the key basis for the subsequent generation of test cases. By reading the script content, the grammatical structure, function definition and call relationship in the script are analyzed using techniques such as parsers or regular expressions. Based on the logical structure of the script and the use of parameters, determine which methods or commands the script will call under different conditions. In this way, the functional logic of the script file can be accurately understood, the core operation points for implementing various functions can be found, and a basis for generating accurate test cases can be provided.

[0071] For example, in the embodiment of the present application, the script content is first read, and then parameter parsing is performed to determine whether input parameters are required; if necessary, the branch functions corresponding to different input parameters are further determined, and then the method or command to be called is found; if not, the target function and the corresponding method or command are directly determined according to the overall logic of the script.

[0072] Step S30: Generate a test case corresponding to the target source code file based on the method or command to be called.

[0073] For example, based on the function, parameter requirements, and possible input and output conditions of the method or command to be called, corresponding test cases can be designed. By simulating different input conditions, calling the corresponding method or command, and recording the comparison between the actual output results and the expected results, a complete test case can be generated.

[0074] Illustratively, in an embodiment of the present application, a loop structure is used to call each method or command to be called in sequence, and the judgment conditions, operation steps and output results in the calling process are recorded; then a test case is constructed based on these records, and the test steps, input data and expected results are described in detail.

[0075] Exemplarily, the step of calling the methods or commands to be called one by one through a loop structure and recording the determination conditions, operation steps and output results corresponding to the methods or commands to be called further includes:

[0076] Determine each branch path according to the input parameters, corresponding branch functions or target functions used in the calling process of the method or command to be called;

[0077] Paths are listed according to the branch paths to generate a full test path diagram, wherein the full test path diagram is used to adjust the test cases corresponding to the target source code file.

[0078] For example, the method or command to be called is the part of the script that will be executed to achieve a specific function. The input parameters are the external data required by these methods or commands when running. The branch functions are the different functions executed in the script based on different input conditions. The target function is the overall function that the script is expected to achieve. By analyzing these elements, we can determine the execution branch paths of the script in different situations.

[0079] For example, the embodiments of the present application identify all possible execution paths of the script under different input conditions, ensuring that the test cases can cover all functional scenarios of the script, thereby improving the completeness and effectiveness of the test. By identifying all possible execution paths of the script under different input conditions, ensuring that the test cases can cover all functional scenarios of the script, thereby improving the completeness and effectiveness of the test.

[0080] For example, branch paths are different routes that a script executes under different input conditions, path listing is the process of listing these routes in a systematic manner, and the full test path diagram is a graphical tool that intuitively displays all possible execution paths of the script. It can help testers fully understand the behavior of the script, thereby adjusting and optimizing test cases to ensure that all functional scenarios are covered. By systematically identifying branch paths and intuitively displaying the full path diagram, testers can find missed test scenarios and avoid functional anomalies or crashes in the actual operation of the script due to insufficient testing. At the same time, it also solves the problems of inefficiency and error-proneness in manually listing paths and adjusting test cases, thereby improving the overall efficiency and quality of testing work.

[0081] This embodiment adopts the above-mentioned scheme, specifically by performing file verification on the target source code file in response to receiving the target source code file; if the target source code file passes the file verification, performing code parsing on the target source code file to determine the method or command to be called; generating a test case corresponding to the target source code file based on the method or command to be called, without relying on the experience of the tester, parsing the target source code file that passes the file verification, determining the method or command to be called, and generating a corresponding test case according to the method or command to be called, which can fully record the input parameters and output results, and dynamically generate test cases according to different input parameters, thereby improving the efficiency, completeness and flexibility of generating test cases, and further improving the accuracy of the test results of the code file.

[0082] Based on the first embodiment of the present application, a second embodiment of the present application is proposed. In the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction and will not be repeated later.

[0083] On this basis, please refer to Figure 2 , step S20 includes steps S201 to S204:

[0084] Step S201: Read the script content in the target source code file;

[0085] Step S202: parsing the script content to determine whether the script content requires input parameters;

[0086] Step S203: If the script content requires input parameters, then select or determine branch functions corresponding to different input parameters, and determine the method or command to be called according to the branch functions;

[0087] Step S204: If the script content does not require input parameters, a target function is determined according to the script content, and the method or command to be called is determined according to the target function.

[0088] Reference Figure 3 , Figure 3 This is a schematic diagram of the overall processing flow according to the second embodiment of the present application, as shown in FIG. Figure 3As shown, a test case generation tool is provided in an embodiment of the present application, and the tool mainly includes three modules: a file reading module, a file parsing module, and a case generation module. After the user imports the target source code file (such as a shell script file) into the test case generation tool, the test case generation tool performs file format verification on the target source code file and makes a comprehensive judgment based on the format verification and syntax verification results. If the format verification passes and the syntax verification finds no errors, the file is considered to meet the requirements; otherwise, the file is considered to not meet the requirements. If the file meets the requirements, the target source code file can be further parsed.

[0089] Reference Figure 4 , Figure 4 This is a schematic diagram of the code parsing process according to the second embodiment of the present application. Figure 4 As shown, in the embodiment of the present application, the script content in the target source code file read is subjected to parameter parsing to determine whether the script content needs to input parameters (i.e., input parameters). Exemplary, the file reading function provided by the programming language (such as the open() function in Python) is used to directly read the file content. This approach is simple and direct and is applicable to most common file systems and script file formats. In Unix-like systems, command line tools (such as cat, sed, awk, etc.) can be used to read file content and pass the content to subsequent processing programs through pipelines or redirections. This approach may be more efficient when processing large files or complex file formats.

[0090] Exemplary, parameter parsing is mainly based on the grammatical and semantic analysis of the script content. By identifying the grammatical structure for receiving input parameters in the script (such as positional variables such as $1, $2 in Shell scripts or getopts option parsing tools), it is determined whether the script needs input parameters. In the embodiment of the present application, regular expressions are used to match the parameter reference pattern in the script content, or the grammatical structure of the script is analyzed using an abstract syntax tree (AST) to identify the position of parameter definition and use. By writing regular expressions to match the parameter reference pattern (such as $1, $2, etc.) in the script. This method is simple and efficient and is applicable to parameter parsing of most Shell scripts. The abstract syntax tree of the script is generated using a static analysis tool, and the tree nodes are traversed to identify parameter definition and use. This method is more accurate and can handle complex script logic and grammatical structure. Combining regular expression matching and abstract syntax tree analysis can improve the accuracy and robustness of parameter parsing. Regular expressions can quickly identify common parameter reference patterns, and abstract syntax tree analysis can handle complex parameter definitions and usage scenarios.

[0091] For example, based on determining that the script requires input parameters, the script content is further analyzed to identify the branch functions corresponding to different input parameters, and determine the corresponding methods or commands to be called. This helps to deeply understand the behavioral logic of the script and provide support for generating accurate test cases. Based on the syntax and logical structure analysis of the script content, conditional statements (such as if, case, etc.) and function calls are identified to determine the mapping relationship between input parameters and branch functions. Determine the branch functions and methods or commands to be called corresponding to different input parameters in the script in order to generate test cases covering all functional scenarios.

[0092] Exemplarily, the step of determining the method or command to be called according to the branch function or the target function includes:

[0093] Matching the method or command corresponding to the branch function or target function through an associative array and / or a pre-configured file;

[0094] The methods or commands corresponding to the branch functions or target functions are sorted based on a preset calling logic to determine the method or command to be called.

[0095] For example, by analyzing the conditional statements and function calls in the script, a mapping relationship between input parameters and branch functions is established. These mapping relationships can be stored in an associative array or configuration file so that subsequent steps can quickly find and use them. By analyzing conditional statements such as if and case in the script, it is determined how the input parameters affect the script's execution flow. This method is applicable to most scripting languages ​​and can effectively identify branch functions. By analyzing the function calls in the script, the relationship between input parameters and function calls is determined. This method is more effective when processing modular scripts and can accurately identify function calls corresponding to different input parameters. Combining conditional statement analysis and function call analysis can comprehensively identify branch functions and methods or commands to be called in the script. Conditional statement analysis can help identify the logical branches of the script, while function call analysis can further determine the specific execution operations, helping to generate complete and accurate test cases that cover all functional scenarios of the script and ensure the stability and reliability of the script.

[0096] This embodiment adopts the above scheme, specifically by reading the script content in the target source code file; performing parameter parsing on the script content to determine whether the script content requires input parameters; if the script content requires input parameters, then selecting or determining the branch functions corresponding to different input parameters, and determining the method or command to be called according to the branch functions; if the script content does not require input parameters, then determining the target function according to the script content, and determining the method or command to be called according to the target function, by analyzing the script content to determine whether the script requires input parameters, this is a key step in understanding the script function and behavior, because input parameters usually significantly affect the execution logic and output results of the script. On the basis of determining that the script requires input parameters, the script content is further analyzed to identify the branch functions corresponding to different input parameters. For the script content that does not require input parameters, the overall logic and code structure of the script are analyzed to determine its target function and the corresponding method or command to be called, and the corresponding method or command to be called is determined, which helps to generate accurate test cases.

[0097] Based on any of the above embodiments of this application, a third embodiment of this application is proposed. In the third embodiment of this application, the same or similar contents as any of the above embodiments can be referred to the above introduction and will not be described in detail later. Figure 5 , step S30 includes steps S301 to S302:

[0098] Step S301: calling the methods or commands to be called one by one through a loop structure, and recording the judgment conditions, operation steps and output results corresponding to the methods or commands to be called;

[0099] Step S302: Fill in a preset test case template according to the determination conditions, operation steps and output results corresponding to the method or command to be called, and obtain a test case corresponding to the target source code file.

[0100] Exemplarily, in the embodiment of the present application, a loop structure (such as a for loop, a while loop) of a programming language is used to traverse all methods or commands to be called. In each iteration, the corresponding method or command is called, and variables or data structures are used to record the judgment conditions, operation steps and output results. A basic loop structure can be used to call methods or commands in sequence and record the results. Suitable for test case generation of small scripts or simple functions. Conditional judgments can also be added to the loop structure to adjust the subsequent call logic according to the execution results of the method or command. Suitable for complex scripts that need to dynamically adjust the test process.

[0101] For example, judgment conditions refer to conditions that affect the execution process of a method or command, such as the value of an input parameter or the existence of a file. Operation steps refer to the specific steps involved in calling a method or command, including parameter passing and command execution. Output results refer to the results of executing a method or command, which can be a return value, success, or failure. The recorded judgment conditions, operation steps, and output results are integrated into a complete test case. The collected information is organized into test cases in a structured manner for subsequent test execution and verification.

[0102] For example, in an embodiment of the present application, based on data organization and template filling technology, the recorded judgment conditions, operation steps, and output results can be organized according to a certain template or structure to generate standardized test cases. By designing a test case template, the recorded information is filled into the template. This is suitable for situations where the test case format is fixed, and the generated test cases are standardized and unified. Scripts or tools can also be used to automatically generate test cases based on the recorded information. This is suitable for situations where the test case format needs to be flexibly adjusted, and the generated test cases can be dynamically adjusted according to needs.

[0103] Reference Figure 6 , Figure 6 This is a test case diagram according to the third embodiment of the present application, as shown in FIG. Figure 6 As shown, in the embodiment of the present application, the function of updating the ssh configuration file is used as an example to illustrate. This function also supports the rollback operation after the update. After importing the target source code file into the test case generation tool, the test case generation tool performs file verification on the target source code file. When the target source code file passes the file verification, the target source code file is parsed to determine the method or command to be called, and the test case corresponding to the target source code file is generated based on the method or command to be called. It is presented in a table form, including case number, test name, step description and expected result. The case number can be sorted in the order of execution of the method or command, and the test name is the corresponding method or command to be executed. The method or command corresponding to the function of updating the ssh configuration file can include ssh configuration update, setting result success or failure, input parameter update, environment check and rollback operation, etc. Different test names can correspond to a series of step descriptions, and can also correspond to a series of expected results, such as ssh configuration file backup success, ssh configuration file update success, rollback after update success and output help information success, etc.

[0104] Exemplarily, after calling the methods or commands to be called one by one through a loop structure and recording the determination conditions, operation steps, and output results corresponding to the methods or commands to be called, the following steps are further included:

[0105] Determine each branch path according to the input parameters, corresponding branch functions or target functions used in the calling process of the method or command to be called;

[0106] Paths are listed according to the branch paths to generate a full test path diagram, wherein the full test path diagram is used to adjust the test cases corresponding to the target source code file.

[0107] For example, by analyzing the method or command to be called and its input parameters, combined with the script's branching or target functions, all possible execution paths of the script can be determined. This is key to understanding script behavior and generating comprehensive test cases, as different branching paths represent different script behaviors under different conditions. Script-based control flow analysis and data flow analysis analyze the script's grammatical structure and logical flow to identify the method or command call location, call conditions, and parameter usage, thereby inferring the script's branching paths.

[0108] For example, the script's syntax is first parsed to identify the definition and call locations of methods or commands. The parameter list and branching logic of the method or command are then analyzed. Combined with the possible value ranges of the input parameters, the script's execution flow under different conditions is determined. Finally, a branching path graph is constructed based on this information.

[0109] Exemplarily, in an embodiment of the present application, each branch path can be determined by static code analysis or dynamic debugging tools. For example, by scanning the script code, the definition, parameter list and branch statement of the method or command can be identified. This method can quickly discover the potential branch paths of the script without running the script, which is suitable for preliminary analysis of the script and path identification of simple logic; use a debugger to run the script to track the calling process and actual execution path of the method or command. This method can observe the actual behavior of the script under different input parameters, which helps to discover hidden branch logic and dynamic behavior. Combining static code analysis and dynamic debugging can fully identify the branch paths of the script. Static analysis can quickly build a path model, and dynamic debugging can verify and supplement the accuracy of the model, thereby generating a complete branch path list.

[0110] Reference Figure 7 , Figure 7 This is a schematic diagram of a full test path diagram according to the third embodiment of the present application, as shown in FIG. Figure 7As shown, based on control flow graph theory, the script's branch paths are converted into a graph structure. Each node represents a method or command call, and each edge represents the transition relationship between branch conditions. By traversing the control flow graph, a full test path graph is generated. Specifically, the control flow graph is constructed by collecting information about all branch paths in the script. A graph layout algorithm is then used to convert the control flow graph into an intuitive full test path graph, providing interactive features to facilitate tester adjustments.

[0111] For example, by systematically listing the identified branch paths and converting them into an intuitive full-test path diagram, a basis is provided for adjusting and optimizing test cases. This helps testers identify missing parts of test cases, optimize test case design, and ensure that all functional scenarios are effectively covered. This provides an intuitive way to display all execution paths of the script, helping testers identify missing parts of test cases, optimize test case design, and improve test coverage and efficiency.

[0112] It should be noted that the above examples are only used to understand this application and do not constitute a limitation on the test case generation method of this application. More simple transformations based on this technical concept are all within the scope of protection of this application.

[0113] This application also provides a test case generation device, please refer to Figure 8 , the test case generating device includes:

[0114] A response module 10 is configured to perform file verification on the target source code file in response to receiving the target source code file;

[0115] The parsing module 20 is used to parse the target source code file and determine the method or command to be called when the target source code file passes the file verification;

[0116] The generating module 30 is configured to generate a test case corresponding to the target source code file based on the method or command to be called.

[0117] The test case generation device mainly performs the following steps:

[0118] The first step is to import the shell script and perform file format verification on the shell script file;

[0119] The second step is to perform a simple syntax check on the imported shell script to ensure that the script can be run, and then parse it based on the shell language syntax rules;

[0120] The third step is to parse the syntax based on the second step, and gradually list the different branches of the code in the order of code execution, and supplement the input conditions and output results required for each branch (for example, if a piece of code contains an if-else structure, then it is necessary to clearly indicate the corresponding operation steps and their results when the judgment condition is true or false), and finally generate the execution process logic diagram of the source code file and the corresponding test cases.

[0121] This application develops a shell script source code case generator. By importing a single shell script source code file, the application generates a visual logic diagram and test cases with one click. The advantage is that once the script source code is available, users can visualize the script's branching logic, accelerating their understanding of the script's functionality. This also allows for test case generation, improving test design efficiency and accuracy.

[0122] The test case generation device provided in this application utilizes the test case generation method of the aforementioned embodiment to solve the technical problem of test case generation. Compared to the prior art, the beneficial effects of the test case generation device provided in this application are the same as those of the test case generation method provided in the aforementioned embodiment. Other technical features of the test case generation device are the same as those disclosed in the aforementioned embodiment and are not further elaborated here.

[0123] The present application provides a test case generation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the test case generation method in the above-mentioned embodiment 1.

[0124] Reference below Figure 9 , which shows a schematic diagram of the structure of a test case generation device suitable for implementing the embodiments of the present application. The test case generation device in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 9 The test case generation device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.

[0125] like Figure 9As shown, the test case generation device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on programs stored in a read-only memory 1002 or programs loaded from a storage device 1003 into a random access memory 1004. The random access memory 1004 also stores various programs and data required for the operation of the test case generation device. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other via a bus 1005. An input / output interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. Communication device 1009 can allow the test case generation device to communicate with other devices wirelessly or wired to exchange data. Although the figure shows a test case generation device with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems can be implemented or provided instead.

[0126] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are performed.

[0127] The test case generation device provided in this application utilizes the test case generation method of the aforementioned embodiment to solve the technical problems associated with test case generation. Compared to the prior art, the beneficial effects of the test case generation device provided in this application are the same as those of the test case generation method provided in the aforementioned embodiment. Other technical features of the test case generation device are the same as those disclosed in the aforementioned embodiment and are not further elaborated here.

[0128] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0129] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

[0130] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer program) stored thereon, and the computer-readable program instructions are used to execute the test case generation method in the above embodiment.

[0131] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0132] The computer-readable storage medium may be included in the test case generating device; or may exist independently without being assembled into the test case generating device.

[0133] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the test case generation device, the test case generation device: performs file verification on the target source code file in response to receiving the target source code file; when the target source code file passes the file verification, performs code parsing on the target source code file to determine the method or command to be called; generates a test case corresponding to the target source code file based on the method or command to be called, without relying on the experience of the tester. The target source code file that passes the file verification is parsed to determine the method or command to be called, and the corresponding test case is generated according to the method or command to be called, which can improve the efficiency, completeness and flexibility of generating test cases, thereby improving the accuracy of the test results of the code file.

[0134] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0135] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.

[0136] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.

[0137] The computer-readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described test case generation method, thereby resolving the technical problem of test case generation. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the test case generation method provided in the above-described embodiment, and are not further elaborated here.

[0138] The present application also provides a computer program product, including a computer program, which implements the steps of the test case generation method as described above when the computer program is executed by a processor.

[0139] The computer program product provided in this application can solve the technical problem of test case generation. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the test case generation method provided in the above embodiment, and will not be repeated here.

[0140] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A test case generation method, characterized in that: The method comprises: In response to receiving the target source code file, performing file verification on the target source code file; If the target source code file passes the file verification, performing code parsing on the target source code file to determine the method or command to be called; Generate a test case corresponding to the target source code file based on the method or command to be called.

2. The test case generation method according to claim 1, wherein: The step of performing file verification on the target source code file includes: Performing format verification on the target source code file to determine whether the target source code file is in the target format; If the target source code file is in a target format, performing syntax check on the target source code file to determine whether the target source code file has syntax errors or logical anomalies; If the target source code file does not have any syntax errors or logic anomalies, it is determined that the target source code file passes the file verification.

3. The test case generation method according to claim 1, wherein: The step of parsing the target source code file to determine the method or command to be called includes: Read the script content in the target source code file; Perform parameter parsing on the script content to determine whether the script content requires input parameters; If the script content requires input parameters, then select or determine branch functions corresponding to different input parameters, and determine the method or command to be called according to the branch functions; If the script content does not require input parameters, the target function is determined according to the script content, and the method or command to be called is determined according to the target function.

4. The test case generation method according to claim 3, wherein: The step of determining the method or command to be called according to the branch function or the target function includes: Matching the method or command corresponding to the branch function or target function through an associative array and / or a pre-configured file; The methods or commands corresponding to the branch functions or target functions are sorted based on a preset calling logic to determine the method or command to be called.

5. The test case generation method according to claim 1, wherein: The step of generating a test case corresponding to the target source code file based on the method or command to be called includes: Call the methods or commands to be called one by one through a loop structure, and record the judgment conditions, operation steps and output results corresponding to the methods or commands to be called; The preset test case template is filled in according to the determination conditions, operation steps and output results corresponding to the method or command to be called to obtain the test case corresponding to the target source code file.

6. The test case generation method according to claim 5, wherein: After the step of calling the methods or commands to be called one by one through a loop structure and recording the determination conditions, operation steps and output results corresponding to the methods or commands to be called, the following steps are further included: Determine each branch path according to the input parameters, corresponding branch functions or target functions used in the calling process of the method or command to be called; Paths are listed according to the branch paths to generate a full test path diagram, wherein the full test path diagram is used to adjust the test cases corresponding to the target source code file.

7. A test case generating device, characterized in that: The device comprises: A response module, configured to perform file verification on the target source code file in response to receiving the target source code file; A parsing module, configured to parse the target source code file and determine a method or command to be called if the target source code file passes file verification; A generation module is used to generate a test case corresponding to the target source code file based on the method or command to be called.

8. A test case generating device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the test case generation method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the test case generation method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the test case generation method according to any one of claims 1 to 6 are implemented.