Automatic testing method with compatibility

Through unified naming and decorator mechanisms and combined with coverage detection, the existing automation testing tools have been solved in terms of flexibility and ease of use, the compatibility and scalability of automated testing are achieved, and the requirements of automation testing are adapted to diversified testing and improved Development efficiency and code reusability.

CN119003343APending Publication Date: 2024-11-22TIANJIN HUALAI TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411036701.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Existing automated testing tools have shortcomings in flexibility, scalability and ease of use. Terminal-based tools are flexible but poorly scalable, while tools called through third-party programs are highly ease of use but have a high threshold for use, which is difficult to Meet the diverse and rapid iterative testing needs.

Method used

A compatible automated testing method is proposed. By uniformly naming automation tool classes and functions, using decorators to determine whether terminal interaction is performed, and testing cases are adjusted through coverage detection to achieve flexibility and scalability of automated testing.

Benefits of technology

It supports users to select test projects and operating environments through terminal input, adapt to multiple usage scenarios, simplify the development process, improve development speed and code reusability, and reduce the complexity of multi-person development.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003343A_ABST
    Figure CN119003343A_ABST
Patent Text Reader

Abstract

The invention provides an automatic testing method with compatibility. The automatic testing method comprises the following steps of uniformly naming files in which all automatic tool classes are located; naming the automatic tool class according to a tool class naming rule and a current project name; setting a function naming rule, and naming an automatic test item function name according to the function naming rule; the decorator is used on each automatic test item function, and whether terminal interaction is executed or not is judged according to the value of the input parameter, so that the automatic test is executed. The method has the beneficial effects that developers directly create files, naming classes and functions according to rules, do not need to additionally create project configuration files, and only need to normally write implementation codes of a set of automatic tools, multi-person synchronous modular development is facilitated through clear naming rules and clear hierarchical splitting of code files, and the development efficiency is improved. And the development speed is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of automated detection, and in particular relates to an automated testing method with compatibility. Background Art

[0002] With the continuous increase in the number of products and projects and the accumulation of existing maintenance and testing tasks, automated testing tools have become an important means to ensure the quality of App, firmware and cloud service development and maintenance. With the gradual increase in the complexity of software systems and the continuous improvement of software testing quality requirements, automated testing tools need to have stronger compatibility and scalability to support diverse and rapidly iterative testing requirements and dynamically changing test scenarios.

[0003] The automated testing tools currently in use are mainly divided into two categories: interactive testing tools that run based on Windows terminals and test code blocks that are called through third-party programs.

[0004] Terminal-based testing tools: These tools are highly flexible and interactive, allowing users to manually execute steps and view test results in real time. However, these tools often have many restrictions, requiring users to interact step by step during the testing process, making it difficult to expand functions, and are mainly suitable for single test scenarios and difficult to maintain.

[0005] Test code blocks called by third-party programs: Such tools have advantages in ease of use, are easy to call in different test scenarios, and can be used by developers in other departments within the company. However, the threshold for using such tools is high, and usually only software developers can operate them. Ordinary testers lack the ability to use and modify them.

[0006] In summary, existing automated testing tools have their own advantages and disadvantages in terms of flexibility, scalability and ease of use. Terminal-based testing tools excel in flexibility and interactivity, but are deficient in scalability and maintenance; while test code blocks called by third-party programs have advantages in ease of use and cross-departmental calls, but require a high level of technical skills from the user. Summary of the invention

[0007] In view of this, the present invention aims to propose a compatible automated testing method in order to solve at least one of the above-mentioned technical problems.

[0008] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0009] In a first aspect, the present invention provides an automated testing method with compatibility, comprising the following steps:

[0010] Unify the names of all files containing automation tools;

[0011] Name the automation tool class according to the tool class naming rules and the current project name;

[0012] Set the function naming rules and name the automated test item functions according to the function naming rules;

[0013] Automated testing is performed by using a decorator on each automated test item function and determining whether to perform terminal interaction based on the value of the input parameter.

[0014] Furthermore, the tool class naming rules are as follows:

