Test case writing method and device, readable storage medium and electronic equipment
By automatically parsing source files and header files, obtaining and assigning function pointers, the flexibility problem of simulator test case management is solved, the complexity of test case writing is reduced, and the writing efficiency and code maintainability are improved.
Patent Information
- Application Number
- CN202510783903.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-06-12
AI Technical Summary
In the existing technology, instruction set simulator test case management lacks flexibility, test case writing is complex, and it is difficult to meet current needs.
By obtaining the file name in the specified file, extracting the source file and header file corresponding to the test case, matching and assigning the member variables of the test case registry structure to function pointers, the registry structure is automatically updated to reduce manual configuration work.
It reduces the complexity of test case writing, improves writing efficiency, ensures that the registry is consistent with the latest test case definition, and improves the maintainability and reliability of the code.
Smart Images

Figure CN120295927B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of testing, in particular to a test case writing method and device, readable storage medium and electronic equipment. BACKGROUND
[0002] In the prior art, there are many deficiencies in the management of instruction set simulator test cases. In the aspect of firmware simulation (a hardware environment for simulating the running of firmware code on a Windows platform), the problems are particularly prominent. At present, each test case can only be configured before compilation, which lacks flexibility. The writing of test cases lacks unified specifications and standards. If more universal test cases are to be written, command lines must be configured one by one, which means that each test case needs to be manually written with a set of command line functions, greatly increasing the complexity of test case writing and seriously reducing the writing efficiency, making it difficult to meet the current needs of test case writing and management. SUMMARY
[0003] The technical problem to be solved by the present application is to provide a test case writing method, device, readable storage medium and electronic equipment, which can reduce the complexity of test case writing.
[0004] To solve the above technical problems, one technical solution adopted by the present application is:
[0005] A test case writing method, comprising the steps of:
[0006] obtaining all file names in a specified file, and extracting source files and header files corresponding to each test case from the specified file according to the all file names;
[0007] obtaining a test case registry structure body member variable;
[0008] matching a function name corresponding to the test case registry structure body member variable from the source files and the header files, and assigning the test case registry structure body member variable as a function pointer corresponding to the function name;
[0009] updating the specified file based on the test case registry structure body member variable after assignment.
[0010] To solve the above technical problems, another technical solution adopted by the present application is:
[0011] A test case writing device, comprising:
[0012] a file extraction module configured to obtain all file names in a specified file, and extract source files and header files corresponding to each test case from the specified file according to the all file names;
[0013] a variable obtaining module, configured to obtain a test case registry structure member variable;
[0014] an assignment module, configured to match a function name corresponding to the test case registry structure member variable from the source file and the header file, and assign the test case registry structure member variable as a function pointer corresponding to the function name;
[0015] a file updating module, configured to update the specified file based on the assigned test case registry structure member variable.
[0016] To solve the above technical problems, another technical solution adopted by the present application is:
[0017] A computer readable storage medium, having a computer program stored thereon, the computer program being executed by a processor to implement each step of the test case writing method.
[0018] To solve the above technical problems, another technical solution adopted by the present application is:
[0019] An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements each step of the test case writing method when executing the computer program.
[0020] The present application has the beneficial effects that all file names in the specified file are obtained, and the source file and the header file corresponding to each test case are extracted from the specified file according to all the file names, the test case registry structure member variable is obtained, the function name corresponding to the test case registry structure member variable is matched from the source file and the header file, and the test case registry structure member variable is assigned as the function pointer corresponding to the function name, and the specified file is updated based on the assigned test case registry structure member variable, so that the source file and the header file are automatically parsed, the function name of the test case is extracted, and it is assigned as the corresponding function pointer, the registration information of the test case is automatically updated, manual modification of the registry is not required, and similar codes do not need to be repeatedly written for the registration and configuration of each test case, thereby reducing the complexity of test case writing and improving the efficiency of test case writing. BRIEF DESCRIPTION OF DRAWINGS
[0021] Figure 1 A step flow chart of a test case writing method according to an embodiment of the present application;
[0022] Figure 2 A structural schematic diagram of a test case writing device according to an embodiment of the present application;
[0023] Figure 3A structural schematic diagram of an electronic device according to an embodiment of the present application;
[0024] Figure 4 A case registration flow chart in a test case writing method according to an embodiment of the present application;
[0025] Figure 5 A case command line function generation flow chart in a test case writing method according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] To make the technical content, the achieved purposes and effects of the present application clear, the following will be described in detail in combination with the embodiments and the accompanying drawings.
[0027] Please refer to Figure 1 A test case writing method, comprising the steps of:
[0028] Obtaining all file names in a specified file, and extracting source files and header files corresponding to each test case from the specified file according to the all file names;
[0029] Obtaining a test case registry structure body member variable;
[0030] Matching a function name corresponding to the test case registry structure body member variable from the source files and the header files, and assigning the test case registry structure body member variable as a function pointer corresponding to the function name;
[0031] Updating the specified file based on the test case registry structure body member variable after the assignment.
[0032] From the above description, the beneficial effects of the present application are that all file names in a specified file are obtained, and source files and header files corresponding to each test case are extracted from the specified file according to the all file names, a test case registry structure body member variable is obtained, a function name corresponding to the test case registry structure body member variable is matched from the source files and the header files, and the test case registry structure body member variable is assigned as a function pointer corresponding to the function name, the specified file is updated based on the test case registry structure body member variable after the assignment, so that the source files and the header files are automatically parsed, the function name of the test case is extracted, and it is assigned as the corresponding function pointer, the registration information of the test case is automatically updated, manual modification of the registry is not needed, and similar codes for registration and configuration of each test case do not need to be repeatedly written manually, so as to reduce the complexity of test case writing, and further improve the test case writing efficiency.
[0033] Further, the obtaining of the test case registry structure body member variable comprises:
[0034] Finding a structure definition from a file storing a test case registry structure;
[0035] Parses the structure definition using a parsing function to obtain a structure member variable;
[0036] Storing the structure member variable into the test case registry structure.
[0037] As can be seen from the above description, the structure definition is parsed using a parsing function to obtain a structure member variable, and the structure member variable is stored into the test case registry structure, realizing the automatic management and updating of the test case registry structure, which can reduce the workload of manually maintaining the registry and ensure that the registry structure is always consistent with the latest test case definition, improving the maintainability and reliability of the code.
[0038] Further, the structure member variable includes a member variable name and a corresponding type name;
[0039] The matching of the function name corresponding to the test case registry structure member variable from the source file and the header file, and the assignment of the test case registry structure member variable to the function pointer corresponding to the function name include:
[0040] Applying a memory;
[0041] Writing the pre-data of the registration function into the memory;
[0042] Traversing each type name in the test case registry structure;
[0043] For the traversed type name, if the type name is not a function type, a preset assignment statement is written into the memory, and the post-data of the registration function is written into the memory;
[0044] And / or, if the type name is a function type, it is determined whether there is a function declaration and function definition of the member variable name corresponding to the type name in the header file and the source file, if yes, a statement data assigning the function pointer corresponding to the function definition is written into the memory, and the post-data of the registration function is written into the memory.
[0045] As can be seen from the above description, by parsing the structure member variable (including the variable name and the type name) and combining the function information in the source file and the header file, the structure member variable is automatically assigned to the corresponding function pointer, which reduces the complexity of manually writing and maintaining the registry structure, and can adapt to the changes of the test case, thereby improving the writing efficiency.
[0046] Further, the function of judging whether the function declaration and the function definition of the member variable name corresponding to the type name exist in the header file and the source file, if yes, writing the statement data of assigning the function pointer corresponding to the function definition into the memory, and writing the post data of the registration function into the memory includes:
[0047] judging whether the function declaration of the member variable name corresponding to the type name exists in the header file, if not, writing the statement data of assigning 0 into the memory, and writing the post data of the registration function into the memory, if yes, judging whether the function definition corresponding to the function declaration exists in the source file, if yes, writing the statement data of assigning the function pointer corresponding to the function definition into the memory, and writing the post data of the registration function into the memory, if not, outputting error information.
[0048] As can be seen from the above description, by gradually checking the function declaration in the header file and the function definition in the source file, the correct assignment statement is dynamically generated for the registry structure body, which avoids the runtime error caused by the missing function or the mismatched declaration, and can also find the potential error (such as the existence of function declaration but the missing definition) in time and remind the developer to correct through the error information, thereby ensuring the correct operation of the test case.
[0049] Further, the updating of the specified file based on the member variable of the test case registry structure body after assignment includes:
[0050] updating the data in the memory to the specified file.
[0051] As can be seen from the above description, by updating the data in the memory to the specified file, the latest state of the registry structure body can be ensured to be saved, so that the subsequent program operation can be executed based on the latest registration information, ensuring the correct registration and operation of the test case.
[0052] Further, it further includes:
[0053] loading the file data in the header file into the memory;
[0054] judging whether the test case information structure body corresponding to the header file exists in the memory, if yes, outputting each test case information structure body member variable in the test case information structure body, and waiting to receive the parameters required by the test case information structure body member variable.
[0055] As can be known from the above description, by loading data in the header file into the memory and checking whether the corresponding use case information structure body exists, the configuration parameters (member variables) of each use case can be automatically identified and output, and by waiting for receiving the parameter values input by the user, the required running parameters of each use case can be dynamically configured, thereby improving the flexibility and configurability of the test case and reducing the workload of manual parameter configuration.
[0056] Further, it further comprises:
[0057] obtaining a test case registration table;
[0058] determining a to-be-run test case table from the test case registration table;
[0059] creating a test case execution thread;
[0060] sequentially executing the test cases in the to-be-run test case table based on the test case execution thread.
[0061] As can be known from the above description, by obtaining the test case registration table and determining the to-be-run test case table, the test cases that need to be run can be dynamically identified and loaded, the test case execution thread is created and these test cases are sequentially executed, thereby improving the efficiency of the test, separating the test case execution and the system running, making the simulator run more flexible, simplifying the difficulty of writing and improving the controllability of the simulator.
[0062] Please refer to Figure 2 Another embodiment of the present application provides a test case writing device, comprising:
[0063] a file extraction module, configured to obtain all file names in a specified file and extract source files and header files corresponding to each test case from the specified file according to the all file names;
[0064] a variable obtaining module, configured to obtain member variables of a test case registration table structure body;
[0065] an assignment module, configured to match function names corresponding to the member variables of the test case registration table structure body from the source files and the header files and assign the member variables of the test case registration table structure body as function pointers corresponding to the function names;
[0066] a file updating module, configured to update the specified file based on the member variables of the test case registration table structure body after assignment.
[0067] Another embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize each step in the test case writing method.
[0068] Referring to Figure 3 Another embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements each step of the test case writing method when executing the computer program.
[0069] The test case writing method, device, readable storage medium and electronic device can be applied to test scenarios, such as scenarios using a simulator to test, which are described below through a specific implementation.
[0070] Referring to Figure 1 , Figure 4 and Figure 5 Embodiment one of the present application is:
[0071] A test case writing method includes the following steps:
[0072] In this embodiment, the principle of case writing is to create a.h file and a.c or.cpp file for writing a case file in a specified file, with the file name being the case name+_case; write necessary functions, with the function name being the case name plus the member variable name corresponding to the function of the case structure; write the structure of the case configurable parameters, with the structure name being the case name+_Info. The subsequent steps are all written according to this principle.
[0073] S1, obtain all file names in the specified file, and extract source files and header files corresponding to each test case from the specified file according to the all file names, as shown in Figure 4 .
[0074] Specifically, according to the obtained all file names, xxx_case.h, xxx_case.c and xxx_case.cpp are extracted from the specified file, and the prefix xxx of the.h (header file) has a corresponding.c.cpp (source file).
[0075] In an optional implementation, it can also include saving the extracted source files and header files corresponding to each test case to a test case processing table. For example, the extracted.c.cpp files and.h files corresponding to each case are saved in the form of xxx_case to the case processing table.
[0076] S2, obtain the test case registry structure member variable, specifically including S21-S23:
[0077] S21, find the structure definition from the file storing the test case registry structure.
[0078] Specifically, the structure definition is searched from a file storing the test case registry structure, if not found, an error code is output, if found, S22 is executed.
[0079] S22, the structure definition is parsed using a parsing function to obtain structure member variables.
[0080] S23, the structure member variables are stored in the test case registry structure.
[0081] In an optional embodiment, the structure member variables include the number of member variables, the name of the member variable, and the corresponding type name, etc.
[0082] In an optional embodiment, it can also include: traversing the source file and the header file one by one in the case processing table, for the source file and the header file traversed, S3 is executed, after execution, the corresponding file is removed from the case processing table, until the case processing table is empty.
[0083] S3, the function name corresponding to the test case registry structure member variable is matched from the source file and the header file, and the test case registry structure member variable is assigned as the function pointer corresponding to the function name, as shown in the following formula: Figure 4 S31-S33, specifically including:
[0084] S31, a memory is applied.
[0085] In an optional embodiment, a memory is applied using the malloc (memory allocation) function.
[0086] S32, the pre-data of the registration function is written into the memory.
[0087] The pre-data of the registration function includes function definition and required intermediate variables, etc.
[0088] S33, each type name in the test case registry structure is traversed.
[0089] For the type name traversed, if the type name is not a function type, a preset assignment statement is written into the memory, and the post-data of the registration function is written into the memory.
[0090] If the type name is a function type, it is determined whether a function declaration and a function definition of a member variable name corresponding to the type name exist in the header file and the source file, if yes, statement data of an assignment to a function pointer corresponding to the function definition is written in the memory, and post data of the registration function is written in the memory.
[0091] The preset assignment statement is an assignment statement written in advance.
[0092] If the type name is a function type, it is determined whether a function declaration and a function definition of a member variable name corresponding to the type name exist in the header file and the source file, if yes, statement data of an assignment to a function pointer corresponding to the function definition is written in the memory, and post data of the registration function is written in the memory.
[0093] If the type name is a function type, it is determined whether a function declaration and a function definition of a member variable name corresponding to the type name exist in the header file and the source file, if yes, statement data of an assignment to a function pointer corresponding to the function definition is written in the memory, and post data of the registration function is written in the memory.
[0094] Specifically, it is determined whether a function declaration of a case name + a member variable name corresponding to a type name exists in a.h file, if not, statement data of an assignment to 0 is appended and written in the memory, and post data of the registration function is appended and written in the memory, if yes, it is determined whether a function definition corresponding to the function declaration exists in a.c or.cpp file, if yes, statement data of an assignment to a function pointer corresponding to the function definition is appended and written in the memory, and post data of the registration function is appended and written in the memory, if not, error information is output.
[0095] S4, updating a member variable of a test case registration table structure based on the assignment.
[0096] Specifically, data in the memory is updated to the specified file.
[0097] In the process of running the simulator, if a new case needs to be added, a new case is automatically generated by using S1-S4, and functions and case information (such as a case name and a case ID) required for running the case can be registered by using S1-S4, which has two most basic functions: the corresponding function in the registration table is called to run when the simulator runs; and the position of the case in the registration table is found through the case information.
[0098] In an alternative embodiment, as shown in Figure 5 Further comprising:
[0099] S5, loading file data in the header file to memory.
[0100] S6, judging whether there is a use case information structure corresponding to the header file in the memory, if so, outputting each use case information structure member variable in the use case information structure and waiting for receiving parameters required by the use case information structure member variable.
[0101] Specifically, judging whether there is an _Info structure corresponding to the.h header file in the memory, if so, outputting each _Info structure member variable in the _Info structure using the printf function and waiting for receiving parameters required by the _Info structure member variable using the scanf function.
[0102] Through S5 and S6, additional parameters required by actual running of the case can be obtained.
[0103] In an alternative embodiment, further comprising:
[0104] S7, obtaining a test case registry.
[0105] S8, determining a to-be-run test case table from the test case registry.
[0106] S9, creating a test case execution thread.
[0107] S10, sequentially executing test cases in the to-be-run test case table based on the test case execution thread.
[0108] S7-S10 can be executed synchronously with or after S1-S6.
[0109] If the case is stuck when running the simulator, an exit function in the case file is automatically called to make it exit the stuck process, so as to solve the problem that the case cannot exit the stuck process when stuck when running the simulator.
[0110] The application scenario of the above-mentioned test case writing method of the present application is described by examples as follows. As shown in Figure 4 The case registration process includes steps (1)-(10) as follows:
[0111] (1) opening a specified file.
[0112] (2) traversing the whole file to read and sort all file names in the file.
[0113] (3) Remove non-.cpp,.c,.h file names, and pair the two files, add case processing table.
[0114] (4) Load two corresponding.cpp,.c,.h files into memory.
[0115] (5) Traverse the case registry structure member variable, splice the case name and the registry structure member variable name.
[0116] (6) Determine whether the corresponding function name is found in the.cpp,.c and.h files, if yes, execute (8), if not, execute (7).
[0117] (7) Assign the corresponding structure variable to 0.
[0118] (8) Assign the corresponding structure variable to the corresponding function pointer.
[0119] (9) Write the assigned data into the specified configuration file.
[0120] (10) Remove the two files from the case processing table.
[0121] As shown in Figure 5 , the case command line function generation process includes steps (a)-(g):
[0122] (a) Open the specified file.
[0123] (b) Read all.h files in the folder and load the file data into memory.
[0124] (c) Splice the case name and the _Info structure.
[0125] (d) Determine whether the spliced structure variable name is matched in memory, if not, execute (e), if yes, execute (f).
[0126] (e) Generate an empty string.
[0127] (f) Generate the string printf(“%s”, member variable name) scanf(“%d” structure variable name Temp. Member variable name) in order.
[0128] (g) Write the generated string into the specified file.
[0129] Please refer to Figure 2 , the second embodiment of the present application is:
[0130] A test case writing device, comprising:
[0131] A file extraction module is configured to acquire all file names in a specified file, and extract source files and header files corresponding to each test case from the specified file according to the all file names;
[0132] A variable acquisition module is configured to acquire a test case registry structure body member variable;
[0133] An assignment module is configured to match a function name corresponding to the test case registry structure body member variable from the source files and the header files, and assign the test case registry structure body member variable as a function pointer corresponding to the function name;
[0134] A file update module is configured to update the specified file based on the test case registry structure body member variable after assignment.
[0135] Embodiment three of the present application is:
[0136] A computer readable storage medium, which stores a computer program, the computer program is executed by a processor to realize each step of the test case writing method in embodiment one.
[0137] Embodiment four of the present application is:
[0138] Please refer to Figure 3 An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor realizes each step of the test case writing method in embodiment one when executing the computer program.
[0139] To sum up, the application provides a test case writing method, device, readable storage medium and electronic equipment, all file names in a specified file are obtained, source files and header files corresponding to each test case are extracted from the specified file according to all the file names, a test case registry structure body member variable is obtained, function names corresponding to the test case registry structure body member variable are matched from the source files and the header files, and the test case registry structure body member variable is assigned as a function pointer corresponding to the function name, the specified file is updated based on the test case registry structure body member variable after the assignment, so that the function names of the test cases are extracted by automatically parsing the source files and the header files, and the function names are assigned as the corresponding function pointers, the registration information of the test cases is automatically updated, manual modification of the registry is not needed, and similar codes for registration and configuration of each test case do not need to be repeatedly written by artificial, so that the complexity of test case writing is reduced, and the test case writing efficiency is improved; and the structure body member variable (including a variable name and a type name) is parsed, and the function information in the source files and the header files is combined to automatically assign the structure body member variable as the corresponding function pointer, the complexity of manually writing and maintaining the registry structure body is reduced, and the writing efficiency is improved.
[0140] In the above-described embodiments provided in the present application, it should be understood that the disclosed methods, devices, computer-readable storage media and electronic equipment can be implemented in other manners. For example, the above-described device embodiments are merely illustrative, and the division of the modules is merely a logical function division, and there can be another division manner in actual implementation, for example, a plurality of components or modules can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed components can be indirect coupling or communication connection through some interfaces, devices or components, and can be electrical, mechanical or other forms.
[0141] The components described as separate components may or may not be physically separate, and the components shown as components may or may not be physical modules, that is, they can be located in one place or distributed on a plurality of network modules. Some or all of the components can be selected according to actual needs to achieve the purpose of the embodiments.
[0142] In addition, the functional modules in each embodiment of the application can be integrated into one processing module, or each component can be physically present alone, or two or more modules can be integrated into one module. The above integrated module can be realized in the form of hardware or in the form of a software functional module.
[0143] The integrated module, if implemented in the form of a software function module and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, etc.
[0144] It should be noted that, for the foregoing method embodiments, in order to facilitate description, they are all expressed as a combination of a series of actions, but those skilled in the art should know that the present application is not limited by the order of the described actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.
[0145] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0146] The above only describes the embodiments of the present application, and does not limit the patent scope of the present application, and any equivalent transformation or direct or indirect application in the related technical field based on the content of the specification and drawings of the present application is also included in the patent protection scope of the present application.
Claims
1. A test case writing method, characterized in that: Including steps: Obtain all file names in a specified file, and extract source files and header files corresponding to each test case from the specified file according to all file names; Get the test case registry structure member variables; Matching the function name corresponding to the test case registry structure member variable from the source file and the header file, and assigning the test case registry structure member variable to a function pointer corresponding to the function name; Update the specified file based on the assigned test case registry structure member variables; The method of obtaining the test case registry structure member variables includes: Find the structure definition from the file storing the test case registry structure; Parsing the structure definition using a parsing function to obtain structure member variables, wherein the structure member variables include member variable names and corresponding type names; Storing the structure member variables in the test case registry structure; The matching of the function name corresponding to the test case registry structure member variable from the source file and the header file, and assigning the test case registry structure member variable to a function pointer corresponding to the function name includes: Apply for a memory segment; Writing the pre-data of the registration function into the memory; Traversing each of the type names in the test case registry structure; For the traversed type name, if the type name is a non-function type, writing a preset assignment statement into the memory and writing the post-data of the registered function into the memory; And / or, if the type name is a function type, determine whether there is a function declaration and function definition with a member variable name corresponding to the type name in the header file and the source file; if so, write statement data of a function pointer corresponding to the function definition into the memory, and write the post-data of the registered function into the memory.
2. A test case writing method according to claim 1, characterized in that: The determining whether there is a function declaration and a function definition with a member variable name corresponding to the type name in the header file and the source file, and if so, writing statement data of a function pointer corresponding to the function definition into the memory, and writing the post-data of the registered function into the memory includes: Determine whether there is a function declaration with a member variable name corresponding to the type name in the header file. If not, write statement data with a value of 0 into the memory, and write the post-data of the registered function into the memory. If so, determine whether there is a function definition corresponding to the function declaration in the source file. If so, write statement data with a value of the function pointer corresponding to the function definition into the memory, and write the post-data of the registered function into the memory. If not, output an error message.
3. A test case writing method according to claim 1 or 2, characterized in that: The updating of the designated file based on the assigned test case registry structure member variables includes: Update the data in the memory to the specified file.
4. A test case writing method according to claim 1, characterized in that: Also includes: Load the file data in the header file into the memory; Determine whether there is a use case information structure corresponding to the header file in the memory; if so, output each use case information structure member variable in the use case information structure, and wait to receive parameters required by the use case information structure member variables.
5. A test case writing method according to claim 1, characterized in that: Also includes: Get the test case registry; Determine a table of test cases to be run from the test case registration table; Create a test case execution thread; The test cases in the to-be-run test case table are executed sequentially based on the test case execution thread.
6. A test case writing device, characterized in that: include: A file extraction module is used to obtain all file names in a specified file, and extract source files and header files corresponding to each test case from the specified file according to all the file names; Variable acquisition module, used to obtain member variables of the test case registry structure; An assignment module, configured to match a function name corresponding to a member variable of the test case registry structure from the source file and the header file, and assign the member variable of the test case registry structure to a function pointer corresponding to the function name; A file update module, used for updating the specified file based on the assigned test case registry structure member variables; The method of obtaining the test case registry structure member variables includes: Find the structure definition from the file storing the test case registry structure; Parsing the structure definition using a parsing function to obtain structure member variables, wherein the structure member variables include member variable names and corresponding type names; Storing the structure member variables in the test case registry structure; The matching of the function name corresponding to the test case registry structure member variable from the source file and the header file, and assigning the test case registry structure member variable to a function pointer corresponding to the function name includes: Apply for a memory segment; Writing the pre-data of the registration function into the memory; Traversing each of the type names in the test case registry structure; For the traversed type name, if the type name is a non-function type, writing a preset assignment statement into the memory and writing the post-data of the registered function into the memory; And / or, if the type name is a function type, determine whether there is a function declaration and function definition with a member variable name corresponding to the type name in the header file and the source file; if so, write statement data of a function pointer corresponding to the function definition into the memory, and write the post-data of the registered function into the memory.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step in the test case writing method according to any one of claims 1 to 5 is implemented.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, each step in the test case writing method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Application test method and device, electronic equipment and storage medium
CN116303098A
Hardware function detection system and method, electronic equipment and storage medium
CN116627738A