A method and device for parameterizing test cases in an automated testing framework

By using global variable setting and retrieval methods in the automated testing framework and identifying interface parameters with identifiers, the code redundancy problem caused by interface parameter passing is solved, and automatic passing of interface parameters and code simplification are achieved.

CN114048140BActive Publication Date: 2024-11-12HANGZHOU YOWANT NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111394278.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-23
Publication Date
2024-11-12
Estimated Expiration
2041-11-23

AI Technical Summary

Technical Problem

In existing automated testing frameworks, parameter passing between interfaces needs to be implemented by defining methods, resulting in code redundancy and failing to effectively support projects with complex process connections.

Method used

By defining global variable setting and retrieval methods in the automated testing framework, and using identifiers (such as ^ and $) to identify interface parameters, automatic parameter passing is achieved, avoiding the need to redefine methods.

Benefits of technology

It effectively avoids code redundancy, simplifies the process of passing interface parameters, and improves the efficiency of automated testing and the maintainability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114048140B_ABST
    Figure CN114048140B_ABST
Patent Text Reader

Abstract

The present application discloses a parameterization method for test cases in an automated testing framework, which predefines a global variable setting method and a global variable reading method. When a test case reads a first identifier in a configuration file, the global variable setting method is called to implement a corresponding global variable setting process. When a test case reads a second identifier in a configuration file, the global variable reading method is called to implement a corresponding global variable reading process, and finally interface parameter transfer between test cases is implemented, effectively avoiding the problem of code redundancy caused by defining interface parameters as methods to implement interface parameter transfer. In addition, the present application also provides a parameterization device, computer equipment, and computer-readable storage medium for test cases in an automated testing framework, and the technical effects thereof correspond to the technical effects of the above-mentioned method.
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 method, device, computer equipment and computer-readable storage medium for parameterizing test cases in an automated testing framework. Background Art

[0002] Pytest is an automated testing framework for Python. All parameterized processes in the framework are implemented by reading yaml files. However, in fact, each test case reads an independent configuration file. For example, testcase1 reads yaml1 and testcase2 reads yaml2. After reading, testcase1 and testcase 2 are used independently. The disadvantage of this method is that when testcase1 and testcase2 are related, such as testcase1 is a login interface, and testcase2 is a new interface that depends on the token obtained by logging in to testcase1, the existing framework does not support testcase2 to obtain the parameters of testcase1.

[0003] In the current automated testing framework, when a single interface script reads parameters and encounters parameters that need to be passed between interfaces, most of the time the required parameters are defined as methods so that other interfaces can call them directly. This method requires writing many methods when encountering projects with complex process associations, involving associated parameters, resulting in code redundancy. Summary of the invention

[0004] The purpose of this application is to provide a method, device, computer equipment and computer-readable storage medium for parameterizing test cases in an automated test framework, so as to solve the problem that parameter transfer between interfaces in the automated test framework currently needs to be implemented through definition methods, resulting in code redundancy. The specific scheme is as follows:

[0005] In a first aspect, the present application provides a method for parameterizing test cases in an automated testing framework, comprising:

[0006] Executing test cases through an automated testing framework to traverse a configuration file and determine interface parameters with identifiers in the configuration file;

[0007] If the identifier is the first identifier, determining the reading result of the interface parameter according to the configuration file, and calling a global variable setting method to set the interface parameter as a global variable;

[0008] If the identifier is the second identifier, calling a global variable acquisition method to read the interface parameter to obtain a reading result of the interface parameter;

[0009] The parameterization result of the test case is determined according to the reading result of the interface parameter.

[0010] Optionally, before executing the test case through the automated testing framework to traverse the configuration file and determine the interface parameter with the identifier in the configuration file, the method further includes:

[0011] defining identifiers, the identifiers comprising a first identifier and a second identifier;

[0012] A global variable setting method associated with the first identifier is created, and a global variable obtaining method associated with the second identifier is created.

[0013] Optionally, after the defining identifier, the identifier including the first identifier and the second identifier, further includes:

[0014] Based on a configuration request, sets an identifier for an interface parameter in a configuration file.

[0015] Optionally, the interface parameter includes a field name and a field value, and setting an identifier for the interface parameter in the configuration file according to the configuration request includes:

[0016] According to the configuration request, add identifiers to the field names of the interface parameters in the configuration file.

[0017] Optionally, after determining the parameterization result of the test case according to the reading result of the interface parameter, the method further includes:

[0018] The test case is executed according to the parameterized result of the test case through the automated testing framework to realize automated testing.

[0019] Optionally, determining the parameterization result of the test case according to the reading result of the interface parameter includes:

[0020] For the interface parameter with the identifier, the identifier in the reading result of the interface parameter is deleted, and the reading result of the interface parameter after deleting the identifier is used as the parameterization result of the test case.

