Test data generation method and device, computer equipment and storage medium

By dividing variables into logical expressions in the code structure feature file and simplifying the strategy to generate test data of complex data types, the problem that the existing technology cannot generate complex type test data is solved, and efficient and risk-free The test data is generated.

CN118733430APending Publication Date: 2024-10-01SHENZHEN TENCENT COMP SYST CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310379029.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-31
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

It is difficult for the prior art to generate test data of complex data types, especially in business scenarios involving complex types such as functions, classes, structures and protocol buffers, and it is impossible to effectively generate test data.

Method used

By dividing variables into the logical expressions in the code structure feature file, traversing different types of policy makers, calling matching type strategy makers for simplification, obtaining the simplified variable parameters, and generating test data based on these parameters.

Benefits of technology

It realizes the generation of test data of complex data types, supports the generation of test data of various complex data types, improves the generation efficiency, and does not require intrusion code, avoids quality risks, and is suitable for interface and unit testing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733430A_ABST
    Figure CN118733430A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a test data generation method and device, computer equipment and a storage medium. The method comprises the following steps: performing variable segmentation on a logic expression in a code structure feature file to obtain at least one variable parameter corresponding to the logic expression; traversing the plurality of policies, and calling the currently traversed policies to determine a target variable parameter from the at least one variable parameter; calling a currently traversed policy device to simplify the target variable parameter to obtain a simplified variable parameter corresponding to the target variable parameter; after traversal is finished, based on the simplified variable parameter corresponding to each variable parameter in the at least one variable parameter and the parameter value of each variable parameter, the logic expression is simplified, and a simplified logic expression corresponding to the logic expression is obtained; and generating test data based on the simplified logic expression. By adopting the embodiment of the invention, the test data of a complex data type can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a test data generating method, device, computer equipment and storage medium. Background Art

[0002] Before conducting software testing, it is usually necessary to process the original data and generate a large amount of test data. At present, the method of generating test data is mainly based on the path constraints of the extracted code, and the constraint solving generates the corresponding test data. However, this method can only support the generation of test data of basic data types, and in actual business scenarios, the data types are usually more complex. For example, the commonly used logical expressions in business usually involve complex types such as functions, classes, structures, and protocol buffers (PB). Among them, PB is an automated mechanism for serializing structured data in occasions such as communication protocols and data storage. Therefore, how to generate test data for complex types of business data has become an urgent problem to be solved. Summary of the invention

[0003] Embodiments of the present application provide a test data generation method, apparatus, computer equipment, and storage medium, which can generate test data of complex data types.

[0004] In a first aspect, an embodiment of the present application provides a method for generating test data, the method comprising:

[0005] Perform variable segmentation on the logic expression in the code structure feature file to obtain at least one variable parameter corresponding to the logic expression; wherein the logic expression includes at least one variable parameter and parameter values ​​of each variable parameter;

[0006] Traversing multiple policymakers, and calling the currently traversed policymaker to determine a target variable parameter from at least one variable parameter; wherein the data type of the target variable parameter matches the policymaker type of the currently traversed policymaker, and the policymaker types of different policymakers are different;

[0007] Call the currently traversed strategist to simplify the target variable parameters and obtain the simplified variable parameters corresponding to the target variable parameters;

[0008] After the traversal is completed, based on the simplified variable parameter corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression corresponding to the logical expression;

[0009] Generate test data based on the simplified logical expression.

[0010] In a second aspect, an embodiment of the present application provides a test data generating device, the device comprising:

[0011] A segmentation unit, used for performing variable segmentation on the logic expression in the code structure feature file to obtain at least one variable parameter corresponding to the logic expression; wherein the logic expression includes at least one variable parameter and parameter values ​​of each variable parameter;

[0012] A determination unit, used to traverse multiple policy devices, and call the currently traversed policy device to determine a target variable parameter from at least one variable parameter; wherein the data type of the target variable parameter matches the policy device type of the currently traversed policy device, and the policy device types of different policy devices are different;

[0013] A processing unit, used for calling the currently traversed strategist to simplify the target variable parameters, and obtaining simplified variable parameters corresponding to the target variable parameters;

[0014] The processing unit is further used to simplify the logical expression after the traversal is completed based on the simplified variable parameter corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter to obtain a simplified logical expression corresponding to the logical expression;

[0015] The processing unit is also used to generate test data based on the simplified logical expression.

[0016] In a third aspect, an embodiment of the present application provides a computer device, which includes a processor, a communication interface and a memory, wherein the processor, the communication interface and the memory are interconnected, wherein the memory stores a computer program, and the processor is used to call the computer program to execute the test data generation method provided in the embodiment of the present application.

