A test case citation method and device
By judging and assigning reference variables to public test cases in test cases, the problem of insufficient flexibility in public operation reference methods in the existing technology is solved, and the flexibility and reusability of test cases are improved, reducing the redundant cases. produce.
Patent Information
- Application Number
- CN202010470154.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-28
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-05-28
AI Technical Summary
The citation methods of public operations in the prior art in test cases cannot flexibly adjust parameters according to requirements, resulting in a decrease in flexibility in public test cases, increasing labor consumption and the generation of redundant cases.
When executing the main test case, determine whether the reference variable in the public test case needs to be overwritten. If necessary, use a preset new value to assign. If not, use a preset assignment strategy to perform the operation steps in the public test case. .
The flexibility of public test cases is improved through user-defined new value assignments, and a single public test case is adapted to multiple situations, reducing case redundancy.
Smart Images

Figure CN111813654B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a test case citing method and device. Background Art
[0002] When technical personnel are writing test cases, if some common operations are scattered in various test cases, if the common operations change later, the common operation part of each test case needs to be modified, which causes unnecessary manpower consumption.
[0003] Therefore, the relevant public operations are usually extracted as a public test case and called and executed by reference. However, the existing common reference method is to treat the entire public test case as a static operation process and add it to the main case. It is impossible to set the parameters in the referenced public test case according to the needs, which greatly reduces the flexibility of the public test case. Summary of the invention
[0004] The purpose of the present invention is to propose a test case citing method and device in view of the above-mentioned deficiencies in the prior art, and the purpose is achieved through the following technical solutions.
[0005] A first aspect of the present invention provides a method for citing a test case, the method comprising:
[0006] During the execution of the main test case, when executing the referenced common test case, determining whether the referenced variable in the common test case needs to be overwritten;
[0007] If necessary, assigning a value to the reference variable using a preset new value; the preset new value refers to the value reset for the reference variable included in the referenced public test case in the main test case;
[0008] If not necessary, assign a value to the reference variable using a preset assignment strategy;
[0009] The operation steps in the common test case are executed based on the assigned reference variables.
[0010] A second aspect of the present invention provides a test case citing device, the device comprising:
[0011] A judgment module, used for judging whether a referenced variable in a common test case needs to be overwritten when executing the referenced common test case during the execution of the main test case;
[0012] A first assignment module is used to assign a value to the reference variable using a preset new value when the judgment result is required; the preset new value refers to the numerical value reset for the reference variable included in the referenced public test case in the main test case;
[0013] A second assignment module, used for assigning a value to the reference variable using a preset assignment strategy when the judgment result is that it is not needed;
[0014] The case execution module is used to execute the operation steps in the common test case based on the assigned reference variables.
[0015] The third aspect of the present invention proposes a computer device, including a storage medium and a processor, wherein the storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the test case reference method described in the first aspect above.
[0016] In an embodiment of the present invention, during the execution of the main test case, when executing the referenced public test case, it is determined whether the referenced variable in the public test case needs to be overwritten. If so, the referenced variable is assigned a value using a preset new value; if not, the referenced variable is assigned a value using a preset assignment strategy, and then the operation steps in the public test case are executed based on the assigned referenced variable.
[0017] Based on the above description, we can know that the variables of the referenced cases can be assigned according to the new values set by the user, which greatly improves the flexibility of the public test cases. In addition, for different scenarios of the main test cases, different set values can be used to control the running process and score of the referenced cases, so that a single public test case can be adapted to multiple situations, which improves the reusability of the public test cases and thus achieves the purpose of reducing case redundancy. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0019] Figure 1 This is a flow chart of an embodiment of a method for citing a test case according to an exemplary embodiment of the present invention;
[0020] Figure 2 The present invention is based on Figure 1 A schematic diagram of the composition of a common test case shown in the illustrated embodiment;
[0021] Figure 3 The present invention is based on Figure 1A schematic diagram of the overall execution structure of a script of a main test case shown in the illustrated embodiment;
[0022] Figure 4 A hardware structure diagram of a computer device according to an exemplary embodiment of the present invention;
[0023] Figure 5 The present invention is a flowchart of an embodiment of a device for citing a test case according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0024] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0025] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0026] It should be understood that although the terms first, second, third, etc. may be used in the present invention to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0027] Interface automation testing is an important test method to ensure system quality due to its high efficiency and stability. There are many ways to implement it, including coding and many visual online editing platforms for writing test cases. However, due to the need for rapid verification of interface automation testing, the threshold for writing interface automation cases should not be too high. Therefore, web-based visual editing is often used for case writing.
[0028] In the process of writing test cases, if some common operations are scattered in various test cases, if the common operations change later, the common operation part of each test case needs to be modified, which lacks flexibility and causes unnecessary manpower consumption.
[0029] Therefore, related operations are usually extracted as a public test case and called for execution through reference. However, the existing common reference method is to treat the public test case as a static operation process for execution. The variable parameters in the public test case cannot be modified and customized, and it is difficult to flexibly adjust according to actual needs, which greatly reduces the flexibility of public test case references, resulting in the need to write multiple public test cases for different scenarios, and there is a lot of redundancy.
[0030] In order to solve the above technical problems, the present invention improves the variable value taking method when the test case is executed, that is, during the execution of the main test case, when the referenced public test case is executed, it is determined whether the referenced variable in the public test case needs to be overwritten. If necessary, the referenced variable is assigned a value using a preset new value; if not, the referenced variable is assigned a value using a preset assignment strategy, and then the operation steps in the public test case are executed based on the assigned referenced variable.
[0031] Based on the above description, we can know that the variables of the referenced cases can be assigned according to the new values set by the user, which greatly improves the flexibility of the public test cases. In addition, for different scenarios of the main test cases, different set values can be used to control the running process and score of the referenced cases, so that a single public test case can be adapted to multiple situations, which improves the reusability of the public test cases and thus achieves the purpose of reducing case redundancy.
[0032] The reference method of the test case proposed by the present invention is described in detail below with specific embodiments.
[0033] Figure 1 This is a flow chart of an embodiment of a method for referencing a test case according to an exemplary embodiment of the present invention. The method for referencing a test case can be applied on a computer device, and includes the following steps:
[0034] Step 101: During the execution of the main test case, when executing the referenced public test case, determine whether the referenced variables in the public test case need to be overwritten. If yes, execute step 102; if no, execute step 103.
[0035] Before executing step 101, new values may be set in advance for reference variables in the public test case referenced by the main test case. The setting process may be: extracting case information of the referenced public test case from the main test case, and using the case information to request the script of the public test case, and extracting the reference variables in the public test case from the script, and outputting and displaying them. If a new value for the reference variable is received, the reference variable and the new value are correspondingly saved in the main test case.
[0036] The extracted case information of the public test case may include a case name, a case ID, and the like.
[0037] In the present invention, see Figure 2 As shown, in order to implement the reference of functional public test cases, the public test cases are divided into the following three parts:
[0038] ①Case operation steps: define the actual execution steps of the case, including request information, database operations, various assertions, etc.
[0039] ② Case fixed parameters: Parameters that do not need to change with the case, which can be understood as case constants.
[0040] ③Case reference variables: Dynamic variables used in the case need to be declared through local variables or system variables.
[0041] Among them, the reference variables in the third part are variables that can be flexibly set when referencing.
[0042] Taking the case editing method based on web visual editing as an example, when editing the main test case on the page, the script of the main test case (such as json script) can be formatted through JavaScript (page script language) to convert the script of the main test case into an object recognizable by the scripting language to extract the case information of the referenced public test case, and then use the case information to request the script of the corresponding public test case, and extract the information of the referenced variables contained in the script (such as variable name, variable initial value, etc.) through regular expressions, and then use dynamic rendering technology to output the information of the referenced variables and display it on the page, and the user can reset the value of the referenced variable of the public test case.
[0043] It can be seen that after the main test case selects the relevant public test case for reference, the reference variables contained in the referenced case will be listed on the page. The user can modify the reference variable value according to the scenario of the current main test case to control the running process and branches of the referenced case.
[0044] In some embodiments, if a new value for the reference variable is received, the reference variable and the new value are saved correspondingly in the main test case, and attribute information to be overwritten can be set for the reference variable in the main test case. If no new value for the reference variable is received, attribute information that does not need to be overwritten is set for the reference variable.
[0045] In an example, the attribute information can be "0" or "1", "0" indicates that no overwriting is required, and "1" indicates that overwriting is required. For reference variables whose values are not modified by the user, the attribute information is represented by "0", and for reference variables whose values are modified by the user, the attribute information is represented by "1".
[0046] Based on this, for the process of step 101, the attribute information of the reference variable can be searched in the main test case. If the attribute information found is to be overwritten, it is determined that the reference variable needs to be overwritten, and step 102 is executed. If the attribute information found is not to be overwritten, it is determined that the reference variable does not need to be overwritten, and step 103 is executed.
[0047] Step 102: Assign a value to the reference variable using a preset new value.
[0048] Based on the description of step 101 above, the reference variable is assigned a value by searching for a new value corresponding to the reference variable in the main test case.
[0049] Among them, since the new value of the reference variable modified by the user is saved in the main test case rather than the public test case, the parameter can only be used in the scenario of the main test case and will not affect other test cases. Therefore, the present invention can realize the respective needs of different cases and greatly improve the flexibility of case reference.
[0050] That is, the preset new value refers to the value reset in the main test case for the reference variable contained in the referenced public test case.
[0051] Step 103: Assign a value to the reference variable using a preset assignment strategy.
[0052] In one embodiment, if there is no need to overwrite the parameters of the reference variable, you can first search in the script of the public test case to see if there is a declaration of the reference variable. If there is a declaration, the declared value is used to assign a value to the reference variable. If there is no declaration, search the main test case for a variable that matches the reference variable, and use the value of the matching variable to assign a value to the reference variable.
[0053] It should be noted that since the main test case stores a variety of variable types, including associated variables generated by the executed operation steps (obtained through HTTP requests and returned, and extracted from the return through regular expressions or jsonpath, etc.), local variables (variables declared in the main test case), and global variables (variables defined in the system settings), it is possible to set a reasonable priority order to search in sequence to achieve the assignment of reference variables in the public test case.
[0054] Based on this, for the process of searching for a variable that matches the reference variable in the main test case, you can first search in the main test case whether there is an associated variable that matches the reference variable. If the associated variable is found, the found associated variable is determined as the variable that matches the reference variable. If the associated variable is not found, then search in the main test case whether there is a local variable that matches the reference variable. If the local variable is found, the found local variable is determined as the variable that matches the reference variable. If the local variable is not found, then search in the main test case for a global variable that matches the reference variable, and determine the found global variable as the variable that matches the reference variable.
[0055] The variable that matches the reference variable refers to the variable name matching.
[0056] Step 104: Execute the operation steps in the common test case based on the assigned reference variables.
[0057] See also Figure 3 , which is a schematic diagram of the overall execution structure of the script of the main test case. The script of the main test case includes three parts: variable setting, operation steps and environment setting. The information storage area in the case executor will store the variable definition information (such as variable name, variable type, value, etc.) and environment information (such as environment address, database address, etc.) in the script. During the execution process, when executing the public test case, first obtain the script of the public test case, and then assign values to the reference variables contained in the public test case. The specific assignment method is the process from step 101 to step 103 above, and then obtain the environment information for filling, and execute the operation steps in the public test case, and then obtain the execution result, and assert the result, and continue to obtain the next operation step in the main test case for execution.
[0058] At this point, the above Figure 1 The reference flow of the test case shown is through Figure 1The process shown can assign values to the variables of the referenced cases according to the new values set by the user, which greatly improves the flexibility of the public test cases. In addition, for different scenarios of the main test cases, different set values can be used to control the running process and score of the referenced cases, so that a single public test case can be adapted to multiple situations, improving the reusability of the public test cases and thus achieving the purpose of reducing case redundancy.
[0059] Figure 4 This is a hardware structure diagram of a computer device according to an exemplary embodiment of the present invention, and the computer device includes: a communication interface 401, a processor 402, a machine-readable storage medium 403, and a bus 404; wherein the communication interface 401, the processor 402, and the machine-readable storage medium 403 communicate with each other through the bus 404. The processor 402 can execute the test case reference method described above by reading and executing the machine executable instructions corresponding to the control logic of the test case reference method in the machine-readable storage medium 403. The specific content of the method is referred to the above embodiment, and will not be repeated here.
[0060] The machine-readable storage medium 403 mentioned in the present invention can be any electronic, magnetic, optical or other physical storage device, which can contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium can be: volatile memory, non-volatile memory or similar storage medium. Specifically, the machine-readable storage medium 403 can be RAM (Random Access Memory), flash memory, storage drive (such as hard disk drive), any type of storage disk (such as optical disk, DVD, etc.), or similar storage medium, or a combination thereof.
[0061] Corresponding to the above-mentioned embodiment of the method for citing a test case, the present invention also provides an embodiment of a device for citing a test case.
[0062] Figure 5 This is a flow chart of an embodiment of a device for citing a test case according to an exemplary embodiment of the present invention. The device for citing a test case can be applied on a computer device. The device for citing a test case includes:
[0063] The judgment module 510 is used to judge whether the referenced variables in the common test case need to be overwritten when executing the referenced common test case during the execution of the main test case;
[0064] A first assignment module 520 is used to assign a value to the reference variable using a preset new value when the judgment result is required; the preset new value refers to the value reset for the reference variable included in the referenced public test case in the main test case;
[0065] A second assignment module 530, configured to assign a value to the reference variable using a preset assignment strategy when the judgment result is that it is not necessary;
[0066] The case execution module 540 is used to execute the operation steps in the common test case based on the assigned reference variables.
[0067] In an optional implementation, the device further includes ( Figure 5 Not shown):
[0068] A setting module is used to extract the case information of the referenced public test case from the main test case before the judgment module 510 judges whether the referenced variable in the public test case needs to be overwritten; use the case information to request the script of the public test case, and extract the referenced variable in the public test case from the script, and output it for display; if a new value for the referenced variable is received, the referenced variable and the new value are saved in the main test case accordingly.
[0069] In an optional implementation, the setting module is further used to, if a new value for the reference variable is received, save the reference variable and the new value correspondingly in the main test case, and set attribute information to be overwritten for the reference variable; if no new value for the reference variable is received, set attribute information that does not need to be overwritten for the reference variable.
[0070] In an optional implementation, the judgment module 510 is specifically used to search for the attribute information of the reference variable in the main test case; if the attribute information found needs to be overwritten, it is determined that the reference variable needs to be overwritten; if the attribute information found does not need to be overwritten, it is determined that the reference variable does not need to be overwritten.
[0071] In an optional implementation, the second assignment module 530 is specifically used to search whether there is a declaration of the reference variable in the script of the common test case; if there is a declaration, the reference variable is assigned a value using the declaration value; if there is no declaration, the main test case is searched for a variable that matches the reference variable, and the reference variable is assigned a value using the value of the matching variable.
[0072] In an optional implementation, the second assignment module 530 is specifically used to search whether there is an associated variable matching the reference variable in the main test case during the process of searching for a variable matching the reference variable in the main test case; if an associated variable is found, the found associated variable is determined as a variable matching the reference variable; if no associated variable is found, search whether there is a local variable matching the reference variable in the main test case; if a local variable is found, the found local variable is determined as a variable matching the reference variable; if no local variable is found, search the main test case for a global variable matching the reference variable, and determine the found global variable as a variable matching the reference variable.
[0073] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0074] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.
[0075] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art not disclosed by the present invention. The description and examples are to be regarded as exemplary only, and the true scope and spirit of the present invention is indicated by the following claims.
[0076] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0077] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A test case citation method, characterized in that: The method comprises: During the execution of the main test case, when executing the referenced common test case, determining whether the referenced variable in the common test case needs to be overwritten; If necessary, assigning a value to the reference variable using a preset new value; the preset new value refers to the value reset for the reference variable included in the referenced public test case in the main test case; If not necessary, assign a value to the reference variable using a preset assignment strategy; Execute the operation steps in the common test case based on the assigned reference variable; Wherein, assigning a value to the reference variable by using a preset assignment strategy includes: Searching in the script of the public test case whether there is a declaration of the reference variable; If there is a declaration, assign the reference variable a value using the declared value; If there is no declaration, searching the main test case for a variable that matches the reference variable, and assigning a value to the reference variable using the value of the matching variable; The step of searching the main test case for a variable that matches the reference variable comprises: Searching in the main test case whether there is an associated variable matching the reference variable; If an associated variable is found, the found associated variable is determined as a variable that matches the reference variable; If no associated variable is found, then searching in the main test case whether there is a local variable matching the reference variable; If a local variable is found, the found local variable is determined as a variable that matches the reference variable; If no local variable is found, a global variable matching the reference variable is searched in the main test case, and the found global variable is determined as a variable matching the reference variable.
2. The method according to claim 1, characterized in that The method further comprises: Before determining whether the referenced variable in the public test case needs to be overwritten, extracting case information of the referenced public test case from the main test case; Requesting a script of the public test case using the case information, extracting reference variables in the public test case from the script, and outputting and displaying the variables; If a new value for the reference variable is received, the reference variable and the new value are correspondingly saved in the main test case.
3. The method according to claim 2, characterized in that The method further comprises: If a new value for the reference variable is received, the reference variable and the new value are correspondingly saved in the main test case, and attribute information to be overwritten is set for the reference variable; If no new value for the reference variable is received, attribute information that does not need to be overwritten is set for the reference variable.
4. The method according to claim 3, characterized in that Determining whether the reference variable in the public test case needs to be overwritten includes: Searching for attribute information of the reference variable in the main test case; If the found attribute information needs to be overwritten, it is determined that the reference variable needs to be overwritten; If the found attribute information does not need to be overwritten, it is determined that the reference variable does not need to be overwritten.
5. A test case citing device, characterized in that: The device comprises: A judgment module, used for judging whether a referenced variable in a common test case needs to be overwritten when executing the referenced common test case during the execution of the main test case; A first assignment module is used to assign a value to the reference variable using a preset new value when the judgment result is required; the preset new value refers to the numerical value reset for the reference variable included in the referenced public test case in the main test case; A second assignment module, used for assigning a value to the reference variable using a preset assignment strategy when the judgment result is that it is not needed; A case execution module, used for executing the operation steps in the common test case based on the assigned reference variables; The second assignment module is specifically used to search whether there is a declaration of the reference variable in the script of the common test case; if there is a declaration, assign a value to the reference variable using the declaration value; if there is no declaration, search for a variable matching the reference variable in the main test case, and assign a value to the reference variable using the value of the matching variable; The second assignment module is specifically used to search whether there is an associated variable matching the reference variable in the main test case during the process of searching for a variable matching the reference variable in the main test case; if an associated variable is found, the found associated variable is determined as a variable matching the reference variable; if no associated variable is found, search whether there is a local variable matching the reference variable in the main test case; if a local variable is found, the found local variable is determined as a variable matching the reference variable; if no local variable is found, search the main test case for a global variable matching the reference variable, and determine the found global variable as a variable matching the reference variable.
6. The device according to claim 5, characterized in that The device also includes: A setting module is used to extract the case information of the referenced public test case from the main test case before the judgment module judges whether the referenced variable in the public test case needs to be overwritten; use the case information to request the script of the public test case, and extract the referenced variable in the public test case from the script, and output it for display; if a new value for the referenced variable is received, the referenced variable and the new value are saved in the main test case accordingly.
7. A computer device, characterized in that: The method comprises a storage medium and a processor, wherein the storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the steps of the test case citing method according to any one of claims 1 to 4.
