Method and device for generating temporary variable, storage medium and electronic device
Patent Information
- Application Number
- CN202110764345.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-06
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2041-07-06
AI Technical Summary
[0003]使用低代码测试平台搭建测试用例时,需要先将测试用例在执行过程中所需要的变量预先进行设定和创建,以便测试用例在执行的过程中对变量进行调用,而如果需要在测试用例在执行的过程中添加变量,则需要中断测试用例的执行,并使用专门的参数管理页面增加新的变量,这种生成变量的方式复杂,不便于工作人员在执行测试用例的过程中添加新的变量,降低了工作人员的工作效率
[0061]本发明提供一种临时变量的生成方法及装置、存储介质及电子设备,该方法包括:当在执行测试用例的过程中获取到临时变量的创建指令时,基于所述创建指令的创建类型,执行与创建类型对应的变量生成方法,得到与创建指令对应的参数值,并基于参数值为创建指令所对应的变量名进行赋值,以得到与创建指令对应的临时变量,其中,测试用例的变量库中尚不存在与变量名对应的变量;将临时变量保存至变量库中,以便测试用例对临时变量进行调用。本发明提供的方法在生成临时变量时,无需中断测试用例的执行,可随时生成变量,根据不同的创建类型执行不同的生成变量的方式,生成变量过程简单、便捷,进而提高工作人员的工作效率。
Smart Images