[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the test data generation method provided in the embodiment of the present application is implemented.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a terminal reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the terminal executes the test data generation method provided in an embodiment of the present application.

[0019] In the embodiment of the present application, the computer device can obtain at least one variable parameter by segmenting the logical expression of the complex data type in the code structure feature file; traverse different types of policy devices, simplify each variable parameter in the at least one variable parameter, and obtain the simplified variable parameter corresponding to each variable parameter; thus, based on the simplified variable parameter corresponding to each variable parameter and the parameter value of each variable parameter, simplify the logical expression, obtain the simplified logical expression, and generate test data based on the simplified logical expression. It can be seen that the test data of the complex data type can be generated by using the embodiment of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 It is a flowchart of a test data generation method provided in an embodiment of the present application;

[0022] Figure 2 It is a flowchart of another test data generation method provided in an embodiment of the present application;

[0023] Figure 3 It is a schematic diagram of mapping information of a logical expression before and after simplification provided by an embodiment of the present application;

[0024] Figure 4 It is another schematic diagram of mapping information of simplified logical expressions before and after provided in an embodiment of the present application;

[0025] Figure 5 It is another schematic diagram of mapping information of logical expressions before and after simplification provided in an embodiment of the present application;

[0026] Figure 6 It is a schematic diagram of the overall process of a test data generation method provided in an embodiment of the present application;

[0027] Figure 7 is a schematic diagram of a test data generating device provided in an embodiment of the present application;

[0028] Figure 8 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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.

[0030] In order to facilitate understanding of the embodiments of the present application, the test data generating method of the present application is described below.

[0031] In order to generate test data of complex data types, an embodiment of the present application provides a test data generation scheme. The following is an explanation of the general implementation process of the test data generation scheme provided by the embodiment of the present application: the computer device performs variable segmentation on the logical expression in the code structure feature file to obtain at least one variable parameter corresponding to the logical expression; wherein the logical expression includes at least one variable parameter and the parameter value of each variable parameter; traverse multiple strategy devices, and call the currently traversed strategy device to determine the target variable parameter from at least one variable parameter; wherein the data type of the target variable parameter matches the strategy device type of the currently traversed strategy device, and the strategy device types of different strategy devices are different; call the currently traversed strategy device to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; after the traversal is completed, based on the simplified variable parameter corresponding to each variable parameter in at least one variable parameter, and the parameter value of each variable parameter, simplify the logical expression to obtain the simplified logical expression corresponding to the logical expression; based on the simplified logical expression, generate test data.

[0032] Practice has shown that the test data generation scheme proposed in the embodiment of the present application can have the following beneficial effects: ① By traversing different types of policy devices, at least one variable parameter corresponding to the complex logical expression in the code structure feature file is simplified, and the simplified variable parameter corresponding to each variable parameter can be obtained; thus, based on the simplified variable parameter corresponding to each variable parameter, and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression, and then based on the simplified logical expression, test data of complex data types can be generated. ② This scheme supports the generation of test data for various newly added complex data types through the policy mode. ③ The computer device statically executes the above scheme without intrusion code and there is no quality risk. ④ In the coding stage, this scheme can generate single test case data of the logical expression with one click, so the execution efficiency is higher. ⑤ The test data generated by this scheme can be used not only in interface test scenarios, but also in unit test scenarios.

[0033] It should be noted that: in the specific implementation, the above scheme can be executed by a computer device, which can be a terminal or a server; wherein the terminal mentioned here can include but is not limited to: smart phones, tablet computers, laptops, desktop computers, smart watches, smart TVs, smart car terminals, etc.; various clients (applications, APPs) can be run in the terminal, such as video playback clients, social clients, browser clients, information flow clients, education clients, etc. The server mentioned here can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms, etc. Furthermore, the computer device mentioned in the embodiments of the present application may be located outside or inside the blockchain network, without limitation. The so-called blockchain network is a network composed of a peer-to-peer network (P2P network) and a blockchain, and the blockchain refers to a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. It is essentially a decentralized database, a string of data blocks (or blocks) generated by cryptographic methods.

[0034] In order to facilitate understanding of the embodiments of the present application, the specific implementation method of the test data generation solution provided by the present application is described in detail below.

[0035] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a test data generation method provided in an embodiment of the present application, and the test data generation method can be executed by a computer device. Figure 1 As shown, the test data generation method may include but is not limited to the following steps:

[0036] S101. Perform variable segmentation on a logic expression in a code structure feature file to obtain at least one variable parameter corresponding to the logic expression.

[0037] Wherein, the logical expression includes at least one variable parameter and parameter values ​​of each variable parameter;

[0038] In an optional embodiment, a computer device performs variable segmentation on a logical expression in a code structure feature file to obtain at least one variable parameter corresponding to the logical expression, which may include: using an operator in the code structure feature file as a segmentation point to segment the logical expression in the code structure feature file to obtain a segmented logical expression; and filtering constants in the segmented logical expression to obtain at least one variable parameter corresponding to the logical expression.

[0039] Optionally, the computer device can also segment the logical expressions in the code structure feature file based on the operators and spaces in the code structure feature file as segmentation points to obtain segmented logical expressions; filter the constants in the segmented logical expressions to obtain at least one variable parameter corresponding to the logical expression.

[0040] For example, suppose a logical expression (referred to as logical expression 1) in the code structure feature file is as follows:

[0041]

[0042]

[0043] The computer device may segment the logical expression 1 with operators (i.e., "=", "if", etc. in the logical expression 1) and spaces to obtain segmented logical expressions; and filter constants in the segmented logical expressions (i.e., "2", "true", etc. in the logical expression 1) to obtain at least one variable parameter corresponding to the logical expression 1 as follows:

[0044] req.ad_dynamic_styles().wechat_mdpa().dpa_type()

[0045] experiment_.GetFlowSwitch()

[0046] monitor_info.tmpl_id

[0047] req.tmpl_id()

[0048] ad_xml_.find("__request_id__")

[0049] IsMatch(req.ad_dynamic_styles())

[0050] The computer device can traverse all logical expressions in the control flow graph (CFG), and divide each logical expression into a substring list using operators and spaces as dividing points. After removing the constants in the list, the remaining parts are all variable parameters.

[0051] Among them, cfg can also be called a control flow graph, which is an abstract representation of a process or program. It is an abstract data structure used in the compiler and maintained internally by the compiler. It represents all the paths that will be traversed during the execution of a program. cfg uses a graph to represent the possible flow of execution of all basic blocks in a process, and can also reflect the real-time execution process of a process.

[0052] Optionally, after obtaining at least one variable parameter corresponding to each logical expression, the computer device further traverses all variable parameters and executes the following steps S102 to S104.

[0053] S102: traverse multiple policymakers, and call the currently traversed policymaker to determine a target variable parameter from at least one variable parameter.

[0054] The data type of the target variable parameter matches the strategy type of the currently traversed strategy, and the strategy types of different strategy devices are different.

[0055] The data types include but are not limited to function types, class types, pb types, etc.

[0056] Optionally, the policy maker may also be called a policy parser, which may include a function parser (FunctionParser) (or a function expression policy maker), a class parser (ClassParser) (or a class and structure expression policy maker), and a pb parser (PbParser) (or a pb expression parser), etc. A function parser is a policy maker of the function type, a class parser is a policy maker of the class type, and a Pb parser is a policy maker of the Pb type.

[0057] In an optional embodiment, a computer device calls the currently traversed policy device to determine a target variable parameter from at least one variable parameter, which may include: calling the currently traversed policy device, and if it is determined that the data type of the first variable parameter in at least one variable parameter matches the policy device type of the currently traversed policy device, then determining that the first variable parameter is the target variable parameter; the first variable parameter is any one of the at least one variable parameter.

[0058] S103: Call the currently traversed strategist to simplify the target variable parameters to obtain simplified variable parameters corresponding to the target variable parameters.

[0059] In an optional implementation, the computer device calls the currently traversed strategy device to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter, which may include: calling the currently traversed strategy device to increment the previous simplified variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; wherein the previous simplified variable parameter is obtained by simplifying the previous variable parameter of the target variable parameter. Optionally, calling the currently traversed strategy device to increment the previous simplified variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter may include: calling the simplification function and the unique identification information generator in the currently traversed strategy device, incrementing the previous simplified variable parameter by self-incrementing shared variables to obtain the simplified variable parameter corresponding to the target variable parameter. Optionally, the simplification function may be a Simplify function.

[0060] For example, suppose the previous simplified variable parameters are as follows:

[0061] req.uin()->smplify_0

[0062] The computer device can call the Simplify function of the currently traversed strategy device and the unique identification information (Identification, ID) generator, and increment the 0 in smplify_0 by self-incrementing shared variables, so that the simplified variable parameter corresponding to the target variable parameter is smplify_1, and the simplified variable parameter corresponding to the next variable parameter of the target variable parameter is smplify_2, etc. In this way, each simplified variable parameter is cumulatively increased, so that it can be ensured that the generated simplified variable parameter will not have the same name as other existing simplified variable parameters, that is, the simplified variable parameter is unique. Optionally, each simplified variable parameter can be cumulatively increased starting from 0.

[0063] S104. After the traversal is completed, based on the simplified variable parameters corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression corresponding to the logical expression.

[0064] For example, suppose the logical expression (referred to as logical expression 2) is as follows:

[0065] ad_xml_.find("__request_id__")! =string::npos

[0066] By segmenting the logical expression, the computer device can obtain the variable parameter corresponding to the logical expression as ad_xml_.find("__request_id__"), and the parameter value of the variable parameter is string::npos; if the simplified variable parameter corresponding to the variable parameter is simplify_1, the computer device can obtain the simplified logical expression corresponding to logical expression 2 as: simplify_1!=string::npos.

[0067] S105. Generate test data based on the simplified logical expression.

[0068] In an optional implementation, after traversing all variable parameters, the computer device can obtain simplified logical expressions corresponding to all logical expressions in cfg, and can generate test data based on each simplified logical expression.

[0069] In the embodiment of the present application, the computer device can obtain at least one variable parameter by segmenting the complex data type in the code structure feature file; traverse different types of policy devices, simplify each variable parameter in the at least one variable parameter, and obtain the simplified variable parameter corresponding to each variable parameter; thus, based on the simplified variable parameter corresponding to each variable parameter and the parameter value of each variable parameter, simplify the logical expression to obtain the simplified logical expression, and generate test data based on the simplified logical expression. It can be seen that the embodiment of the present application can generate test data of complex data types.

[0070] See also Figure 2 , Figure 2 is a flow chart of another test data generation method provided in an embodiment of the present application. Figure 1 Compared with the test data generation method shown in Figure 2 The test data generation method shown in the figure specifically describes how the computer device calls the currently traversed strategist to determine the target variable parameter from the at least one variable parameter. Figure 2 As shown, the test data generation method may include but is not limited to the following steps:

[0071] S201. Perform variable segmentation on a logic expression in a code structure feature file to obtain at least one variable parameter corresponding to the logic expression.

[0072] In an optional implementation, the relevant description of step S201 can refer to the description of the aforementioned step S101, which will not be repeated here.

[0073] In an optional implementation, before step S201, the computer device may also call the init function of each policy controller to initialize the configuration parameters of the policy controller.

[0074] Among them, the init function can be called before all programs are executed. The characteristics of the init function are as follows: it can be automatically executed before the main function; there can be multiple init functions in each data packet, and there can also be multiple init functions in the source file of each package; the init functions of different packages are executed in the order determined by the dependency relationship of package import; no matter how many times the data packet is imported, the init function will only be called once, that is, it will only be executed once.

[0075] S202, traverse multiple policy devices, and call the currently traversed policy device, determine whether the data type of the first variable parameter in at least one variable parameter matches the policy device type of the currently traversed policy device, if so, execute step S203a; if not, execute step S203b.

[0076] In an optional embodiment, the computer device may regard the simplification method of the logical expression of each data type as a strategy, and then use the strategy mode to set the relevant strategy protocol. Thereafter, if an expression of a new data type is added to the code structure feature file, the computer device may add a strategy device that matches the new data type to process the new data type.

[0077] Among them, the strategy pattern can associate an object with different sub-objects that can perform specific sub-tasks in different ways, thereby indirectly changing the behavior of the object at runtime. The strategy pattern can be implemented by using the interface mechanism in the Go language. In this way, flexible switching of different strategies can be supported.

[0078] In this application, the policy protocol includes: a policy interface expression parser (ExprParser), three specific policies and the main body of the policy call (or expression, or main process). Among them, the three specific policy devices are function parser, class parser and pb parser. Optionally, the relevant content of the policy interface and the three specific policy devices is described below.

[0079] S203a. Determine the first variable parameter as the target variable parameter.

[0080] In an optional implementation, after step S203a, the computer device further performs step S204a.

[0081] S203b: respectively call the policy controllers other than the currently traversed policy controller until it is determined that the data type of the first variable parameter matches the policy controller type of the called policy controller.

[0082] In an optional implementation, after step S203b, the computer device further executes step S204b.

[0083] S204a, calling the currently traversed strategist to simplify the target variable parameters, and obtaining simplified variable parameters corresponding to the target variable parameters.

[0084] In an optional implementation, after obtaining the simplified variable parameters corresponding to the target variable parameters, the computer device may also record mapping information, where the mapping information includes the corresponding relationship between the target variable parameters and the simplified variable parameters.

[0085] S204b: Call the called strategist to simplify the first variable parameter to obtain the simplified variable parameter corresponding to the first variable parameter.

[0086] In an optional implementation, after obtaining the simplified variable parameter corresponding to the first variable parameter, the computer device may further record mapping information, where the mapping information includes the corresponding relationship between the first variable parameter and the simplified variable parameter.

[0087] In an optional implementation, after step S204a or S204b, the computer device further executes step S205.

[0088] S205. After the traversal is completed, based on the simplified variable parameters corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression corresponding to the logical expression.

[0089] S206: Generate test data based on the simplified logical expression.

[0090] In an optional implementation, after step S206, the computer device may also replace each simplified variable parameter in the test data with a variable parameter corresponding to each simplified variable parameter to obtain a test case. That is, after the test data is generated, the computer device may also generate a test code.

[0091] In an optional implementation, the computer device may generate test data through the following code 1.

[0092] Code 1:

[0093]

[0094]

[0095]

[0096] In the embodiment of the present application, the computer device can obtain at least one variable parameter by segmenting the complex data type in the code structure feature file; traverse different types of policy devices, simplify each variable parameter in the at least one variable parameter, and obtain the simplified variable parameter corresponding to each variable parameter; thus, based on the simplified variable parameter corresponding to each variable parameter and the parameter value of each variable parameter, simplify the logical expression to obtain the simplified logical expression, and generate test data based on the simplified logical expression. It can be seen that the test data of complex data types can be generated by adopting the embodiment of the present application.

[0097] Optionally, the aforementioned strategy interface may be as follows code 1.

[0098] Code 1:

[0099]

[0100]

[0101] Optionally, each strategy parser structure contains a map for storing mapping information before and after logical expression simplification, which is used to restore assignment statements when generating test code. Optionally, the definitions of function parser, class and structure parser, and pb parser are as follows:

[0102] 1. Function parser

[0103]

[0104]

[0105] For example, suppose a function expression is as follows:

[0106] ad_xml_.find("__request_id__")! =string::npos

[0107] By calling the above function parser, the computer device can obtain the simplified function expression:

[0108] simplify_1!= string::npos

[0109] Among them, the mapping information between the function expression before simplification and the function expression after simplification is as follows: Figure 3 shown. Figure 3In the function expression, the original expression is the variable parameter in the function expression; the input parameter is 1, which means 1 expression; the symbol after simplification (i.e. the variable parameter after simplification) is simplify_1; the parameter value of the variable parameter is string::npos. Computer equipment can be based on Figure 3 The restoration method in restores the assignment statement corresponding to the simplified variable parameters.

[0110] 2. Class Parser

[0111]

[0112]

[0113] For example, suppose a class expression is as follows:

[0114] monitor_info.tmpl_id==1

[0115] By calling the above class parser, the computer device can obtain the simplified class expression:

[0116] simplify_0==1

[0117] Among them, the mapping information between the function expression before simplification and the function expression after simplification is as follows: Figure 4 shown. Figure 4 The original expression is the variable parameter in this type of expression; the simplified symbol (i.e. the simplified variable parameter) is simplify_0; the parameter value of the variable parameter is 0; and the restoration method is monitor_info.tmpl_id=1. Computer equipment can be based on Figure 4 The restoration method in restores the assignment statement corresponding to the simplified variable parameters.

[0118] 3. pb parser

[0119] Among them, pb is actually also a class, but pb is more standardized than a custom class. When a computer device reads the data members of a pb object, it can only access them through public functions, and assign values ​​to the data members of the pb object through fixed set_xxx functions. Therefore, when a computer device restores each simplified variable parameter in the test data corresponding to a logical expression of the pb type, it can assign values ​​by calling the set function without using mock processing. Optionally, the pb parser is defined as follows:

[0120]

[0121]

[0122] For example, suppose the pb expression is as follows:

[0123] req.ad_dynamic_styles().wechat_mdpa().dpa_type()==2

[0124] req.ad_dynamic_info.dynamic_target_param()! =""

[0125] The computer device can call the above pb parser to obtain the simplified pb expression as follows:

[0126] simplify_2==2

[0127] simplify_3!=""

[0128] Among them, the mapping information between the function expression before simplification and the function expression after simplification is as follows: Figure 5 shown. Figure 5 The original expression is the variable parameter in the pb expression.

[0129] req.ad_dynamic_styles().wechat_mdpa().dpa_type() and

[0130] req.ad_dynamic_info.dynamic_target_param(); where,

[0131] The simplified symbol (i.e. the simplified variable parameter) corresponding to req.ad_dynamic_styles().wechat_mdpa().dpa_type() is simplify_2; the parameter value is 2; and the constraint symbol is ==.

[0132] The simplified symbol corresponding to req.ad_dynamic_info.dynamic_target_param() is simplify_3, the parameter value is ""; the constraint symbol is ! =. Computer equipment can be based on Figure 5 The restoration method in restores the assignment statement corresponding to the simplified variable parameters.

[0133] See also Figure 6 , Figure 6 It is a schematic diagram of the overall process of a test data generation method provided in an embodiment of the present application. Figure 6In Visual Studio Code (VSCode), a free cross-platform source code editor developed by Microsoft. The software supports syntax highlighting, code auto-completion (also known as IntelliSense), code refactoring, view definition functions, and built-in command line tools and Git version control system. cppcheck is an open source static checking tool for C / C++ code defects, which is used to check error types that editors cannot check. Its purpose is to check real errors in the code.

[0134] like Figure 6 As shown, the core process of the test data generation method can correspond to the aforementioned Figure 1 or Figure 2 The test data generation method shown. Among them, the computer device can first select the function through the vscode plug-in, check it with cppcheck, and obtain the checked code structure feature file. Secondly, the code structure feature file is processed by the parsing module to obtain all logical expressions of cfg; all logical expressions of cfg are traversed, and each logical expression is split into variables to obtain at least one variable parameter corresponding to the logical expression. Then, multiple strategy devices are traversed, and the currently traversed strategy device is called to determine whether the data type of the first variable parameter in at least one variable parameter matches the strategy device type of the currently traversed strategy device. If so, the first variable parameter is determined to be the target variable parameter, the mapping information is recorded, and the currently traversed strategy device is called to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; if not, the strategy devices other than the currently traversed strategy device are called respectively until it is determined that the data type of the first variable parameter matches the strategy device type of the called strategy device, and the called strategy device is called to simplify the first variable parameter to obtain the simplified variable parameter corresponding to the first variable parameter. After the traversal is completed, based on the simplified variable parameters corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter, all logical expressions of the cfg structure are simplified to obtain the simplified logical expression corresponding to the logical expression. Finally, test data is generated based on the simplified logical expression. Optionally, before the computer device generates the test data based on the simplified logical expression, it also generates a path. Optionally, after generating the test data, the computer device may also call the GenerateSetter function of the corresponding strategy device based on the mapping information, replace each simplified variable parameter in the test data with the variable parameter corresponding to each simplified variable parameter (i.e., restore the simplified logical expression), and obtain a test case (for example, Figure 6Optionally, after obtaining the test case, the computer device can also visualize the test result and generate a test file through a vscode plug-in, and save the test file.

[0135] Optionally, the implementation form of the embodiments of the present application can be a visual interface service that provides users with code uploads to automatically generate unit test case data, or it can be a background service such as an application programming interface (Application Programming Interface, API) or a software development kit (Software Development Kit, SDK) that provides C++ complex data type test data generation in combination with other application scenarios.

[0136] It should be noted that when the embodiments of the present application are applied to specific products or technologies, the code structure feature files, logical expressions, etc. involved in the embodiments of the present application are obtained only after obtaining the user's permission or consent; and the collection, use and processing of code structure feature files, logical expressions, etc. need to comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0137] Based on the description of the relevant embodiments of the above-mentioned test data generation method, the embodiment of the present application also proposes a test data generation device, which can be a computer program (including program code) running in a computer device. The test data generation device can execute Figure 1 For the test data generation method shown in Figure 7 , Figure 7 is a schematic diagram of a test data generating device provided in an embodiment of the present application, and the test data generating device may include the following units:

[0138] The segmentation unit 701 is used to perform variable segmentation on the logic expression in the code structure feature file to obtain at least one variable parameter corresponding to the logic expression; wherein the logic expression includes at least one variable parameter and parameter values ​​of each variable parameter;

[0139] A determination unit 702 is used to traverse multiple policy devices and call the currently traversed policy device to determine a target variable parameter from at least one variable parameter; wherein the data type of the target variable parameter matches the policy device type of the currently traversed policy device, and the policy device types of different policy devices are different;

[0140] The processing unit 703 is used to call the currently traversed strategist to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter;

[0141] The processing unit 703 is further configured to simplify the logical expression based on the simplified variable parameter corresponding to each variable parameter in the at least one variable parameter and the parameter value of each variable parameter after the traversal is completed, so as to obtain a simplified logical expression corresponding to the logical expression;

[0142] The processing unit 703 is further configured to generate test data based on the simplified logical expression.

[0143] In an optional implementation, when the determination unit 702 is used to call the currently traversed strategist to determine the target variable parameter from at least one variable parameter, it is specifically used to:

[0144] Call the currently traversed strategist, and if it is determined that the data type of the first variable parameter in at least one variable parameter matches the strategist type of the currently traversed strategist, then determine that the first variable parameter is the target variable parameter; the first variable parameter is any one of the at least one variable parameter.

[0145] In an optional implementation, the determining unit 702 is further configured to:

[0146] If the data type of the first variable parameter does not match the policy type of the currently traversed policy device, then respectively call policy devices other than the currently traversed policy device until it is determined that the data type of the first variable parameter matches the policy type of the called policy device;

[0147] The called strategist is called to simplify the first variable parameter to obtain a simplified variable parameter corresponding to the first variable parameter.

[0148] In an optional implementation, the processing unit 703 is used to call the currently traversed strategist to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter, specifically to:

[0149] The currently traversed strategist is called to increment the previous simplified variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; the previous simplified variable parameter is obtained by simplifying the previous variable parameter of the target variable parameter.

[0150] In an optional implementation, the processing unit 703 is further configured to:

[0151] Each simplified variable parameter in the test data is replaced by a variable parameter corresponding to each simplified variable parameter to obtain a test case.

[0152] In an optional implementation, when the segmentation unit 701 is used to segment the logic expression in the code structure feature file into variables to obtain at least one variable parameter corresponding to the logic expression, it is specifically used to:

[0153] Taking the operators in the code structure feature file as segmentation points, segmenting the logical expressions in the code structure feature file to obtain segmented logical expressions;

[0154] The constants in the segmented logical expression are filtered to obtain at least one variable parameter corresponding to the logical expression.

[0155] According to the embodiments provided in this application, Figure 7 The various units in the test data generating device shown can be respectively or all merged into one or several other units to constitute, or some (some) units therein can also be split into multiple smaller units in function to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions. In practical applications, the function of a unit can also be realized by multiple units, or the function of multiple units is realized by one unit. In other embodiments of the present application, other units are also included based on the test data generating device. In practical applications, these functions can also be assisted by other units to be realized, and can be realized by the collaboration of multiple units.

[0156] According to an embodiment provided by the present application, the following can be executed by running on a general computer device such as a computer including a central processing unit (CPU), a random access memory medium (RAM), a read-only memory medium (ROM) and other processing elements and storage elements. Figure 1 A computer program (including program code) for each step involved in the corresponding method shown in FIG. Figure 7 The test data generating device shown in and the test data generating method of the embodiment of the present application are implemented. The computer program can be recorded on, for example, a computer readable storage medium, and loaded into the above-mentioned computer device through the computer readable storage medium, and run therein.

[0157] It can be understood that the specific implementation of each unit in the test data generating device provided in the embodiment of the present application and the beneficial effects that can be achieved can refer to the description of the aforementioned test data generating method embodiment, which will not be repeated here.

[0158] Based on the description of the above method embodiment and device embodiment, the present application embodiment also provides a computer device. Figure 8The computer device at least includes a processor 801, a memory 802, and a communication interface 803. The processor 801, the memory 802, and the communication interface 803 may be connected via a bus 804 or other methods. The embodiment of the present application takes the connection via the bus 804 as an example.

[0159] Among them, the processor 801 (or central processing unit (CPU)) is the computing core and control core of the computer device, which can parse various instructions in the computer device and process various data of the computer device. For example, the CPU can be used to parse the power on and off instructions sent by the user to the computer device, and control the computer device to perform power on and off operations; for another example, the CPU can transmit various interactive data between the internal structures of the computer device, and so on. The communication interface 803 can optionally include a standard wired interface, a wireless interface (such as Wi-Fi, a mobile communication interface, etc.), which is controlled by the processor 801 to send and receive data. The memory 802 (Memory) is a memory device in the computer device for storing computer programs and data. It can be understood that the memory 802 here can include both the built-in memory of the computer device and the extended memory supported by the computer device. The memory 802 provides a storage space, which stores the operating system of the computer device, which may include but is not limited to: Windows system, Linux system, Android system, iOS system, etc., and this application does not limit this. In an optional implementation manner, the processor 801 of the embodiment of the present application may perform the following operations by running the computer program stored in the memory 802:

[0160] Perform variable segmentation on the logic expression in the code structure feature file to obtain at least one variable parameter corresponding to the logic expression; wherein the logic expression includes at least one variable parameter and parameter values ​​of each variable parameter;

[0161] Traversing multiple policymakers, and calling the currently traversed policymaker to determine a target variable parameter from at least one variable parameter; wherein the data type of the target variable parameter matches the policymaker type of the currently traversed policymaker, and the policymaker types of different policymakers are different;

[0162] Call the currently traversed strategist to simplify the target variable parameters and obtain the simplified variable parameters corresponding to the target variable parameters;

[0163] After the traversal is completed, based on the simplified variable parameter corresponding to each variable parameter in at least one variable parameter and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression corresponding to the logical expression;

[0164] Generate test data based on the simplified logical expression.

[0165] In an optional implementation manner, when the processor 801 executes the call to the currently traversed strategist to determine the target variable parameter from at least one variable parameter, the processor 801 specifically executes:

[0166] Call the currently traversed strategist, and if it is determined that the data type of the first variable parameter in at least one variable parameter matches the strategist type of the currently traversed strategist, then determine that the first variable parameter is the target variable parameter; the first variable parameter is any one of the at least one variable parameter.

[0167] In an optional implementation, the processor 801 further executes:

[0168] If the data type of the first variable parameter does not match the policy type of the currently traversed policy device, then respectively call policy devices other than the currently traversed policy device until it is determined that the data type of the first variable parameter matches the policy type of the called policy device;

[0169] The called strategist is called to simplify the first variable parameter to obtain a simplified variable parameter corresponding to the first variable parameter.

[0170] In an optional implementation, when the processor 801 executes the call to the currently traversed strategist to simplify the target variable parameter and obtains the simplified variable parameter corresponding to the target variable parameter, it specifically executes:

[0171] The currently traversed strategist is called to increment the previous simplified variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; the previous simplified variable parameter is obtained by simplifying the previous variable parameter of the target variable parameter.

[0172] In an optional implementation, the processor 801 further executes:

[0173] Each simplified variable parameter in the test data is replaced by a variable parameter corresponding to each simplified variable parameter to obtain a test case.

[0174] In an optional implementation, when the processor 801 performs variable segmentation on the logical expression in the code structure feature file to obtain at least one variable parameter corresponding to the logical expression, the processor 801 specifically executes:

[0175] Taking the operators in the code structure feature file as segmentation points, segmenting the logical expressions in the code structure feature file to obtain segmented logical expressions;

[0176] The constants in the segmented logical expression are filtered to obtain at least one variable parameter corresponding to the logical expression.

[0177] In a specific implementation, the processor 801, memory 802, and communication interface 803 described in the embodiments of the present application can execute the implementation of the computer device described in the test data generation method provided in the embodiments of the present application, and can also execute the implementation described in the test data generation device provided in the embodiments of the present application, which will not be repeated here.

[0178] The embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored, and when the computer is run on a computer, the computer executes the test data generation method of any possible implementation method described above. The specific implementation method can be referred to the above description, and will not be repeated here.

[0179] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the test data generation method of any possible implementation method described above. The specific implementation method can be referred to the above description, which will not be repeated here.

[0180] It should be noted that, for the above-mentioned various method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.

[0181] A person skilled in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0182] The above disclosure is only part of the embodiments of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.

Claims

1. A test data generation method, characterized in that: The method comprises: Perform variable segmentation on the logical expression in the code structure feature file to obtain at least one variable parameter corresponding to the logical expression; wherein the logical expression includes at least one variable parameter and parameter values ​​of each variable parameter; Traversing multiple policymakers, and calling the currently traversed policymaker to determine a target variable parameter from the at least one variable parameter; wherein the data type of the target variable parameter matches the policymaker type of the currently traversed policymaker, and the policymaker types of different policymakers are different; Calling the currently traversed strategist to simplify the target variable parameter to obtain a simplified variable parameter corresponding to the target variable parameter; After the traversal is completed, based on the simplified variable parameter corresponding to each variable parameter in the at least one variable parameter and the parameter value of each variable parameter, the logical expression is simplified to obtain a simplified logical expression corresponding to the logical expression; Based on the simplified logical expression, test data is generated.

2. The method according to claim 1, characterized in that The calling of the currently traversed strategist to determine the target variable parameter from the at least one variable parameter comprises: Call the currently traversed strategy device, and if it is determined that the data type of the first variable parameter in the at least one variable parameter matches the strategy device type of the currently traversed strategy device, then determine that the first variable parameter is the target variable parameter; the first variable parameter is any one of the at least one variable parameter.

3. The method according to claim 2, characterized in that The method further comprises: If the data type of the first variable parameter does not match the policy type of the currently traversed policy device, then respectively call policy devices other than the currently traversed policy device until it is determined that the data type of the first variable parameter matches the policy type of the called policy device; The called strategist is called to simplify the first variable parameter to obtain a simplified variable parameter corresponding to the first variable parameter.

4. The method according to claim 1, characterized in that: The calling of the currently traversed strategist to simplify the target variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter includes: The currently traversed strategist is called to increment the previous simplified variable parameter to obtain the simplified variable parameter corresponding to the target variable parameter; the previous simplified variable parameter is obtained by simplifying the previous variable parameter of the target variable parameter.

5. The method according to claim 1, characterized in that The method further comprises: Each simplified variable parameter in the test data is replaced with a variable parameter corresponding to each simplified variable parameter to obtain a test case.

6. The method according to claim 1, characterized in that The step of performing variable segmentation on the logical expression in the code structure feature file to obtain at least one variable parameter corresponding to the logical expression includes: Taking the operators in the code structure feature file as segmentation points, segmenting the logical expressions in the code structure feature file to obtain segmented logical expressions; The constants in the segmented logical expression are filtered to obtain at least one variable parameter corresponding to the logical expression.

7. A test data generating device, characterized in that: The device comprises: A segmentation unit, used for performing variable segmentation on the logic expression in the code structure feature file to obtain at least one variable parameter corresponding to the logic expression; wherein the logic expression includes at least one variable parameter and parameter values ​​of each variable parameter; A determination unit, configured to traverse a plurality of policymakers, and call a currently traversed policymaker to determine a target variable parameter from the at least one variable parameter; wherein a data type of the target variable parameter matches a policymaker type of the currently traversed policymaker, and policymaker types of different policymakers are different; A processing unit, configured to call the currently traversed strategist to simplify the target variable parameter to obtain a simplified variable parameter corresponding to the target variable parameter; The processing unit is further configured to simplify the logical expression after the traversal is completed based on the simplified variable parameter corresponding to each variable parameter in the at least one variable parameter and the parameter value of each variable parameter to obtain a simplified logical expression corresponding to the logical expression; The processing unit is further used to generate test data based on the simplified logical expression.

8. A computer device, characterized in that: The computer device includes a memory, a communication interface and a processor, wherein the memory, the communication interface and the processor are interconnected; the memory stores a computer program, and the processor calls the computer program stored in the memory to implement the test data generation method described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the test data generating method according to any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program or a computer instruction, and when the computer program or the computer instruction is executed by a processor, the test data generating method according to any one of claims 1 to 6 is implemented.

Citation Information

Cited By

  • Bill of material configuration generation method and device, electronic equipment and program product

    CN121119924A

  • Bill of materials configuration generation method and device, electronic equipment and program product

    CN121119924B