Automatic test method and system for network communication, electronic equipment and storage medium
By using decorator technology to package and record the test functions in the field of automotive electronic testing, the problems of poor reusability of automation tests and high equipment costs in the existing technology are solved, and efficient and flexible network communication automation testing is achieved, reducing costs and learning and maintenance difficulties.
Patent Information
- Application Number
- CN202411763280.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-21
AI Technical Summary
In the existing automotive electronic testing field, it is difficult to reuse test cases by automated testing of on-board network communications. There are limitations in real-time data display and interactive analysis of HIL test results. The professional HIL test equipment has complex structure and high learning and maintenance costs.
Advanced testing capabilities are implemented by creating decorators in existing bus tools. The decorator encapsulates the test function through embedded functions, records the start information and exception information of the test function, and returns the execution result after the test function is executed, and finally stores this information as the test result and sends it to the front end.
The implementation of advanced testing capabilities is achieved, reducing costs, and enhancing the flexibility and adaptability of the test tools, allowing them to better meet specific testing needs and future expansion.
Smart Images

Figure CN119676104A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network testing, and in particular to an automated testing method, system, electronic device and storage medium for network communication. Background Art
[0002] In the current automotive electronics testing field, the industry generally uses Vector's CANoe software to handle the automated testing of vehicle network communications. CANoe software allows users to build complex test scenarios through its TestModel module.
[0003] There are many bus tools on the market. Bus tools other than CANoe do not have similar code forms to realize automated testing, making it difficult to reuse test cases. There are limitations in the real-time data display and interactive analysis of HIL test results, making it difficult to interactively integrate with CICD. At the same time, professional HIL test equipment has a complex structure and requires professional personnel to debug and train, which has a high learning cost. In addition, it requires regular inspections by third-party professionals, resulting in high maintenance costs in the later stages. Summary of the invention
[0004] To solve the above problems, the present disclosure provides an automated testing method, system, electronic device and storage medium for network communication. The solution utilizes existing bus tools and implements advanced testing functions through decorators, which greatly reduces costs.
[0005] In order to solve the above technical problems, the first aspect of the present invention provides an automated testing method for network communication, the method comprising:
[0006] Creating a decorator that takes the network communication test function as a running parameter, and encapsulating the test function through an embedded function in the decorator;
[0007] Recording the start information of the test function and the exception information during the execution of the test function through the error message function;
[0008] After the test function is executed, the embedded function returns the execution result of the test function;
[0009] The start information, the abnormal information and the execution result are stored as a test result, and when the front end accesses the test result, the test result is sent to the front end.
[0010] According to a preferred embodiment of the present invention, the testing method further comprises:
[0011] The embedded function accesses the test function to obtain the function name of the test function;
[0012] Creating a test instance of the test function based on the function name;
[0013] When the test instance is called to execute the test function, a comment is added to the test instance.
[0014] According to a preferred embodiment of the present invention, the testing method further comprises:
[0015] When receiving the description file of the test instance, the decorator initializes the state information of the test instance;
[0016] When receiving the step description of the test function, the decorator initializes the test function step state and adds a test step state function to the test function;
[0017] The decorator encapsulates the test step status function, and when the test step status function detects that the step statuses of the test function are all correct, the instance status of the test instance that executes the test function is set to be correct.
[0018] According to a preferred embodiment of the present invention, storing the start information, the exception information and the execution result as a test result, and sending the test result to the front end when the front end accesses the test result, comprises:
[0019] Linking to a database, and saving the test results in the database;
[0020] The front-end page and the back-end service are deployed through the B / S architecture, and the back-end service is accessed by the front-end page to obtain the test results in the database.
[0021] In order to solve the above technical problems, the second aspect of the present invention provides an automated testing system for network communication, the testing system comprising:
[0022] A decorator creation module, used to create a decorator that takes the test function of the network communication as a running parameter, and encapsulates the test function through an embedded function in the decorator;
[0023] A test recording module, used to record the start information of the test function and the exception information during the execution of the test function through an error message function;
[0024] An execution result returning module, used to return the execution result of the test function through the embedded function after the execution of the test function is completed;
[0025] The data storage access module is used to store the start information, the abnormal information and the execution result as the test result, and send the test result to the front end when the front end accesses the test result.
[0026] According to a preferred embodiment of the present invention, the testing system further comprises:
[0027] An instance generation module, used to access the test function through the embedded function to obtain the function name of the test function; and create a test instance of the test function based on the function name;
[0028] The annotation and marking module is used to add annotations to the test instance when the test instance is called to execute the test function.
[0029] According to a preferred embodiment of the present invention, the testing system further comprises:
[0030] A test instance status annotation module is used to initialize the status information of the test instance through the decorator when a description file of the test instance is received; initialize the step status of the test function through the decorator when a step description of the test function is received, and add a test step status function to the test function; encapsulate the test step status function through the decorator, and when the test step status function detects that the step status of the test function is correct, set the instance status of the test instance that executes the test function to correct.
[0031] According to a preferred embodiment of the present invention, the data storage access module is specifically used to link to a database and save the test results in the database; the front-end page and back-end service are deployed through the B / S architecture, and the back-end service is accessed on the front-end page to obtain the test results in the database.
[0032] In order to solve the above technical problem, the third aspect of the present invention provides an electronic device, comprising:
[0033] Processor; and
[0034] A memory storing computer executable instructions, wherein when the computer executable instructions are executed, the processor executes the method described in any one of the above embodiments.
[0035] In order to solve the above technical problems, the fourth aspect of the present invention proposes a computer storage medium, wherein the computer storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method described in any one of the above embodiments is implemented.
[0036] Compared with the prior art, the present invention has the following advantages: the present invention creates a decorator with a test function as a parameter, encapsulates the test function through an embedded function in the decorator, saves the start information of the test function and the exception information during the execution process through an error message function, and returns the execution result of the test function through the embedded function after the test function is executed. Finally, the test result including the start information, exception information and execution result is stored, and the test result is sent to the front end. This solution utilizes the existing bus tools and implements advanced test functions through decorators, which greatly reduces costs. By providing customizable script transformation, the flexibility and adaptability of the test tool are enhanced, so that it can better meet specific test requirements and future expansion. Through the improved script function, more sophisticated data collection, storage and analysis can be achieved.
[0037] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or be understood by implementing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in 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 some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 A first flow chart of an automated testing method for network communication according to an embodiment of the present disclosure is shown;
[0040] Figure 2 A schematic diagram of a method for executing a test function through an embedded function in a decorator according to an embodiment of the present disclosure is shown;
[0041] Figure 3 A schematic diagram of a method flow for executing a test instance through a decorator according to an embodiment of the present disclosure is shown;
[0042] Figure 4 A block diagram of an automated testing system for network communication according to an embodiment of the present disclosure is shown;
[0043] Figure 5 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0045] The same reference numerals in the drawings represent the same or similar elements, components or parts, and thus the repeated description of the same or similar elements, components or parts may be omitted below. It should also be understood that although the first, second, third and other attributives representing the numbers may be used herein to describe various devices, elements, components or parts, these devices, elements, components or parts should not be limited by these attributives. In other words, these attributives are only used to distinguish one from another. For example, the first device may also be called the second device, but it does not deviate from the essential technical solution of the present invention. In addition, the terms "and / or" and "and / or" refer to all combinations including any one or more of the listed items.
[0046] See also Figure 1 , Figure 1 This is a flow chart of an automated testing method for network communication provided by the present invention. Figure 1 As shown, the method includes:
[0047] S11. Create a decorator that uses the network communication test function as a running parameter, and encapsulate the test function through the embedded function in the decorator.
[0048] In this embodiment, a decorator is an advanced feature in Python that allows you to dynamically extend or modify the behavior of functions or classes without modifying their definitions. A decorator is essentially a function that receives a function as a parameter and returns a new function or modifies the original function.
[0049] In this embodiment, the decorator: testcase decorator, aims to automatically create a test case instance when the function is executed and record related test execution information.
[0050] In this embodiment, the decorator is applied using the @ syntax. In this solution, the testcase decorator returns the wrapper embedded function, so that any function marked with @testcase will be automatically executed through the wrapper embedded function, thereby realizing the function of automatically recording test cases.
[0051] In this embodiment, this step defines a decorator: the testcase decorator is a decorator that accepts a func test function as a parameter. This decorator further defines an embedded function named wrapper to encapsulate the execution of the func test function.
[0052] S12. Record the start information of the test function and the exception information during the execution of the test function through the error message function.
[0053] In this embodiment, the error message function includes: writeErrorInfo function. In software development, writeErrorInfo function is a custom function or method used to record error information. This function or method usually receives one or more parameters, which contain information related to the error, such as error code, error message, stack trace, etc. Then, it formats and writes this information to a specified log file, or records it through other means (such as console output, network sending, etc.).
[0054] In the logging system, the writeErrorInfo function is a method used to record error-level logs. The logging system usually divides logs into different levels, such as debug (DEBUG), information (INFO), warning (WARNING), error (ERROR) and critical error (CRITICAL). The writeErrorInfo method may be specifically used to record error-level logs so that developers can quickly locate and solve problems.
[0055] In this embodiment, when the test function starts, the error message function is called to output a specific message to indicate the start of a specific test case, thereby obtaining the start information of the test function.
[0056] S13. After the test function is executed, the embedded function returns the execution result of the test function.
[0057] In this embodiment, the wrapper embedded function returns the execution result of the func test function, regardless of whether the test succeeds or fails. If an exception occurs, result will be set to None, that is, the execution result is empty.
[0058] S14. The start information, the abnormal information and the execution result are stored as the test result, and when the front end accesses the test result, the test result is sent to the front end.
[0059] In this embodiment, the corresponding test results are saved in the database by linking to the database. For example, the test results can be connected to a JSON database, an XML database, or a manggoDB database, and the test results are converted into data in a corresponding format according to the data storage format in different databases, and then stored in the corresponding database.
[0060] In this embodiment, the front-end page and back-end service can be deployed through the B / S architecture. For example, the front-end and back-end services can be deployed in the Vue+NodeJS mode, and the back-end service can be accessed on the front-end page to obtain the test results in the database. Vuejs and Nodejs are two commonly used technologies in modern Web development. They each have unique functions and advantages, and are often used in combination to build efficient and scalable full-stack Web applications.
[0061] In this embodiment, the test results can be directly accessed on the front end, and the user can obtain the test results in real time. Further, the test results can be displayed on the front end page, thereby optimizing the visualization and interactivity of the test results and improving the test efficiency.
[0062] The present invention creates a decorator with a test function as a parameter, encapsulates the test function through an embedded function in the decorator, saves the start information of the test function and the exception information during the execution process through an error message function, and returns the execution result of the test function through an embedded function after the test function is executed. Finally, the test result including the start information, exception information and execution result is stored, and the test result is sent to the front end. This solution utilizes existing bus tools and implements advanced test functions through decorators, which greatly reduces costs. By providing customizable script transformation, the flexibility and adaptability of the test tool are enhanced, so that it can better meet specific test requirements and future expansion. Through the improved script function, more sophisticated data collection, storage and analysis can be achieved.
[0063] Specifically, Figure 2 As shown, executing the test function through the embedded function in the decorator includes the following steps:
[0064] S21. The embedded function accesses the test function to obtain the function name of the test function.
[0065] S22. Create a test instance of the test function based on the function name.
[0066] In this embodiment, inside the wrapper embedded function, an instance of the TestCase test class is first created. The name of this instance is obtained by accessing func.name, that is, the name of the decorated test function.
[0067] S23. When the test instance is called to execute the test function, add a comment to the test instance.
[0068] In this embodiment, the current instance will be automatically located as the use case during instantiation, and comments will be directly added to the use case when testCaseComment is called.
[0069] Further to this scheme, Figure 3 As shown, through the decorator, executing the test instance includes the following steps:
[0070] S31. When receiving the description file of the test instance, the decorator initializes the status information of the test instance.
[0071] In this embodiment, a test case description is received, and the use case state is initialized, and current_test_case=self._name_ is located as the current test case.
[0072] S32. When receiving the step description of the test function, the decorator initializes the test function step state and adds a test step state function to the test function.
[0073] In this embodiment, the step description of the test function is accepted, and the test step status is initialized, and the test step functions teststepPass and testStepFail are added to monitor each step of the test function.
[0074] S33. The decorator encapsulates the test step status function, and when the test step status function detects that the step statuses of the test function are all correct, the instance status of the test instance that executes the test function is set to be correct.
[0075] In this embodiment, the test step status is encapsulated, and when all steps are correct, the test instance status is True; various prompt information is encapsulated.
[0076] See also Figure 4 , Figure 4 The second aspect of the present invention proposes an automated testing system for network communication, the testing system comprising: a decorator creation module 11, a test recording module 12, an execution result return module 13 and a data storage access module 14.
[0077] In this embodiment, the decorator creation module 11 is used to create a decorator that takes the test function of network communication as a running parameter, and encapsulates the test function through the embedded function in the decorator.
[0078] In this embodiment, the test recording module 12 is used to record the start information of the test function and the abnormal information during the execution of the test function through the error message function.
[0079] In this embodiment, the execution result returning module 13 is used to return the execution result of the test function through the embedded function after the test function is executed.
[0080] In this embodiment, the data storage access module 14 is used to store the start information, the abnormal information and the execution result as the test result, and send the test result to the front end when the front end accesses the test result.
[0081] In this embodiment, the instance generation module is used to access the test function through the embedded function to obtain the function name of the test function; and create a test instance of the test function based on the function name.
[0082] In this embodiment, the annotation module is used to add annotations to the test instance when the test instance is called to execute the test function.
[0083] In this embodiment, the test instance status labeling module is used to initialize the status information of the test instance through a decorator when a description file of the test instance is received; initialize the step status of the test function through the decorator when a step description of the test function is received, and add a test step status function to the test function; encapsulate the test step status function through the decorator, and when the test step status function detects that the step status of the test function is correct, the instance status of the test instance that executes the test function is set to correct.
[0084] In this embodiment, the data storage access module 14 is specifically used to link to the database and save the test results in the database; the front-end page and back-end service are deployed through the B / S architecture, and the back-end service is accessed on the front-end page to obtain the test results in the database.
[0085] like Figure 5 As shown, an embodiment of the present invention provides an electronic device, including a processor 1110, a communication interface 1120, a memory 1130 and a communication bus 1140, wherein the processor 1110, the communication interface 1120, and the memory 1130 communicate with each other through the communication bus 1140;
[0086] Memory 1130, used for storing computer programs;
[0087] The processor 1110 is used to implement any of the above-mentioned testing methods when executing the program stored in the memory 1130.
[0088] In the electronic device provided by the embodiment of the present invention, the processor 1110 creates a decorator that uses a test function of network communication as a running parameter by executing a program stored in the memory 1130, and encapsulates the test function through an embedded function in the decorator; records the start information of the test function and the exception information during the execution of the test function through an error message function; after the test function is executed, the embedded function returns the execution result of the test function; the start information, exception information and execution result are stored as test results, and when the front end accesses the test result, the test result is sent to the front end.
[0089] The communication bus 1140 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 1140 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0090] The communication interface 1120 is used for communication between the above electronic device and other devices.
[0091] The memory 1130 may include a random access memory 1130 (RAM), or may include a non-volatile memory 1130 (non-volatile memory), such as at least one disk memory 1130. Optionally, the memory 1130 may also be at least one storage device located away from the processor 1110.
[0092] The above-mentioned processor 1110 can be a general-purpose processor 1110, including a central processing unit 1110 (CPU), a network processor 1110 (NP), etc.; it can also be a digital signal processor 1110 (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0093] An embodiment of the present invention provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors 1110 to implement the testing method of any of the above embodiments.
[0094] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk SolidStateDisk (SSD)), etc.
[0095] Although the present disclosure 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 make equivalent replacements for some of the technical features therein; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. An automated testing method for network communication, characterized in that: The method comprises: Creating a decorator that takes the network communication test function as a running parameter, and encapsulating the test function through an embedded function in the decorator; Recording the start information of the test function and the exception information during the execution of the test function through the error message function; After the test function is executed, the embedded function returns the execution result of the test function; The start information, the abnormal information and the execution result are stored as a test result, and when the front end accesses the test result, the test result is sent to the front end.
2. The automated testing method according to claim 1, characterized in that: The test method also includes: The embedded function accesses the test function to obtain the function name of the test function; Creating a test instance of the test function based on the function name; When the test instance is called to execute the test function, a comment is added to the test instance.
3. The automated testing method according to claim 2, characterized in that: The test method also includes: When receiving the description file of the test instance, the decorator initializes the state information of the test instance; When receiving the step description of the test function, the decorator initializes the test function step state and adds a test step state function to the test function; The decorator encapsulates the test step status function, and when the test step status function detects that the step statuses of the test function are all correct, the instance status of the test instance that executes the test function is set to be correct.
4. The automated testing method according to any one of claims 1 to 3, characterized in that: The storing the start information, the abnormal information and the execution result as a test result, and sending the test result to the front end when the front end accesses the test result, comprises: Linking to a database, and saving the test results in the database; The front-end page and the back-end service are deployed through the B / S architecture, and the back-end service is accessed by the front-end page to obtain the test results in the database.
5. An automated testing system for network communications, characterized in that: The test system comprises: A decorator creation module, used to create a decorator that takes the test function of the network communication as a running parameter, and encapsulates the test function through an embedded function in the decorator; A test recording module, used to record the start information of the test function and the exception information during the execution of the test function through an error message function; An execution result returning module, used to return the execution result of the test function through the embedded function after the execution of the test function is completed; The data storage access module is used to store the start information, the abnormal information and the execution result as the test result, and send the test result to the front end when the front end accesses the test result.
6. The test system according to claim 5, characterized in that: The test system further comprises: An instance generation module, used to access the test function through the embedded function to obtain the function name of the test function; and create a test instance of the test function based on the function name; The annotation and marking module is used to add annotations to the test instance when the test instance is called to execute the test function.
7. The test system according to claim 6, characterized in that: The test system further comprises: A test instance status annotation module is used to initialize the status information of the test instance through the decorator when a description file of the test instance is received; initialize the step status of the test function through the decorator when a step description of the test function is received, and add a test step status function to the test function; encapsulate the test step status function through the decorator, and when the test step status function detects that the step status of the test function is correct, set the instance status of the test instance that executes the test function to correct.
8. The test system according to any one of claims 5 to 7, characterized in that: The data storage access module is specifically used to link to a database and save the test results in the database; deploy the front-end page and back-end service through the B / S architecture, and access the back-end service on the front-end page to obtain the test results in the database.
9. An electronic device, characterized in that: include: processor; as well as A memory storing computer executable instructions which, when executed, cause the processor to perform the method according to any one of claims 1-4.
10. A computer storage medium, characterized in that: in, The computer storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Automatic interface testing method based on pytest
CN117234944A
Automatic testing method with compatibility
CN119003343A