Figure CN115576795B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software testing technology, and in particular to a method and apparatus for generating temporary variables, a storage medium, and an electronic device. Background Technology
[0002] With the rise of the Internet in recent years, software development processes have become increasingly faster. Software testing technologies have also adapted to the characteristics of rapid response. In order to lower the threshold of testing technology and allow testers to focus more on business logic, automated testing systems provide low-code testing platforms. This allows users to manually build test scenarios using a page-based approach, making automated testing increasingly convenient.
[0003] When building test cases using a low-code testing platform, the variables required by the test cases during execution need to be pre-defined and created so that the test cases can call the variables during execution. However, if variables need to be added during the execution of the test cases, the execution of the test cases needs to be interrupted and new variables need to be added using a dedicated parameter management page. This method of generating variables is complicated and inconvenient for staff to add new variables during the execution of test cases, thus reducing the efficiency of staff. Summary of the Invention
[0004] In view of this, the present invention provides a method and apparatus for generating temporary variables, a storage medium and an electronic device. By applying the present invention, variables can be added without interrupting the execution of test cases, and the process of adding variables is convenient and quick, improving the work efficiency of staff.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] A method for generating temporary variables, comprising:
[0007] When a temporary variable creation instruction is obtained during the execution of a test case, a variable generation method corresponding to the creation type is executed based on the creation type corresponding to the creation instruction to obtain the parameter value corresponding to the creation instruction. The parameter value is then used to assign a value to the variable name corresponding to the creation instruction to obtain a temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name.
[0008] The temporary variable is saved to the variable library so that the test case can call the temporary variable.
[0009] Optionally, in the above method, the step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value to obtain a temporary variable corresponding to the creation instruction, includes:
[0010] When the creation type of the creation instruction is a function creation type, the function identifier in the creation instruction is used to traverse each built-in function in the preset function library, and the built-in function corresponding to the function identifier is used as the target function;
[0011] Execute the target function and use the output of the target function as the parameter value corresponding to the creation instruction;
[0012] The variable name is obtained based on the creation instruction, and a value is assigned to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0013] Optionally, in the above method, the step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value to obtain a temporary variable corresponding to the creation instruction, includes:
[0014] When the creation type of the creation instruction is a calculation creation type, determine the calculation logic corresponding to the calculation identifier in the creation instruction;
[0015] Based on the calculation logic, each test variable corresponding to the calculation identifier is obtained from the variable library;
[0016] According to the calculation logic, each of the test variables is calculated, and the result of the calculation is used as the parameter value corresponding to the creation instruction;
[0017] Generate a variable name corresponding to the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0018] Optionally, in the above method, the step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value to obtain a temporary variable corresponding to the creation instruction, includes:
[0019] When the creation type of the creation instruction is an assignment creation type, the variable name corresponding to the creation instruction is obtained from the preset expected value box;
[0020] Obtain the test data returned when the test case is executed, and use the test data as the parameter value corresponding to the creation instruction;
[0021] The variable name is assigned a value based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0022] Optionally, the above method further includes, before executing the variable generation method corresponding to the creation type based on the creation instruction, the following:
[0023] Determine the creation type corresponding to the creation instruction;
[0024] The step of determining the creation type corresponding to the creation instruction includes:
[0025] The creation instruction is parsed, and it is determined whether the creation instruction contains a function identifier;
[0026] If the creation instruction contains a function identifier, then the creation type corresponding to the creation instruction is determined to be a function creation type;
[0027] If the creation instruction does not contain a function identifier, then determine whether the creation instruction contains a calculation identifier;
[0028] If the creation instruction contains a calculation identifier, then the creation type corresponding to the creation instruction is determined to be a calculation creation type;
[0029] If the creation instruction does not contain a calculation identifier, then the creation type corresponding to the creation instruction is determined to be an assignment creation type.
[0030] The above methods may also include:
[0031] When the test case finishes execution, the variable library for that test case is deleted.
[0032] A device for generating temporary variables, comprising:
[0033] The execution unit is used to, when a creation instruction for a temporary variable is obtained during the execution of a test case, execute a variable generation method corresponding to the creation type based on the creation type corresponding to the creation instruction, obtain a parameter value corresponding to the creation instruction, and assign a value to the variable name corresponding to the creation instruction based on the parameter value, so as to obtain a temporary variable corresponding to the creation instruction, wherein there is no variable corresponding to the variable name in the variable library of the test case;
[0034] A storage unit is used to save the temporary variable to the variable library so that the test case can call the temporary variable.
[0035] Optionally, the execution unit in the aforementioned apparatus includes:
[0036] The traversal subunit is used to, when the creation type of the creation instruction is a function creation type, traverse each built-in function in the preset function library by the function identifier in the creation instruction, and take the built-in function corresponding to the function identifier as the target function;
[0037] An execution subunit is used to execute the objective function and use the output of the objective function as the parameter value corresponding to the creation instruction;
[0038] The first assignment subunit is used to obtain the variable name based on the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0039] Optionally, the execution unit in the aforementioned apparatus includes:
[0040] The first determining subunit is used to determine the computation logic corresponding to the computation identifier in the creation instruction when the creation type of the creation instruction is a computation creation type;
[0041] The first acquisition subunit is used to acquire, based on the calculation logic, each test variable corresponding to the calculation identifier from the variable library;
[0042] The calculation subunit is used to perform calculations on each of the test variables according to the calculation logic, and use the result of the calculation as the parameter value corresponding to the creation instruction;
[0043] A generation subunit is used to generate a variable name corresponding to the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0044] Optionally, the execution unit in the aforementioned apparatus includes:
[0045] The second acquisition subunit is used to acquire the variable name corresponding to the creation instruction from a preset expected value box when the creation type of the creation instruction is an assignment creation type.
[0046] The third acquisition subunit is used to acquire the test data returned when the test case is executed, and use the test data as the parameter value corresponding to the creation instruction;
[0047] The second assignment subunit is used to assign a value to the variable name based on the parameter value, so as to obtain a temporary variable corresponding to the creation instruction.
[0048] The aforementioned apparatus may optionally further include:
[0049] A determining unit is used to determine the creation type corresponding to the creation instruction;
[0050] The determining unit includes:
[0051] The first judgment unit is used to parse the creation instruction and determine whether the creation instruction contains a function identifier;
[0052] The second determining unit is configured to determine that the creation type corresponding to the creation instruction is a function creation type if the creation instruction contains a function identifier;
[0053] The second judgment unit is used to determine whether the creation instruction contains a calculation identifier if the creation instruction does not contain a function identifier.
[0054] The third determining unit is used to determine that the creation type corresponding to the creation instruction is a calculation creation type if the creation instruction contains a calculation identifier;
[0055] The fourth determining unit is used to determine that the creation type corresponding to the creation instruction is an assignment creation type if the creation instruction does not contain a calculation identifier.
[0056] The aforementioned apparatus may optionally further include:
[0057] The deletion unit is used to delete the variable library of the test case when the execution of the test case ends.
[0058] A storage medium comprising stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides executes the temporary variable generation method described above.
[0059] An electronic device includes a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors as described above in the method for generating temporary variables.
[0060] Compared with the prior art, the present invention has the following advantages:
[0061] This invention provides a method, apparatus, storage medium, and electronic device for generating temporary variables. The method includes: when a temporary variable creation instruction is obtained during the execution of a test case, executing a variable generation method corresponding to the creation type based on the creation type of the instruction, obtaining a parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value to obtain a temporary variable corresponding to the creation instruction, wherein the variable library of the test case does not yet contain a variable corresponding to the variable name; and saving the temporary variable to the variable library so that the test case can call the temporary variable. The method provided by this invention does not require interrupting the execution of the test case when generating temporary variables, can generate variables at any time, and executes different variable generation methods according to different creation types. The variable generation process is simple and convenient, thereby improving the work efficiency of staff. Attached Figure Description
[0062] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0063] Figure 1 A flowchart illustrating a method for generating temporary variables according to an embodiment of the present invention;
[0064] Figure 2 This is another flowchart illustrating a method for generating temporary variables provided in an embodiment of the present invention.
[0065] Figure 3 Another flowchart of a method for generating temporary variables provided in an embodiment of the present invention;
[0066] Figure 4 A flowchart illustrating another method for generating a temporary variable provided in an embodiment of the present invention;
[0067] Figure 5 A flowchart illustrating yet another method for generating a temporary variable, as provided in an embodiment of the present invention.
[0068] Figure 6 A schematic diagram of a temporary variable generation device provided in an embodiment of the present invention;
[0069] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0070] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0071] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0072] This invention provides a method for generating temporary variables. This method can be applied to a low-code testing platform, which can be composed of a computer terminal or a smart terminal. The execution subject of this method can be the processor or server of the low-code testing platform.
[0073] Reference Figure 1 The following is a flowchart of a method for generating temporary variables according to an embodiment of the present invention, which is described in detail below:
[0074] S101. When a temporary variable creation instruction is obtained during the execution of a test case, a variable generation method corresponding to the creation type is executed based on the creation type corresponding to the creation instruction to obtain the parameter value corresponding to the creation instruction. The parameter value is then used to assign a value to the variable name corresponding to the creation instruction to obtain a temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name.
[0075] The test cases of this invention are written by business personnel according to business testing requirements. Before the test cases are executed, the global variables corresponding to the test cases need to be preloaded. Global variables are also called external variables. They are variables defined outside of functions and can be referenced by all objects or functions.
[0076] The creation command can be generated when the code for generating temporary variables, which is pre-written by business personnel in the test cases, is read during the execution of test cases. Alternatively, it can be generated when the code for generating temporary variables is input by business personnel during the execution of test cases. The creation command is used to guide the server to generate temporary variables.
[0077] Different creation types employ different variable generation methods. Based on the creation type corresponding to the creation instruction, the variable generation method corresponding to that creation type is executed, thereby obtaining temporary variables corresponding to the creation instruction. The variable library for test cases in this invention stores variables required by the test cases during execution. The variables in the library include global variables pre-loaded before the test cases are executed, and temporary variables generated during test case execution are also stored in this variable library. Furthermore, the variable names used by the temporary variables generated during test case execution are variable names that do not exist in the variable library; in other words, the variable names used by the temporary variables generated during test case execution do not yet have corresponding variables in the variable library.
[0078] S102. Save the temporary variable to the variable library so that the test case can call the temporary variable.
[0079] The generated temporary variables are stored in a variable library so that test cases can call these temporary variables when needed during execution.
[0080] To elaborate further, the variable library for the test cases is deleted when the test case execution ends. That is, the variable library is deleted at the end of the test cycle of the test cases. This can make reasonable use of the platform's resources and prevent the platform from calling incorrect variables when executing other test cases, ensuring the accuracy of the data used when executing test cases, thereby improving the correctness of the output results when the test cases are executed.
[0081] In the method provided by this invention, when a temporary variable creation instruction is obtained during the execution of a test case, the creation type of the creation instruction is determined; the variable generation method corresponding to the creation type is executed to obtain the parameter value corresponding to the creation instruction, and a value is assigned to the variable name corresponding to the creation instruction based on the parameter value, thereby obtaining a temporary variable corresponding to the creation instruction. The variable name corresponding to the variable name does not yet exist in the variable library of the test case; the temporary variable is saved to the variable library so that the test case can call the temporary variable. During the execution of a test case, when a temporary variable creation instruction is obtained, based on the creation type of the creation instruction, the variable generation method corresponding to the creation instruction is executed, and a value is assigned to the variable name based on the obtained parameter value, thereby obtaining a temporary variable. This allows temporary variables to be added at any time during the execution of test cases, and the generated temporary variables are saved to the variable library so that the test case can call them when needed. Applying the method provided by this invention, variables can be added at any time during the execution of test cases. The method of adding variables can be set according to the business requirements of the test cases. Applying this invention allows for the quick, simple, and flexible addition of new variables without affecting the execution of test cases, thus improving the efficiency of the platform's testing work.
[0082] Different creation types correspond to different variable generation methods. This invention describes the different variable generation methods corresponding to different creation types, as detailed below:
[0083] Reference Figure 2 The diagram illustrates a method flow for generating temporary variables when the creation type of the creation instruction is a function creation type, as provided in an embodiment of the present invention. The specific details are as follows:
[0084] S201. When the creation type of the creation instruction is a function creation type, the function identifier in the creation instruction is used to traverse each built-in function in the preset function library, and the built-in function corresponding to the function identifier is used as the target function.
[0085] When the creation type of the creation instruction is function creation type, the function identifier in the creation instruction will be used to traverse the various built-in functions in the function library. The function library contains multiple built-in functions, and different functions have different functions. Specific built-in functions included in the function library include: random function, uuid function, and currenttime() function, etc. The built-in functions here will not be listed one by one.
[0086] S202. Execute the target function and use the output of the target function as the parameter value corresponding to the creation instruction.
[0087] After determining the target function, it can be executed, yielding its output. This output is then used as the parameter value corresponding to the creation command. Further, the target function is interpreted using an editor, leading to its execution.
[0088] S203. Obtain the variable name based on the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0089] A temporary variable is obtained by creating a command to get the variable name and assigning the parameter value to the variable name. For example, in [%a%=currenttime()], the variable name is a. After assigning a value to a, a becomes a temporary variable. The result of executing the function currenttime() is then assigned to a to get the temporary variable a.
[0090] The process of creating temporary variables using function creation types is illustrated in code form, as shown below:
[0091] {
[0092] "blacklist":{
[0093] "activityType":2001,
[0094] "pin": "lianghaoyi"
[0095] },
[0096] "systemld":"jrcrm-pub-web",
[0097] "systemToken":"[%systemToken%=currenttime()]"
[0098] }
[0099] As can be seen from the code above, the temporary variable is systemToken, and the value in this temporary variable is the result obtained after executing the function currenttime().
[0100] Reference Figure 3 The following is a flowchart of a method for creating temporary variables when the creation type of the creation instruction is a calculation creation type, as provided by the present invention. The specific details are as follows:
[0101] S301. When the creation type of the creation instruction is a calculation creation type, determine the calculation logic corresponding to the calculation identifier in the creation instruction.
[0102] S302. Based on the calculation logic, obtain each test variable corresponding to the calculation identifier from the variable library.
[0103] S303. Perform calculations on each of the test variables according to the calculation logic, and use the results of the calculations as parameter values corresponding to the creation instruction.
[0104] S304. Generate a variable name corresponding to the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0105] Different calculation identifiers correspond to different calculation logics, and different calculation logics apply different test variables. Specifically, if the calculation logic adds test variable 1 and test variable 2, then test variable 1 and test variable 2 are determined in the variable library, and the value obtained by adding test variable 1 and test variable 2 is used as the parameter value. This parameter value is then assigned to a variable name generated according to the creation instruction, thus obtaining a temporary variable. Furthermore, the calculation logic can be applied to the logic during the execution of test cases, thereby creating temporary variables for data generated by the test user during execution.
[0106] Reference Figure 4 The flowchart of the method for generating temporary variables when the creation type of the creation instruction is assignment creation type, as provided by the present invention, is described in detail below:
[0107] S401. When the creation type of the creation instruction is an assignment creation type, obtain the variable name corresponding to the creation instruction from the preset expected value box.
[0108] S402. Obtain the test data returned when the test case is executed, and use the test data as the parameter value corresponding to the creation instruction.
[0109] S403. Assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0110] Staff can enter variable names in the expected value box on the page to obtain the variable names corresponding to the creation instructions; determine the test data returned by the currently executed test case, use the test data as a parameter value, and assign the parameter value to the variable name to obtain a temporary variable; specifically, if the test case calls interface 3 during execution and returns the data obtained from calling interface 3, this data can be used as a parameter value and assigned to the variable name to obtain a temporary variable. In this way, temporary variables can be created for the data returned by the test case during execution, thereby meeting the variable requirements of the test case during execution.
[0111] Based on the various embodiments provided by the present invention described above, before executing the variable generation method corresponding to the creation type based on the creation type corresponding to the creation instruction, each embodiment may first determine the creation type corresponding to the creation instruction; refer to Figure 5 The following is a flowchart of a method for determining the creation type of a creation instruction according to an embodiment of the present invention, which is described in detail below:
[0112] S501. Parse the creation instruction and determine whether the creation instruction contains a function identifier; if the creation instruction contains a function identifier, then execute S502; if the creation instruction does not contain a function identifier, then execute S503.
[0113] S502. Determine that the creation type corresponding to the creation instruction is a function creation type.
[0114] S503. Determine whether the creation instruction contains a calculation identifier; if the creation instruction contains a calculation identifier, then execute S504; if the creation instruction does not contain a calculation identifier, then execute S505.
[0115] S504. Determine that the creation type corresponding to the creation instruction is a calculation creation type.
[0116] S505. Determine that the creation type corresponding to the creation instruction is an assignment creation type.
[0117] The creation instruction is parsed to determine whether it contains a function identifier. The function identifier indicates that the temporary variable is generated by calling a function, and also indicates that the creation type of the creation instruction is a function creation type. Furthermore, the function identifier can be composed of a function name.
[0118] The calculation identifier indicates that the temporary variable is generated by calculation, and also indicates that the creation type of the creation instruction is a calculation creation type. Furthermore, the calculation identifier contains the corresponding calculation logic.
[0119] When the creation instruction does not contain function identifiers and calculation identifiers, it is determined that the creation instruction contains an assignment identifier. This assignment identifier indicates the method of generating temporary variables based on the result returned by the current execution of the test case, and also indicates that the creation type of the creation instruction is an assignment creation type.
[0120] By parsing the creation instructions, the creation type corresponding to the creation instructions can be determined. This allows for the rapid generation of temporary variables using the methods corresponding to the creation type, thereby improving the accuracy and efficiency of temporary variable generation.
[0121] and Figure 1 Correspondingly, the present invention also provides a temporary variable generation apparatus for supporting Figure 1 The method shown can be applied in real-world scenarios. This device can be installed on a low-code testing platform. A schematic diagram of the device is shown below. Figure 6 As shown, the specific explanation is as follows:
[0122] The execution unit 601 is configured to, when a creation instruction for a temporary variable is obtained during the execution of a test case, execute a variable generation method corresponding to the creation type based on the creation type corresponding to the creation instruction, obtain a parameter value corresponding to the creation instruction, and assign a value to the variable name corresponding to the creation instruction based on the parameter value, so as to obtain a temporary variable corresponding to the creation instruction, wherein there is no variable corresponding to the variable name in the variable library of the test case;
[0123] The storage unit 602 is used to save the temporary variable to the variable library so that the test case can call the temporary variable.
[0124] In the method provided by this invention, when a temporary variable creation instruction is obtained during the execution of a test case, the creation type of the creation instruction is determined; the variable generation method corresponding to the creation type is executed to obtain the parameter value corresponding to the creation instruction, and a value is assigned based on the parameter value to the variable name corresponding to the creation instruction to obtain the temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name; the temporary variable is saved to the variable library so that the test case can call the temporary variable. This invention can add temporary variables to test cases. The generation process of temporary variables is simple and convenient. Applying this invention can effectively and promptly supplement the variables missing during the execution of test cases without setting a large number of variables before the execution of test cases, thereby effectively reducing the workload of staff. Adding variables does not interrupt the execution of test cases, thus improving the efficiency of testing test cases written by staff and providing staff with a more convenient way to add variables, thereby improving work efficiency.
[0125] In the apparatus provided in this embodiment of the invention, the execution unit 602 in the apparatus can be configured as follows:
[0126] The traversal subunit is used to, when the creation type of the creation instruction is a function creation type, traverse each built-in function in the preset function library by the function identifier in the creation instruction, and take the built-in function corresponding to the function identifier as the target function;
[0127] An execution subunit is used to execute the objective function and use the output of the objective function as the parameter value corresponding to the creation instruction;
[0128] The first assignment subunit is used to obtain the variable name based on the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0129] In the apparatus provided in this embodiment of the invention, the execution unit 602 in the apparatus can be configured as follows:
[0130] The first determining subunit is used to determine the computation logic corresponding to the computation identifier in the creation instruction when the creation type of the creation instruction is a computation creation type;
[0131] The first acquisition subunit is used to acquire, based on the calculation logic, each test variable corresponding to the calculation identifier from the variable library;
[0132] The calculation subunit is used to perform calculations on each of the test variables according to the calculation logic, and use the result of the calculation as the parameter value corresponding to the creation instruction;
[0133] A generation subunit is used to generate a variable name corresponding to the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
[0134] In the apparatus provided in this embodiment of the invention, the execution unit 602 in the apparatus can be configured as follows:
[0135] The second acquisition subunit is used to acquire the variable name corresponding to the creation instruction from a preset expected value box when the creation type of the creation instruction is an assignment creation type.
[0136] The third acquisition subunit is used to acquire the test data returned when the test case is executed, and use the test data as the parameter value corresponding to the creation instruction;
[0137] The second assignment subunit is used to assign a value to the variable name based on the parameter value, so as to obtain a temporary variable corresponding to the creation instruction.
[0138] In the apparatus provided in this embodiment of the invention, the apparatus may also be configured as follows:
[0139] A determining unit is used to determine the creation type corresponding to the creation instruction;
[0140] The determining unit includes:
[0141] The first judgment unit is used to parse the creation instruction and determine whether the creation instruction contains a function identifier;
[0142] The second determining unit is configured to determine that the creation type corresponding to the creation instruction is a function creation type if the creation instruction contains a function identifier;
[0143] The second judgment unit is used to determine whether the creation instruction contains a calculation identifier if the creation instruction does not contain a function identifier.
[0144] The third determining unit is used to determine that the creation type corresponding to the creation instruction is a calculation creation type if the creation instruction contains a calculation identifier;
[0145] The fourth determining unit is used to determine that the creation type corresponding to the creation instruction is an assignment creation type if the creation instruction does not contain a calculation identifier.
[0146] In the apparatus provided in this embodiment of the invention, the apparatus may also be configured as follows:
[0147] The deletion unit is used to delete the variable library of the test case when the execution of the test case ends.
[0148] This invention also provides a storage medium, the storage medium including storage instructions, wherein, when the instructions are executed, the device where the storage medium is located performs the following operations:
[0149] When a temporary variable creation instruction is obtained during the execution of a test case, a variable generation method corresponding to the creation type is executed based on the creation type corresponding to the creation instruction to obtain the parameter value corresponding to the creation instruction. The parameter value is then used to assign a value to the variable name corresponding to the creation instruction to obtain a temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name.
[0150] The temporary variable is saved to the variable library so that the test case can call the temporary variable.
[0151] This invention also provides an electronic device, the structural schematic of which is shown below. Figure 7 As shown, it specifically includes a memory 701 and one or more instructions 702, wherein one or more instructions 702 are stored in the memory 701 and configured to be executed by one or more processors 703 to perform the following operations:
[0152] When a temporary variable creation instruction is obtained during the execution of a test case, a variable generation method corresponding to the creation type is executed based on the creation type corresponding to the creation instruction to obtain the parameter value corresponding to the creation instruction. The parameter value is then used to assign a value to the variable name corresponding to the creation instruction to obtain a temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name.
[0153] The temporary variable is saved to the variable library so that the test case can call the temporary variable.
[0154] The specific implementation processes and derivative methods of the above embodiments are all within the protection scope of this invention.
[0155] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0156] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0157] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating temporary variables, characterized in that, include: When a temporary variable creation instruction is received during the execution of a test case, either by real-time user input or dynamically triggered by code within the test case, a variable generation method corresponding to the creation type is executed based on the creation type of the instruction. This yields a parameter value corresponding to the creation instruction, and the variable name corresponding to the creation instruction is assigned a value based on the parameter value to obtain the temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name. The variable library of the test case is at least used to store global variables pre-loaded from the test case. The temporary variable is saved to the variable library so that the test case can call the temporary variable.
2. The method according to claim 1, characterized in that, The step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value, to obtain a temporary variable corresponding to the creation instruction, includes: When the creation type of the creation instruction is a function creation type, the function identifier in the creation instruction is used to traverse each built-in function in the preset function library, and the built-in function corresponding to the function identifier is used as the target function; Execute the target function and use the output of the target function as the parameter value corresponding to the creation instruction; The variable name is obtained based on the creation instruction, and a value is assigned to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
3. The method according to claim 1, characterized in that, The step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value, to obtain a temporary variable corresponding to the creation instruction, includes: When the creation type of the creation instruction is a calculation creation type, determine the calculation logic corresponding to the calculation identifier in the creation instruction; Based on the calculation logic, each test variable corresponding to the calculation identifier is obtained from the variable library; According to the calculation logic, each of the test variables is calculated, and the result of the calculation is used as the parameter value corresponding to the creation instruction; Generate a variable name corresponding to the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
4. The method according to claim 1, characterized in that, The step of executing a variable generation method corresponding to the creation type based on the creation instruction to obtain the parameter value corresponding to the creation instruction, and assigning a value to the variable name corresponding to the creation instruction based on the parameter value, to obtain a temporary variable corresponding to the creation instruction, includes: When the creation type of the creation instruction is an assignment creation type, the variable name corresponding to the creation instruction is obtained from the preset expected value box; Obtain the test data returned when the test case is executed, and use the test data as the parameter value corresponding to the creation instruction; The variable name is assigned a value based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
5. The method according to any one of claims 1 to 4, characterized in that, Before executing the variable generation method corresponding to the creation type based on the creation instruction, the method further includes: Determine the creation type corresponding to the creation instruction; The step of determining the creation type corresponding to the creation instruction includes: The creation instruction is parsed, and it is determined whether the creation instruction contains a function identifier; If the creation instruction contains a function identifier, then the creation type corresponding to the creation instruction is determined to be a function creation type; If the creation instruction does not contain a function identifier, then determine whether the creation instruction contains a calculation identifier; If the creation instruction contains a calculation identifier, then the creation type corresponding to the creation instruction is determined to be a calculation creation type; If the creation instruction does not contain a calculation identifier, then the creation type corresponding to the creation instruction is determined to be an assignment creation type.
6. The method according to claim 1, characterized in that, Also includes: When the test case finishes execution, the variable library for that test case is deleted.
7. A device for generating temporary variables, characterized in that, include: An execution unit is configured to, during the execution of a test case, receive a creation instruction for a temporary variable that is input in real time by the user or dynamically triggered by code within the test case. Based on the creation type corresponding to the creation instruction, the unit executes a variable generation method corresponding to the creation type to obtain a parameter value corresponding to the creation instruction. The unit then assigns a value to the variable name corresponding to the creation instruction based on the parameter value to obtain a temporary variable corresponding to the creation instruction. The variable library of the test case does not yet contain a variable corresponding to the variable name. The variable library of the test case is used to store at least the global variables pre-loaded from the test case. A storage unit is used to save the temporary variable to the variable library so that the test case can call the temporary variable.
8. The apparatus according to claim 7, characterized in that, The execution unit includes: The traversal subunit is used to, when the creation type of the creation instruction is a function creation type, traverse each built-in function in the preset function library by the function identifier in the creation instruction, and take the built-in function corresponding to the function identifier as the target function; An execution subunit is used to execute the objective function and use the output of the objective function as the parameter value corresponding to the creation instruction; The first assignment subunit is used to obtain the variable name based on the creation instruction, and assign a value to the variable name based on the parameter value to obtain a temporary variable corresponding to the creation instruction.
9. A storage medium, characterized in that, The storage medium includes stored instructions, wherein, when the instructions are executed, the device where the storage medium is located is controlled to perform the method for generating temporary variables as described in any one of claims 1 to 6.
10. An electronic device, characterized in that, It includes memory, and one or more instructions, wherein one or more instructions are stored in memory and configured to be executed by one or more processors as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method of operating a computer to produce test case programmes
GB1479122A