[0021] Optionally, when the configuration file includes an interface parameter without an identifier, taking the reading result of the interface parameter after deleting the identifier as the parameterization result of the test case includes:

[0022] The reading result of the interface parameter after deleting the identifier and the reading result of the interface parameter without the identifier are taken as the parameterization result of the test case.

[0023] In a second aspect, the present application provides a parameterization device for test cases in an automated testing framework, comprising:

[0024] A traversal module, used for executing test cases through an automated testing framework to traverse a configuration file and determine interface parameters with identifiers in the configuration file;

[0025] A global variable setting module, configured to determine the reading result of the interface parameter according to the configuration file if the identifier is the first identifier, and call a global variable setting method to set the interface parameter as a global variable;

[0026] A global variable reading module, configured to, if the identifier is the second identifier, call a global variable acquisition method to read the interface parameter and obtain a reading result of the interface parameter;

[0027] The result output module is used to determine the parameterization result of the test case according to the reading result of the interface parameter.

[0028] In a third aspect, the present application provides a computer device, comprising:

[0029] Memory: used to store computer programs;

[0030] Processor: used to execute the computer program to implement the parameterization method of test cases in the automated testing framework as described above.

[0031] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for parameterizing test cases in the automated testing framework as described above is implemented.

[0032] The present application provides a parameterization method for test cases in an automated testing framework, comprising: executing test cases through the automated testing framework to traverse a configuration file, and determining an interface parameter with an identifier in the configuration file; if the identifier is a first identifier, determining a reading result of the interface parameter according to the configuration file, and calling a global variable setting method to set the interface parameter as a global variable; if the identifier is a second identifier, calling a global variable acquisition method to read the interface parameter and obtaining a reading result of the interface parameter; and determining a parameterization result of the test case according to the reading result of the interface parameter.

[0033] It can be seen that the method predefines a global variable setting method and a global variable reading method. When the test case reads the first identifier in the configuration file, the global variable setting method is called to implement the corresponding global variable setting process. When the test case reads the second identifier in the configuration file, the global variable reading method is called to implement the corresponding global variable reading process, and finally the interface parameter passing between test cases is realized, which effectively avoids the problem of code redundancy caused by defining the interface parameters as methods to realize interface parameter passing.

[0034] In addition, the present application also provides a parameterization device, computer equipment and computer-readable storage medium for test cases in an automated testing framework, the technical effects of which correspond to the technical effects of the above-mentioned method and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions of the prior art, the drawings required for use in the embodiments or the description of the prior art 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 paying any creative work.

[0036] Figure 1 This is a flowchart of Example 1 of a parameterization method for test cases in an automated testing framework provided by the present application;

[0037] Figure 2 This is a flowchart of Example 2 of a parameterization method for test cases in an automated testing framework provided by this application;

[0038] Figure 3 A functional block diagram of an embodiment of a parameterization device for test cases in an automated testing framework provided by the present application;

[0039] Figure 4 This is a schematic diagram of the structure of a computer device embodiment provided in this application. DETAILED DESCRIPTION

[0040] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0041] The core of this application is to provide a parameterization method, device, computer equipment and computer-readable storage medium for test cases in an automated testing framework. By setting identifiers, all configuration files starting with the first identifier are for setting global variables, and those starting with the second identifier are for obtaining global variables, thereby solving the problem that the automated testing framework pytest cannot pass variables in upstream and downstream associated interfaces.

[0042] The following is an introduction to the first embodiment of the parameterization method of test cases in the automated testing framework provided by this application. Figure 1 , Embodiment 1 includes:

[0043] S11, executing the test case through the automated testing framework to traverse the configuration file and determine the interface parameters with the identifier in the configuration file;

[0044] S12. If the identifier is the first identifier, determine the reading result of the interface parameter according to the configuration file, and call the global variable setting method to set the interface parameter as a global variable;

[0045] S13. If the identifier is the second identifier, calling the global variable acquisition method to read the interface parameters to obtain the reading result of the interface parameters;

[0046] S14. Determine the parameterization result of the test case according to the reading result of the interface parameter.

[0047] Define two identifiers in the general method, such as the first identifier and the second identifier, where the first identifier indicates setting a global variable and the second identifier indicates obtaining a global variable; then loop through the parameters or return results, determine whether the passed-in parameters include the first identifier or the second identifier, and perform operations of setting and obtaining global variables respectively. In this way, the required parameters are set as global variables when executing the interface, and other interfaces can directly obtain the set global variables when they need the parameters, which not only realizes parameter transfer between interfaces, but also reduces code redundancy.

[0048] As a specific implementation method, the YAML format is used to configure parameters, giving full play to its advantages such as high readability and simple syntax. This embodiment can also solve the problem that the YAML format does not support variables, making parameter passing more convenient and more conducive to automated testing.