[0015] The project name of the project where the current automation tool class is located is obtained, and the project name is used as the prefix of the name of the current automation tool class, wherein the name of the automation tool class except the prefix is ​​a fixed name.

[0016] Furthermore, the function naming rules are as follows:

[0017] The name of the automated test item function is set to "test item_test", wherein when the fixed name is when the automatic test item requires terminal interaction, a function named "input_test item_test" is implemented therein.

[0018] Furthermore, the process of performing the automated test by using a decorator on each automated test item function and determining whether to perform terminal interaction according to the value of the input parameter includes:

[0019] Add the decorator to each automatic test item function and create a decorator function corresponding to the decorator;

[0020] The decorator function receives the decorated main function as a parameter, and defines a nested function inside the decorator function as a new main function;

[0021] The decorator function identifies whether the name of the current body function contains the target field;

[0022] If included, wait until the input processing function is executed, then call the original main function and pass in the same parameters as the original function;

[0023] Otherwise, call the original main function directly and pass in all parameters.

[0024] Furthermore, during the process of executing the automatic test, the coverage of the automated test is detected by a coverage detection method, and the process includes:

[0025] Create and configure the coverage tool in the file where the automation tool class is located, and install the coverage tool on the CI / CD server;

[0026] Run the test case in the CI / CD server. The coverage tool continuously collects execution data during the test case execution and generates a corresponding execution file after the test case execution is completed.

[0027] The code area not covered by the test case is obtained according to the execution file analysis, and the reason for not being covered is analyzed, and the test case is adjusted according to the reason.

[0028] Furthermore, the process of analyzing and obtaining code areas not covered by the test cases includes:

[0029] Obtaining coverage indicators in the execution file, wherein the coverage indicators include line coverage, branch coverage, and function coverage;

[0030] It is determined whether the uncovered code is deprecated code or test code, and the code is marked if the determination result is yes.

[0031] Furthermore, the process of analyzing the reasons for non-coverage includes:

[0032] Check whether the current code is not covered due to insufficient number of test cases;

[0033] Analyze whether the input data of the test case covers all possible scenarios and boundary conditions;

[0034] Evaluate whether the code is difficult to test due to highly nested conditionals and large number of branches;

[0035] Check whether the code path cannot be executed due to external dependencies or environment restrictions.

[0036] Furthermore, the process of adjusting the test case according to the cause includes:

[0037] Design new test cases for uncovered code areas, and adjust and extend existing test cases to increase code coverage;

[0038] After implementing improvement actions, regenerate the coverage report and review the new report to confirm whether the uncovered code areas have been improved.

[0039] In a second aspect, the present invention provides a server, characterized in that it includes at least one processor and a memory communicatively connected to the processor, the memory storing instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes a compatible automated testing method as described in the first aspect.

[0040] In a third aspect, the present invention provides a computer-readable storage medium storing a computer program, characterized in that when the computer program is executed by a processor, the computer program implements the automated testing method with compatibility described in the first aspect.

[0041] Compared with the prior art, the automated testing method with compatibility described in the present invention has the following beneficial effects:

[0042] It supports users to select different test projects and operating environments through terminal input, adapts to various usage scenarios, and categorizes various projects, products, and automation tools through naming rules and other designs. Developers can directly create files and name classes and functions based on the rules without having to create project configuration files separately.

[0043] The whole system is compatible with two different calling schemes, and developers only need to write a normal set of implementation codes for the automation tools. With clear naming rules and clearer code file hierarchy, it is convenient for multiple people to develop synchronous modules, greatly improving the development speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings constituting a part of the present invention are used to provide a further understanding 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 accompanying drawings:

[0045] Figure 1 A schematic diagram of the workflow of an automated testing method with compatibility described in an embodiment of the present invention. DETAILED DESCRIPTION

[0046] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0047] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0048] An automated compatibility testing method comprises the following steps:

[0049] S1. Unify the names of all files containing automation tools;

[0050] S2. Naming the automation tool class according to the tool class naming rules and the current project name;

[0051] S3. Set the function naming rules and name the automated test item function according to the function naming rules;

