Method for automatically generating test case and related product
By parsing ARXML files and unit test case documents and automatically filling in test case templates, the problem of low-efficiency test case generation in the existing technology is solved, and more efficient test case generation is achieved.
Patent Information
- Application Number
- CN202411150355.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-13
AI Technical Summary
The existing test case generation methods are inefficient, especially when the number of model component interfaces is huge, it requires a large number of manual input interface values, resulting in very low test case generation efficiency.
By obtaining ARXML files, model files and unit test case documents, extracting interface name, data type and execution step information, parsing and automatically filling in test case templates, and generating test case files.
It improves the efficiency of test cases generation, reduces the time of manual configuration and addition, and improves the efficiency of test cases generation.
Smart Images

Figure CN119127682A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to a method for automatically generating test cases and related products. Background Art
[0002] With the development of computer technology, the number of development projects for various model components has gradually increased. In order to ensure that they can work as expected and meet safety standards, it is usually necessary to thoroughly test each part of the model component.
[0003] The existing test case generation method is usually based on BTC Embedded Platform (embedded platform). When offline, technicians need to first make a detailed design for the functional test of the model, form a unit test document, and then manually enter the value of each interface into the test case file one by one according to the document description. In this way, when the number of interfaces is huge, a lot of manpower will be consumed, resulting in a very low test case generation efficiency.
[0004] Therefore, how to improve the efficiency of generating test cases is a problem that technical personnel in this field need to solve urgently. Summary of the invention
[0005] Based on the above problems, the present application provides a method and related products for automatically generating test cases, which obtains relevant data through file parsing and automatically fills it into the test case template, thereby improving the efficiency of test case generation.
[0006] In a first aspect, an embodiment of the present application provides a method for automatically generating test cases, comprising:
[0007] Obtain an ARXML file, a model file, and a unit test case document corresponding to the model file;
[0008] Extracting the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name from the model file;
[0009] Extracting custom data type information from the ARXML file;
[0010] Parse the unit test case document to obtain the interface value and execution step information corresponding to the interface name;
[0011] The test case template is improved based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and a test case file is obtained.
[0012] Optionally, before parsing the unit test case document, the process further includes:
[0013] Performing a format check on the unit test case document and obtaining a check result;
[0014] If the inspection result meets the preset rules, a correct prompt is returned;
[0015] If the inspection result does not meet the preset rules, the inspection result is output and an error prompt is returned.
[0016] Optionally, the format checking of the unit test case document includes:
[0017] The unit test case document is checked for step format correctness, interface naming rule, consistency between interface dimension and interface value number, and out-of-range check of interface value.
[0018] Optionally, the interface value out-of-range check includes:
[0019] It is determined whether the interface value corresponding to each interface is between the upper and lower limit values specified by the interface data type corresponding to the respective interface.
[0020] Optionally, extracting the custom data type information from the ARXML file includes:
[0021] Determine a structure corresponding to the model component based on the interface name and the interface data type;
[0022] Get the dimensions of all member variables in the structure;
[0023] Based on the dimension, obtain the name, data type and dimension information corresponding to each member variable.
[0024] Optionally, parsing the unit test case document to obtain an interface value and execution step information corresponding to the interface name includes:
[0025] Parse the unit test case document and obtain execution step information corresponding to the interface name;
[0026] According to the interface naming rules, extract all interface names recorded in the unit test case document;
[0027] All interface names recorded in the unit test case document are compared with the interface names corresponding to the model components to be tested, and interface values corresponding to each interface name are obtained based on the interface data type.
[0028] Optionally, before improving the test case template based on the interface name, the interface data type, the custom data type information, the interface value, and the execution step information, the method further includes:
[0029] Generate test case templates based on the test case format.
[0030] In a second aspect, an embodiment of the present application provides a device for automatically generating test cases, including:
[0031] An acquisition module is used to acquire an ARXML file, a model file, and a unit test case document corresponding to the model file;
[0032] A first extraction module, used to extract the interface name and interface data type corresponding to the model component from the model file;
[0033] A second extraction module, used to extract custom data type information from the ARXML file;
[0034] A parsing module, used to parse the unit test case document to obtain the interface value and execution step information corresponding to the interface name;
[0035] A generation module is used to improve the test case template based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and obtain a test case file.
[0036] In a third aspect, an embodiment of the present application provides a device for automatically generating test cases, including:
[0037] Memory for storing computer programs;
[0038] A processor is used to implement the steps of the method for automatically generating test cases as described above when executing the computer program.
[0039] In a fourth aspect, an embodiment of the present application provides a readable storage medium, characterized in that a computer program is stored on the readable storage medium, and when the computer program is executed by a processor, the steps of the method for automatically generating test cases as described above are implemented.
[0040] It can be seen from the above technical solutions that compared with the prior art, the present application has the following advantages:
[0041] This application first obtains an ARXML file, a model file, and a unit test case document corresponding to the model file. Then, the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name are extracted from the model file, and the custom data type information is extracted from the ARXML file. Finally, the unit test case document is parsed to obtain the interface value and execution step information corresponding to the interface name, and the test case template is improved based on the interface name, interface data type, custom data type information, interface value, and execution step information, and a test case file is obtained. In this way, relevant data is obtained through file parsing and automatically filled into the test case template, thereby improving the efficiency of test case generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A flowchart of a method for automatically generating test cases provided in an embodiment of the present application;
[0043] Figure 2 A flowchart of a document parsing method provided in an embodiment of the present application;
[0044] Figure 3 A schematic diagram of the configuration flow of a test case template provided in an embodiment of the present application;
[0045] Figure 4 An overall configuration flow chart provided for an embodiment of the present application;
[0046] Figure 5 A schematic diagram of the structure of a device for automatically generating test cases provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] As mentioned above, the existing test case generation method has the problem of low efficiency. Specifically, BTCEmbeddedPl atform provides two test case generation methods, one is to add and modify test cases online, and the other is to modify and generate test cases offline and import them into the software for execution. Especially for the offline method, it is necessary to first make a detailed design of the functional test of the model, form a unit test case document, and then manually enter the value of each interface into the test case one by one according to the document description. However, with the development of science and technology, the scale of model components is getting larger and larger. Each model may involve dozens or even hundreds of interfaces, and each model corresponds to dozens or even dozens of test cases. Each test case needs to execute many steps, and each step requires manual adjustment of the value of each interface, which makes the labor consumption very large, resulting in the problem of low efficiency of test case generation.
[0048] To solve the above problems, an embodiment of the present application provides a method for automatically generating test cases. First, an ARXML file, a model file, and a unit test case document corresponding to the model file are obtained. Then, the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name are extracted from the model file, and the custom data type information is extracted from the ARXML file. Finally, the unit test case document is parsed to obtain the interface value and execution step information corresponding to the interface name, and the test case template is improved based on the interface name, interface data type, custom data type information, interface value, and execution step information, and a test case file is obtained.
[0049] In this way, the interface name, interface data type, custom data type information, interface value and execution step information involved in the model component to be tested are obtained through file parsing and automatically filled into the test case template, which solves the problem of time-consuming manual configuration and addition and improves the efficiency of test case generation.
[0050] It should be noted that the method for automatically generating test cases and related products provided in the embodiments of the present application can be applied to the field of software testing technology. The above is only an example and does not limit the application field of the method for automatically generating test cases and related products provided in the present application.
[0051] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0052] Figure 1 A flowchart of a method for automatically generating test cases provided in an embodiment of the present application. Figure 1 As shown, a method for automatically generating test cases provided by an embodiment of the present application may include:
[0053] S101: Obtain an ARXML file, a model file, and a unit test case document corresponding to the model file.
[0054] In practical applications, BTC Embedded Pl atform provides tools to realize the generation of test cases. In order to solve the problem of low efficiency in the above-mentioned offline generation of test cases, the embodiment of the present application provides a test case generation tool, which generates test cases (cases) in batches by automatically parsing unit test case documents, and solves the problem of manual creation and modification of test cases that takes too long. Specifically, the test case generation tool first obtains the ARXML file, model file and unit test case document corresponding to the model file input by the staff. ARXML (AUTOSARXML) file is a file format based on XML (Extensible Markup Language) defined in the AUTOSAR (Automotive Open System Architecture, automotive open system architecture) standard, which is used to describe the heavier elements of automotive electronic software systems, including software components, interfaces, data types and configuration parameters. The model file (MATLAB Simulink slx file) is a file that describes the model component to be tested, which contains the interface information corresponding to the model component to be tested. The unit test case document is a set of documents including test input, execution conditions and expected results written by technicians to find problems in the model component, corresponding to the model component to be tested. A complete unit test case document usually includes elements such as case number, functional module, case title, test type, prerequisites, input data, test steps, expected results, actual results, priority and test results.
[0055] S102: Extracting, from the model file, an interface name corresponding to the model component to be tested and an interface data type corresponding to the interface name.
[0056] In practical applications, the essence of testing model components is to input data into the model components and check whether the output of the model components meets the standards. Therefore, it is necessary to clarify all interface information contained in the model components to be tested. Specifically, after the test case generation tool obtains the ARXML file, the model file, and the unit test case document corresponding to the model file, the test case generation process is triggered, the model file is parsed, and all interface information corresponding to the model component to be tested indicated by the model file is extracted. The interface information includes the interface name corresponding to each input and output interface, and the interface data type corresponding to each interface. Among them, the interface data type can include basic types, array types, and custom data (structure) types, etc.
[0057] S103: Extracting user-defined data type information from the ARXML file.
[0058] In actual applications, the basic data type information corresponding to the model component to be tested can be directly parsed and obtained from the unit test case document, while the record format of the custom data type information in the unit test case document is different from the standard record. Therefore, it is necessary to extract the custom data type information corresponding to the model component to be tested from the ARXML file. Specifically, the custom data type information includes the dimensions of the structure member variables, as well as the name, data type and dimension of each member variable.
[0059] In addition, since the methods for obtaining the custom data type information are not the same, the embodiment of the present application can illustrate a possible acquisition method.
[0060] In one case, S103: extracting the user-defined data type information from the ARXML file may specifically include:
[0061] Determine a structure corresponding to the model component based on the interface name and the interface data type;
[0062] Get the dimensions of all member variables in the structure;
[0063] Based on the dimension, obtain the name, data type and dimension information corresponding to each member variable.
[0064] In practical applications, the test case generation tool can extract the interface names corresponding to all input and output interfaces from the model file and determine the interface data types corresponding to each interface name to generate a table record. Then, the test case generation tool can filter out the custom data types from all interface data types corresponding to the model components to be tested, and list the names corresponding to all custom data types to generate a custom data type (structure) name list. In this way, the ARXML file is loaded into the MATLAB workspace, and the exist function is used to determine whether all the custom data types involved are recorded in the ARXML file, such as exist('Variable_Struct','var'). If not all are included, feedback is given to the technician; if all are included, the dimensions of the structure member variables are first obtained through the Variable_Struct.Elements function, and finally the name, data type and dimension information of each member variable are obtained through the Name, DataType and Dimensions functions, such as: Variable_Struct.Elements(n).Name, Variable_Struct.Elements(n).DataType, Variable_Struct.Elements(n).Dimensions.
[0065] S104: Parse the unit test case document to obtain interface values and execution step information corresponding to the interface names.
[0066] In practical applications, the unit test case document is written by a technician, including test input, execution conditions and expected results, etc., for discovering problems in the model component. In an embodiment of the present application, the test case generation tool parses the unit test case document to obtain the interface value corresponding to the interface name and the execution step information. For example, the model component includes three interfaces, the interface names are A, B and C, and the unit test case document records that the A interface needs to input values d, e and f for testing, and the execution step is to first input e, then input f and finally input d, then for the test case generation tool, it parses the unit test case document, first determines the A corresponding to the interface name, then obtains the interface value (d, e, f) corresponding to the interface name A, and the execution step information (the first step inputs e, the second step inputs f, and the third step inputs d).
[0067] In addition, since the parsing methods of unit test case documents are not the same, the embodiment of the present application can illustrate a possible parsing method.
[0068] In one case, S104: parsing the unit test case document to obtain the interface value and execution step information corresponding to the interface name can be specifically used for:
[0069] Parse the unit test case document and obtain execution step information corresponding to the interface name;
[0070] According to the interface naming rules, extract all interface names recorded in the unit test case document;
[0071] All interface names recorded in the unit test case document are compared with the interface names corresponding to the model components to be tested, and interface values corresponding to each interface name are obtained based on the interface data type.
[0072] Figure 2 A flowchart of a document parsing method provided in an embodiment of the present application. Figure 2As shown, the test case generation tool can parse the execution step step of the unit test case document to obtain the execution step information corresponding to the interface name involved in the model component to be tested. Specifically, step can be the nth step or m steps added on the current basis. Then, according to the interface naming rules, the interface information (all the interface names involved) is extracted from the unit test case document, and compared with the interface name corresponding to the model component to be tested extracted from the model file. If it is a basic type interface, the value after the equal sign is obtained as the interface value corresponding to the interface name, such as port_name=0, and 0 is taken; if it is an array type interface, the array dimension description information after the interface name is obtained, and then the corresponding values after the equal sign are expanded and extracted as the interface value corresponding to the interface name, such as port_name(2:4)=[2,3,4], which are expanded as follows: port_name(2)=2, port_name(3)=3, port_name e(4)=4, take 2, 3 and 4 respectively and correspond to the interface name; if it is a structure type interface, get the structure member description information after the interface name, and then extract the value after the equal sign as the value corresponding to the interface. If there is no description information, that is, all member variables are the same value, just expand them separately and take the corresponding value after the equal sign as the interface value corresponding to the interface name, such as port_name_struct=10, after expansion, it is port_name_struct.temperature=10, port_name_struct.voltage=10 and port_name_struct.current=10. If the member variable name is specified, directly extract the member variable value after the equal sign, such as: port_name_struct.temperature=11, take 11 as the interface value corresponding to the interface name.
[0073] In addition, since the preprocessing methods before parsing the unit test case document are not the same, the embodiment of the present application can illustrate a possible preprocessing method.
[0074] In one embodiment, before parsing the unit test case document, the method further includes:
[0075] Performing a format check on the unit test case document and obtaining a check result;
[0076] If the inspection result meets the preset rules, a correct prompt is returned;
[0077] If the inspection result does not meet the preset rules, the inspection result is output and an error prompt is returned.
[0078] In practical applications, because the unit test case document is written by a technician, the integrity of its content is closely related to the experience of the technician, and errors often occur. Therefore, the test case generation tool provided in the embodiment of the present application also adds a format check function, which can perform a format check on the unit test case document and obtain the inspection result. If there is no error (the inspection result meets the preset rules), the test case will continue to be generated and the correct prompt will be returned; if there is an error (the inspection result does not meet the preset rules), an error will be reported, and the inspection result of the error will be fed back to the technician, and an error prompt will be returned.
[0079] In addition, since the formats checking methods are not the same, the embodiments of the present application can illustrate a possible format checking method.
[0080] In one embodiment, the format checking of the unit test case document includes:
[0081] The unit test case document is checked for step format correctness, interface naming rule, consistency between interface dimension and interface value number, and out-of-range check of interface value.
[0082] In actual applications, the test case generation tool can check the correctness of the step format of the unit test case document. If it contains the start step and the end step, it means that the check result meets the preset rules and the prompt "OK" is fed back; if it does not, it means that the check result does not meet the preset rules, outputs relevant information about the check failure, and feeds back the prompt "Error". The test case generation tool can also check the interface naming rules in the unit test case document. If the name starts with uppercase and lowercase letters "AZ / az" or underscore "_", followed by a combination of 0 or more letters, underscores and numbers (0-9), it means that the check result meets the preset rules and the prompt "OK" is fed back; if not, it means that the check result does not meet the preset rules, outputs relevant information about the check failure, and feeds back the prompt "Error". The test case generation tool can also check the consistency of the interface dimension and the number of interface values in the unit test case document. If it is a basic data type interface, the equal sign should be followed by a value. If it is an array variable or a structure variable, the interface dimension described before the equal sign should be consistent with the number of values after the equal sign. In this way, if they are consistent, it means that the inspection result meets the preset rules, and an "OK" prompt is fed back; if not, it means that the inspection result does not meet the preset rules, relevant information about the inspection failure is output, and an "Error" prompt is fed back. In addition, the test case generation tool can also check whether the interface value in the unit test case document is out of range. If it is not out of range, it means that the inspection result meets the preset rules, and an "OK" prompt is fed back; if not, it means that the inspection result does not meet the preset rules, relevant information about the inspection failure is output, and an "Error" prompt is fed back. In this way, when all the above checks are passed, the subsequent test case generation process will continue; if not all pass, all error information will be output to the document for technical personnel to refer to.
[0083] In addition, since the methods for checking whether the interface value is out of range are different, the embodiment of the present application can illustrate a possible checking method.
[0084] In one embodiment, the interface value out-of-range check includes:
[0085] It is determined whether the interface value corresponding to each interface is between the upper and lower limit values specified by the interface data type corresponding to the respective interface.
[0086] In practical applications, the test case generation tool needs to check whether the interface value in the unit test case document is out of range. Specifically, each input and output interface in the model component to be tested has its unique corresponding interface name, and the test case generation tool can determine the interface data type corresponding to each interface name from the model file. Since the interface values specified by different interface data types are different, and have corresponding upper and lower limits that can be input. Therefore, the test case generation tool can parse the unit test case document, determine the interface name corresponding to the interface name involved in the model component to be tested from the unit test case document, and then based on the correspondence between the interface name and the interface data type, respectively determine whether the interface value corresponding to each interface is between the upper and lower limits specified by the interface data type corresponding to each interface. If so, it indicates that the inspection result meets the preset rules, and feedback "OK" prompts; if not, it indicates that the inspection result does not meet the preset rules, outputs relevant information of the inspection failure, and feedbacks "Error" prompts.
[0087] S105: Perfect the test case template based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and obtain a test case file.
[0088] In actual applications, the test case file corresponding to the model component to be tested should clearly indicate the specific test process of the model component to be tested. For example, what kind of interface value needs to be input for a certain interface involved in the model component to be tested and what kind of test steps need to be executed. Therefore, it is necessary to fill the interface name, interface data type, custom data type information, interface value and execution step information related to the model component to be tested extracted from the ARXML file, model file and unit test case document into the test case template, so as to generate test case files in batches.
[0089] In addition, since the methods of generating test case templates are different, the embodiments of the present application can illustrate a possible generation method.
[0090] In one case, before the test case template is improved based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, the method further includes:
[0091] Generate test case templates based on the test case format.
[0092] Figure 3 A schematic diagram of the configuration flow of a test case template provided in an embodiment of the present application. Figure 3As shown, the test case generation tool can generate a test case template based on the test case format. First, the fixed format content is configured for the test case, including "Format Version", "Architecture", "Scope", "Name", "Mode" and "Step". Then the basic data type interface name, array type interface name and structure type interface name are configured. Among them, for the configuration of the array type interface name, the test case generation tool can expand the array type interface according to the array dimension and configure it to the specified position respectively, such as: port_name(1), port_name(2), port_name(n), etc.; for the configuration of the structure type interface name, the test case generation tool can expand the structure type interface according to the member variable information and configure it to the specified position respectively, such as: port_name.temperature, port_name.voltage, port_name.current, etc.
[0093] In summary, Figure 4 An overall configuration flow chart provided for an embodiment of the present application. Figure 4 As shown, the use of the test case generation tool to generate test samples first requires initialization configuration, and imports ARXML files, slx files (MATLABSimulink slx, model files) and corresponding unit test case documents. Then, through file parsing, the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name are extracted from the model file, and the custom data type information is extracted from the ARXML file. The unit test case document needs to be formatted before use, such as step format check, interface naming rule check, structural dimension and number of numerical consistency check, and interface numerical value out-of-range check. If the check is not passed in full, the check failure information is output to the document and the process is terminated; if the check is passed in full, the test case generation process is continued. The test case generation tool continues to parse the unit test case document, obtains the interface value corresponding to the interface name and the execution step information, and generates a test case case template based on the test case format. Finally, the relevant data is input into the test case case template, batches of test case case files are generated, and the process is terminated.
[0094] In summary, the present application first obtains an ARXML file, a model file, and a unit test case document corresponding to the model file. Then, the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name are extracted from the model file, and the custom data type information is extracted from the ARXML file. Finally, the unit test case document is parsed to obtain the interface value and execution step information corresponding to the interface name, and the test case template is improved based on the interface name, interface data type, custom data type information, interface value, and execution step information, and a test case file is obtained. In this way, relevant data is obtained through file parsing and automatically filled into the test case template, thereby improving the efficiency of test case generation.
[0095] Based on the method for automatically generating test cases provided in the above embodiment, the embodiment of the present application further provides a device for automatically generating test cases. The device for automatically generating test cases is described below in conjunction with the embodiments and drawings.
[0096] Figure 5 A schematic diagram of the structure of a device for automatically generating test cases provided in an embodiment of the present application. Figure 5 As shown, the apparatus 500 for automatically generating test cases provided in the embodiment of the present application includes:
[0097] An acquisition module 501 is used to acquire an ARXML file, a model file, and a unit test case document corresponding to the model file;
[0098] A first extraction module 502, used to extract the interface name and interface data type corresponding to the model component from the model file;
[0099] A second extraction module 503, used to extract user-defined data type information from the ARXML file;
[0100] A parsing module 504 is used to parse the unit test case document to obtain the interface value and execution step information corresponding to the interface name;
[0101] The generation module 505 is used to improve the test case template based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and obtain a test case file.
[0102] As an implementation method, with respect to how to pre-process the unit test case document, the above-mentioned apparatus 500 for automatically generating test cases further includes: a format checking module and a feedback module;
[0103] A format checking module, used to perform format checking on the unit test case document and obtain the checking result;
[0104] The feedback module is used to determine whether the inspection result meets the preset rules. If the inspection result meets the preset rules, a correct prompt is returned; if the inspection result does not meet the preset rules, the inspection result is output and an error prompt is returned.
[0105] As an implementation method, regarding how to perform format check on a unit test case document, the format check module is specifically used to:
[0106] The unit test case document is checked for step format correctness, interface naming rule, consistency between interface dimension and interface value number, and out-of-range check of interface value.
[0107] As an implementation method, how to perform an interface value out-of-range check on a unit test case document, the interface value out-of-range check includes:
[0108] It is determined whether the interface value corresponding to each interface is between the upper and lower limit values specified by the interface data type corresponding to the respective interface.
[0109] As an implementation manner, regarding how to extract the custom data type information from the ARXML file, the second extraction module 503 is specifically used to:
[0110] Determine a structure corresponding to the model component based on the interface name and the interface data type;
[0111] Get the dimensions of all member variables in the structure;
[0112] Based on the dimension, obtain the name, data type and dimension information corresponding to each member variable.
[0113] As an implementation manner, with respect to how to parse the unit test case document, the parsing module 504 is specifically used to:
[0114] Parse the unit test case document and obtain execution step information corresponding to the interface name;
[0115] According to the interface naming rules, extract all interface names recorded in the unit test case document;
[0116] All interface names recorded in the unit test case document are compared with the interface names corresponding to the model components to be tested, and interface values corresponding to each interface name are obtained based on the interface data type.
[0117] As an implementation method, with respect to how to obtain a test case template, the apparatus 500 for automatically generating a test case further includes: a generating submodule;
[0118] The generation submodule is used to generate test case templates based on the test case format.
[0119] In summary, the present application first obtains an ARXML file, a model file, and a unit test case document corresponding to the model file. Then, the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name are extracted from the model file, and the custom data type information is extracted from the ARXML file. Finally, the unit test case document is parsed to obtain the interface value and execution step information corresponding to the interface name, and the test case template is improved based on the interface name, interface data type, custom data type information, interface value, and execution step information, and a test case file is obtained. In this way, relevant data is obtained through file parsing and automatically filled into the test case template, thereby improving the efficiency of test case generation.
[0120] In addition, the present application also provides a device for automatically generating test cases, including:
[0121] Memory for storing computer programs;
[0122] A processor is used to implement the steps of the method for automatically generating test cases as described in any one of the above items when executing the computer program.
[0123] In addition, the present application also provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for automatically generating test cases as described in any of the above items are implemented.
[0124] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for automatically generating test cases, characterized in that: The method comprises: Obtain an ARXML file, a model file, and a unit test case document corresponding to the model file; Extracting the interface name corresponding to the model component to be tested and the interface data type corresponding to the interface name from the model file; Extracting custom data type information from the ARXML file; Parse the unit test case document to obtain the interface value and execution step information corresponding to the interface name; The test case template is improved based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and a test case file is obtained.
2. The method according to claim 1, characterized in that Before parsing the unit test case document, the method further includes: Performing a format check on the unit test case document and obtaining a check result; If the inspection result meets the preset rules, a correct prompt is returned; If the inspection result does not meet the preset rules, the inspection result is output and an error prompt is returned.
3. The method according to claim 2, characterized in that The format checking of the unit test case document includes: The unit test case document is checked for step format correctness, interface naming rule, consistency between interface dimension and interface value number, and out-of-range check of interface value.
4. The method according to claim 3, characterized in that The interface value out-of-range check includes: It is determined whether the interface value corresponding to each interface is between the upper and lower limit values specified by the interface data type corresponding to the respective interface.
5. The method according to claim 1, characterized in that The extracting the custom data type information from the ARXML file includes: Determine a structure corresponding to the model component based on the interface name and the interface data type; Get the dimensions of all member variables in the structure; Based on the dimension, obtain the name, data type and dimension information corresponding to each member variable.
6. The method according to claim 1, characterized in that The parsing of the unit test case document to obtain the interface value and execution step information corresponding to the interface name includes: Parse the unit test case document and obtain execution step information corresponding to the interface name; According to the interface naming rules, extract all interface names recorded in the unit test case document; All interface names recorded in the unit test case document are compared with the interface names corresponding to the model components to be tested, and interface values corresponding to each interface name are obtained based on the interface data type.
7. The method according to claim 1, characterized in that Before the test case template is improved based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, the test case template further includes: Generate test case templates based on the test case format.
8. A device for automatically generating test cases, characterized in that: include: An acquisition module is used to acquire an ARXML file, a model file, and a unit test case document corresponding to the model file; A first extraction module, used to extract the interface name and interface data type corresponding to the model component from the model file; A second extraction module, used to extract custom data type information from the ARXML file; A parsing module, used to parse the unit test case document to obtain the interface value and execution step information corresponding to the interface name; A generation module is used to improve the test case template based on the interface name, the interface data type, the custom data type information, the interface value and the execution step information, and obtain a test case file.
9. A device for automatically generating test cases, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for automatically generating test cases as claimed in any one of claims 1 to 7 when executing the computer program.
10. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for automatically generating test cases according to any one of claims 1 to 7 are implemented.