[0049] Specifically, the interface parameter includes a field name and a field value. As a specific implementation method, the identifier is used as a prefix of the field name of the interface parameter.

[0050] After obtaining the reading result of the interface parameter, for the interface parameter with the identifier, the identifier in the reading result of the interface parameter is deleted, and the reading result of the interface parameter after deleting the identifier is used as the parameterization result of the test case. It is understandable that if the configuration file includes the interface parameter without the identifier, the reading result of the interface parameter after deleting the identifier is used together with the reading result of the interface parameter without the identifier as the parameterization result of the test case.

[0051] After the parameterization result of the test case is obtained, the test case can be executed according to the parameterization result of the test case through the automated testing framework to realize automated testing.

[0052] The present embodiment provides a parameterization method for test cases in an automated testing framework. The method predefines a global variable setting method and a global variable reading method. When a test case reads a first identifier in a configuration file, the global variable setting method is called to implement a corresponding global variable setting process. When a test case reads a second identifier in a configuration file, the global variable reading method is called to implement a corresponding global variable reading process. Finally, interface parameter transfer between test cases is realized, effectively avoiding the problem of code redundancy caused by defining interface parameters as methods to realize interface parameter transfer.

[0053] The following is a detailed description of the second embodiment of the parameterization method of test cases in the automated testing framework provided by this application. Figure 2 , Embodiment 2 specifically includes:

[0054] S21. Define an identifier, where the identifier includes a first identifier and a second identifier;

[0055] S22, creating a global variable setting method associated with the first identifier, and creating a global variable obtaining method associated with the second identifier;

[0056] S23, the interface parameters include field names and field values. According to the configuration request, an identifier is added to the field name of the interface parameter in the configuration file;

[0057] S24, executing the test case through the automated testing framework to traverse the configuration file and determine the interface parameters with the identifier in the configuration file;

[0058] S25. If the identifier is the first identifier, determine the reading result of the interface parameter according to the configuration file, and call the global variable setting method to set the interface parameter as a global variable; if the identifier is the second identifier, call the global variable acquisition method to read the interface parameter to obtain the reading result of the interface parameter;

[0059] S26. For the interface parameters with identifiers, delete the identifiers in the reading results of the interface parameters, and use the reading results of the interface parameters after deleting the identifiers together with the reading results of the interface parameters without identifiers as the parameterization results of the test case;

[0060] S27. Execute the test case according to the parameterized result of the test case through the automated testing framework to realize automated testing.

[0061] The implementation process of this embodiment is described in detail below using actual application as an example.

[0062] 1. General method definition

[0063] 1. General method: define and obtain global variables through Python's global, define global dictionary type variables to store global public variables, and set two general methods for adding and deleting public variables in the general method;

[0064] 2. Loop through the parameters, read the parameters with these two identifiers, and then call the general method to set or get the global variables.

[0065] 3. When setting or getting variables, remove the prefix of the first parameter with a specific identifier and store it in a new dictionary; the user's new dictionary data replaces the original parameters to ensure the correctness of the final uploaded parameters.

[0066] 2. Execution

[0067] 1. Configure the interface json parameters in the YAML file, where the parameters in params have specific identifiers, such as ^pageIndex and $pageSize1 in this example.

[0068] 2. When executing the test case through pytest, the yaml file will be read through the self-encapsulated get_test_data method, and each node of the yaml will be traversed to obtain the field name and field value with the identifier.

[0069] 3. Process the read results, add a call to the traversal method, determine whether it contains an identifier, process the parameters containing the identifier using the general method, call the parameters starting with ^ to set global variables, and call the parameters starting with $ to get global variables.

[0070] 4. Process the original parameters, remove the identifiers in the header, such as: ^pageIndex becomes pageIndex, $pageSize1 becomes pageSize1, and finally assemble them into the correct parameter results.

[0071] 5. Test the case script and pass the assigned correct json parameters to the interface, so that the interface can work normally.

[0072] In summary, this embodiment defines two general identifiers such as ^ and $, ^ is used to set global variables, and $ is used to obtain global variables. When configuring yaml parameters, if testcase1 reads ^token in the configuration file, testcase1 calls a general method to set token as a global variable. Similarly, if testcase2 is $token, a general method is called to obtain token from a global variable and return it to testcase2. The processing process of the general method is: loop through the parameters, determine whether the incoming parameters start with ^ or $, and perform the operations of setting global variables and obtaining global variables respectively. Finally, the tokens of testcase1 and testcase2 are processed by two general identifiers and general methods and become globally shared variables.

[0073] This embodiment calls a general method to traverse parameters, and determines the definition and acquisition of variables by itself, instead of manual definition and acquisition, which is more in line with the original intention of automation; moreover, in this embodiment, repeated parameter values ​​only need to be defined once, reducing code redundancy.