[0052] S4. Automated testing is performed by using a decorator on each automated test item function and determining whether to perform terminal interaction based on the value of the input parameter.

[0053] The tool class naming rules are as follows:

[0054] The project name of the project where the current automation tool class is located is obtained, and the project name is used as the prefix of the name of the current automation tool class, wherein the name of the automation tool class except the prefix is ​​a fixed name.

[0055] The function naming rules are as follows:

[0056] The name of the automated test item function is set to "test item_test", wherein when the fixed name is when the automatic test item requires terminal interaction, a function named "input_test item_test" is implemented therein.

[0057] The process of performing automated testing by using a decorator on each automated test item function and determining whether to perform terminal interaction according to the value of an input parameter includes:

[0058] Add the decorator to each automatic test item function and create a decorator function corresponding to the decorator;

[0059] The decorator function receives the decorated main function as a parameter, and defines a nested function inside the decorator function as a new main function;

[0060] The decorator function identifies whether the name of the current body function contains the target field;

[0061] If included, wait until the input processing function is executed, then call the original main function and pass in the same parameters as the original function;

[0062] Otherwise, call the original main function directly and pass in all parameters.

[0063] During the execution of the automatic test, the coverage of the automated test is detected by the coverage detection method, and the process includes:

[0064] Create and configure the coverage tool in the file where the automation tool class is located, and install the coverage tool on the CI / CD server;

[0065] Run the test case in the CI / CD server. The coverage tool continuously collects execution data during the test case execution and generates a corresponding execution file after the test case execution is completed.

[0066] The code area not covered by the test case is obtained according to the execution file analysis, and the reason for not being covered is analyzed, and the test case is adjusted according to the reason.

[0067] The process of analyzing and obtaining code areas not covered by the test cases includes:

[0068] Obtaining coverage indicators in the execution file, wherein the coverage indicators include line coverage, branch coverage, and function coverage;

[0069] It is determined whether the uncovered code is deprecated code or test code, and the code is marked if the determination result is yes.

[0070] The process of analyzing the reasons for non-coverage includes:

[0071] Check whether the current code is not covered due to insufficient number of test cases;

[0072] Analyze whether the input data of the test case covers all possible scenarios and boundary conditions;

[0073] Evaluate whether the code is difficult to test due to highly nested conditionals and large number of branches;

[0074] Check whether the code path cannot be executed due to external dependencies or environment restrictions.

[0075] The process of adjusting the test case according to the cause includes:

[0076] Design new test cases for uncovered code areas, and adjust and extend existing test cases to increase code coverage;

[0077] After implementing improvement actions, regenerate the coverage report and review the new report to confirm whether the uncovered code areas have been improved.

[0078] Preferably, a specific execution process of the automated testing method with compatibility includes:

[0079] All automation tool code files must be named "auto_special_test_*.py" to ensure a unified naming convention.

[0080] In order to achieve compatible extension of different project tools, each automation tool class is written based on the project dimension. The class naming format is "ProjectSpecialTest", where "Project" represents the project name and can be modified according to the actual project.

[0081] The function name of the automated test item is specified as "item_test_*". If a test item requires interaction when the terminal is running, a function named "input_item_test_" must also be implemented in the test class.

[0082] Decorate each automated test function with the decorator @check_is_input

[0083] For example, if you need to write an automated test for upgrading a product for project A, the steps are as follows: create a file named "auto_special_test.py", create a class named "ASpecialTest" in the file, create "item_test_upgrade" and "input_item_test_upgrade" functions under the class, and finally add the decorator @check_is_input to the "item_test_upgrade" function.

[0084] Terminal operation startup part: Create main.py and implement the startup code in this file. Create read_project_name_list and read_project_name_list functions to read and display the list of special test projects and the automated test items under each project.

[0085] Through the reflection mechanism (inspect module, ast module, etc.), various projects and test items are displayed in the terminal according to the above naming rules. Create a run function to run the automated test items selected by the user, and pass in the only parameter is_input=True when running the specified automated test items through getattr.