[0074] The following is an introduction to the parameterization device for test cases in the automated testing framework provided in an embodiment of the present application. The parameterization device for test cases in the automated testing framework described below and the parameterization method for test cases in the automated testing framework described above can refer to each other.

[0075] like Figure 3 As shown, the parameterization device of the test case in the automated testing framework of this embodiment includes:

[0076] A traversal module 31 is used to execute test cases through an automated testing framework to traverse the configuration file and determine interface parameters with identifiers in the configuration file;

[0077] A global variable setting module 32, for determining the reading result of the interface parameter according to the configuration file if the identifier is the first identifier, and calling the global variable setting method to set the interface parameter as a global variable;

[0078] A global variable reading module 33 is used to call a global variable acquisition method to read the interface parameters if the identifier is the second identifier, and obtain the reading result of the interface parameters;

[0079] The result output module 34 is used to determine the parameterization result of the test case according to the reading result of the interface parameter.

[0080] The parameterization device for test cases in the automated testing framework of this embodiment is used to implement the parameterization method for test cases in the automated testing framework described above. Therefore, the specific implementation method of the device can be found in the embodiment section of the parameterization method for test cases in the automated testing framework in the previous text, and will not be introduced in detail here.

[0081] In addition, the present application also provides a computer device, such as Figure 4 As shown, including:

[0082] Memory 100: used for storing computer programs;

[0083] Processor 200: configured to execute the computer program to implement the parameterization method of test cases in the automated testing framework as described above.

[0084] Finally, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, it is used to implement the parameterization method of test cases in the automated testing framework as described above.

[0085] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0086] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0087] The above is a detailed introduction to the scheme provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for parameterizing test cases in an automated testing framework, characterized in that: include: Execute test cases through the automated testing framework pytest to traverse the configuration file and determine the interface parameters with identifiers in the configuration file; If the identifier is the first identifier, the reading result of the interface parameter is determined according to the configuration file, and a global variable setting method is called to set the interface parameter as a global variable; the first identifier indicates setting a global variable; If the identifier is the second identifier, a global variable acquisition method is called to read the interface parameter to obtain a reading result of the interface parameter; the second identifier indicates reading a global variable; According to the reading result of the interface parameter, for the interface parameter with the identifier, the identifier in the reading result of the interface parameter is deleted, and the reading result of the interface parameter after deleting the identifier is used as the parameterization result of the test case; If the configuration file includes interface parameters without identifiers, the reading results of the interface parameters after deleting the identifiers together with the reading results of the interface parameters without identifiers are used as the parameterization results of the test case.

2. The method according to claim 1, characterized in that Before executing the test case through the automated testing framework to traverse the configuration file and determine the interface parameters with identifiers in the configuration file, the method further includes: defining identifiers, the identifiers comprising a first identifier and a second identifier; A global variable setting method associated with the first identifier is created, and a global variable obtaining method associated with the second identifier is created.

3. The method according to claim 2, characterized in that After defining the identifier, the identifier includes the first identifier and the second identifier, further comprising: Based on a configuration request, sets an identifier for an interface parameter in a configuration file.

4. The method according to claim 3, characterized in that The interface parameters include field names and field values, and the step of setting identifiers for the interface parameters in the configuration file according to the configuration request includes: According to the configuration request, add identifiers to the field names of the interface parameters in the configuration file.

5. The method according to claim 1, characterized in that After determining the parameterization result of the test case according to the reading result of the interface parameter, the method further includes: The test case is executed according to the parameterized result of the test case through the automated testing framework to realize automated testing.

6. A parameterization device for test cases in an automated testing framework, characterized in that: include: A traversal module is used to execute test cases through the automated testing framework pytest to traverse the configuration file and determine the interface parameters with identifiers in the configuration file; A global variable setting module, for determining the reading result of the interface parameter according to the configuration file, and calling a global variable setting method to set the interface parameter as a global variable if the identifier is a first identifier; the first identifier indicates setting a global variable; A global variable reading module, used for calling a global variable acquisition method to read the interface parameter and obtain a reading result of the interface parameter if the identifier is a second identifier; the second identifier indicates reading a global variable; A result output module, for deleting the identifier in the reading result of the interface parameter for the interface parameter with the identifier according to the reading result of the interface parameter, and using the reading result of the interface parameter after deleting the identifier as the parameterization result of the test case; If the configuration file includes interface parameters without identifiers, the reading results of the interface parameters after deleting the identifiers together with the reading results of the interface parameters without identifiers are used as the parameterization results of the test case.

7. A computer device, characterized in that: include: Memory: used to store computer programs; Processor: used to execute the computer program to implement the parameterization method of test cases in the automated testing framework as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, is used to implement the parameterization method of test cases in an automated testing framework as described in any one of claims 1 to 5.