[0086] Automation function compatibility implementation part: Create the check_is_input function, which is a decorator function used to identify whether the value of the is_input field in the main function call parameter is True. If it is True, the "input_original function name" function is called first, and the original main function is called after the function is executed. If it is False, the main function is called directly.

[0087] In summary, writing automated testing tools based on the architecture achieves compatibility with terminal running tools and third-party calling requirements, which ensures that ordinary testers can interact through the terminal and retains the same set of codes to support other third-party programs to directly call the code level without the need for separate writing.

[0088] Embodiment 2:

[0089] A server includes at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes a compatible automated testing method as described in Example 1.

[0090] Embodiment three:

[0091] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements an automated testing method with compatibility described in Embodiment 1.

[0092] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0093] In the several embodiments provided in the present application, it should be understood that the disclosed methods and systems can be implemented in other ways. For example, the division of the units described above is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The above-mentioned units 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 units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.

[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.

[0095] 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 principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A compatibility automated testing method, characterized in that: The steps include: Unify the names of all files containing automation tools; Name the automation tool class according to the tool class naming rules and the current project name; Set the function naming rules and name the automated test item functions according to the function naming rules; Automated testing is performed by using a decorator on each automated test item function and determining whether to perform terminal interaction based on the value of the input parameter.

2. The method for automated compatibility testing according to claim 1, characterized in that: The tool class naming rules are as follows: The project name of the project where the current automation tool class is located is obtained, and the project name is used as the prefix of the name of the current automation tool class, wherein the name of the automation tool class except the prefix is ​​a fixed name.

3. The automated testing method with compatibility according to claim 1, characterized in that: The function naming rules are as follows: The name of the automated test item function is set to "test item_test", wherein when the fixed name is when the automatic test item requires terminal interaction, a function named "input_test item_test" is implemented inside it.

4. The method for automated compatibility testing according to claim 1, characterized in that: The process of performing automated testing by using a decorator on each automated test item function and determining whether to perform terminal interaction according to the value of an input parameter includes: Add the decorator to each automatic test item function and create a decorator function corresponding to the decorator; The decorator function receives the decorated main function as a parameter, and defines a nested function inside the decorator function as a new main function; The decorator function identifies whether the name of the current body function contains the target field; If included, wait until the input processing function is executed, then call the original main function and pass in the same parameters as the original function; Otherwise, call the original main function directly and pass in all parameters.

5. The automated testing method with compatibility according to claim 1, characterized in that: During the execution of the automatic test, the coverage of the automated test is detected by the coverage detection method, and the process includes: Create and configure the coverage tool in the file where the automation tool class is located, and install the coverage tool on the CI / CD server; Run the test case in the CI / CD server. The coverage tool continuously collects execution data during the test case execution and generates a corresponding execution file after the test case execution is completed. The code area not covered by the test case is obtained according to the execution file analysis, and the reason for not being covered is analyzed, and the test case is adjusted according to the reason.

6. The method for automated testing of compatibility according to claim 5, characterized in that: The process of analyzing and obtaining code areas not covered by the test cases includes: Obtaining coverage indicators in the execution file, wherein the coverage indicators include line coverage, branch coverage, and function coverage; It is determined whether the uncovered code is deprecated code or test code, and the code is marked if the determination result is yes.

7. The automated testing method with compatibility according to claim 5, characterized in that: The process of analyzing the reasons for non-coverage includes: Check whether the current code is not covered due to insufficient number of test cases; Analyze whether the input data of the test case covers all possible scenarios and boundary conditions; Evaluate whether the code is difficult to test due to highly nested conditionals and large number of branches; Check whether the code path cannot be executed due to external dependencies or environment restrictions.

8. The method for automated testing of compatibility according to claim 5, characterized in that: The process of adjusting the test case according to the cause includes: Design new test cases for uncovered code areas, and adjust and extend existing test cases to increase code coverage; After implementing improvement actions, regenerate the coverage report and review the new report to confirm whether the uncovered code areas have been improved.

9. A server, characterized in that: It includes at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes a compatible automated testing method as described in any one of claims 1-8.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, an automated testing method with compatibility as described in any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Automatic test method and system for network communication, electronic equipment and storage medium

    CN119676104A