Automated testing method, device, computer equipment and storage medium
By using container cloud platform and Docker imaging technology in automated testing, and generating and executing test scripts, the test environment loss caused by automated test server exceptions is solved, and the reusability of the test environment and the efficiency of automated tests is improved.
Patent Information
- Application Number
- CN202010327124.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-23
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2040-04-23
AI Technical Summary
During the automated test process, when an abnormality occurs in the automated test server and the system needs to be reinstalled, the configuration data of the previously deployed test operation environment will be lost, resulting in the inability to perform automatic testing normally in the subsequent process. The reusability of the test operation environment is not high, and the maintenance cost is relatively high. High, and inefficient in automated testing.
By obtaining the address information of the code management warehouse, using the code management tool of the container cloud platform to obtain the specified code, generate automated test scripts, pull and deploy Docker images, generate pods and execute test scripts in it, and realize the rapid deployment and recovery of the test environment. .
It improves the mobility and reusability of the test environment of automated testing, avoids the problem of loss of the test running environment in traditional methods, reduces maintenance costs, and improves the efficiency and stability of automated testing.
Smart Images

Figure CN111679965B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to an automated testing method, apparatus, computer equipment and storage medium. Background Art
[0002] Automated testing has become increasingly important in the testing phase. Automated testing can cover some test cases, thereby reducing the version delivery pressure on testers. The existing automated testing process usually requires the deployment of a test running environment on an automated testing server, such as a code running environment, dependent libraries, and various software to run automated testing scripts. However, after the test running environment of the automated testing script is successfully deployed on the automated testing server, if an exception occurs on the automated testing server and the system needs to be reinstalled, all the previously deployed configuration data will be lost, resulting in the inability to perform automated testing normally in the future. If the above test running environment needs to be restored, the deployment process of the above test running environment needs to be re-executed. The reusability of the test running environment is not high, and the test efficiency of automated testing is low. Moreover, it is currently difficult, time-consuming, and labor-intensive for testers to quickly restore the test running environment, and the maintenance cost of the test running environment is high. Summary of the invention
[0003] The main purpose of this application is to provide an automated testing method, apparatus, computer equipment and storage medium, aiming to solve the existing technical problems that when an automated testing server encounters an exception during the automated testing process and the system needs to be reinstalled, the deployment process of the test running environment needs to be re-executed, which leads to low reusability of the test running environment, high maintenance cost of the test running environment, and low testing efficiency of the automated test.
[0004] The present application proposes an automated testing method, the method comprising the steps of:
[0005] When receiving an automated test request, obtaining first address information of the code management repository;
[0006] According to the first address information, obtaining the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0007] According to the specified code, generate an automated test script corresponding to the specified code;
[0008] Pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform;
[0009] Copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0010] The automated test script is executed in the pod.
[0011] Optionally, before the step of acquiring the specified code corresponding to the automated test request from the code management repository through a code management tool preset in the container cloud platform according to the first address information, the step includes:
[0012] receiving input test code corresponding to the automated test;
[0013] Filtering method names from the test code, wherein the number of the method names includes one or more;
[0014] Extract the method data corresponding to the method name from the pre-created pytest decorator;
[0015] Using the method data to update the test code, to obtain the specified code;
[0016] The specified code is sent to the Gitlab server so that the specified code is stored in the code management warehouse through the Gitlab server.
[0017] Optionally, before the step of extracting the method data corresponding to the method name from the pre-created pytest decorator, the step includes:
[0018] Get the public methods corresponding to the automated tests;
[0019] Encapsulate the public method into a pytest decorator;
[0020] Store the pytest decorator in the pre-created first specified file.
[0021] Optionally, the step of generating an automated test script corresponding to the specified code according to the specified code includes:
[0022] Performing a compile operation on the specified code;
[0023] Obtaining a compilation result generated after the specified code executes the compilation operation;
[0024] Acquire a script template corresponding to the automated test request from a preset script database;
[0025] The automated test script is generated according to the compilation result and the script template.
[0026] Optionally, before the step of pulling a preset Docker image from an image repository and deploying the Docker image in the container cloud platform, the following steps are included:
[0027] Obtain a dependency library of a Python program, and package the Python dependency library into a second specified file corresponding to a specified file type;
[0028] Get the input Dockerfile file;
[0029] Placing the second designated file and the Dockerfile file in the same pre-created designated directory;
[0030] Obtain a basic image, wherein the basic image includes a running environment of a Python program;
[0031] By using the Docker build command, the dependent libraries of the Python program in the specified directory are packaged into the base image to obtain a corresponding Docker image;
[0032] Send the Docker image to the image warehouse for storage through the Docker push command;
[0033] The step of pulling the preset Docker image from the image repository includes:
[0034] Obtaining second address information of the image repository;
[0035] Pull the Docker image from the image repository according to the second address information.
[0036] Optionally, before the step of obtaining the first address information of the code management repository when receiving the automated test request, the step includes:
[0037] Monitoring the cloud container platform within a preset time period to obtain status information corresponding to the cloud container platform;
[0038] According to the status information, determining whether an abnormality occurs in the container status of the cloud container platform;
[0039] If it is determined that there is no abnormality in the container state of the cloud container platform, an acquisition instruction for acquiring the first address information of the code management warehouse is generated.
[0040] Optionally, after the step of executing the automated test script in the pod, the following steps are included:
[0041] Obtaining the running result of the automated test script;
[0042] Compare the actual output corresponding to the operation result with the expected output to obtain a comparison result;
[0043] Generate a test report for the automated test script according to the running result and the comparison result;
[0044] The test report is displayed.
[0045] The present application also provides an automated testing device, comprising:
[0046] A first acquisition module, configured to acquire first address information of a code management repository when receiving an automated test request;
[0047] A second acquisition module is used to acquire, according to the first address information, the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0048] A first generating module, configured to generate an automated test script corresponding to the specified code according to the specified code;
[0049] A deployment module, used to pull a preset Docker image from an image repository and deploy the Docker image in the container cloud platform;
[0050] A second generation module is used to copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0051] An execution module is used to execute the automated test script in the pod.
[0052] The present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0053] The present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0054] The automated testing method, apparatus, computer device, and storage medium provided in this application have the following beneficial effects:
[0055] The automated testing method, device, computer equipment and storage medium provided in the present application, when receiving an automated testing request, obtain the first address information of the code management warehouse; according to the first address information, obtain the specified code corresponding to the automated testing request from the code management warehouse through the code management tool in the preset container cloud platform; according to the specified code, generate an automated testing script corresponding to the specified code; pull the preset Docker image from the image warehouse, and deploy the Docker image in the container cloud platform; copy the automated testing script to the Docker image in the container cloud platform to generate the corresponding pod; execute the automated testing script in the pod. The present application increases the portability of the test environment of automated testing by using container technology and image technology to generate pods for automated testing. When an exception occurs in the pod, a new pod can be quickly generated to redeploy the test running environment for executing automated testing, and the test running environment will not be lost, which ensures the reusability and maintainability of the test running environment of the automated test, effectively avoiding the need for the traditional automated testing method to redeploy the test running environment when an exception occurs in the test running environment deployed on the automated testing server, thereby improving the test efficiency and test stability of automated testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 It is a flowchart of an automated testing method according to an embodiment of the present application;
[0057] Figure 2 is a structural schematic diagram of an automated testing device according to an embodiment of the present application;
[0058] Figure 3 It is a schematic diagram of the structure of a computer device according to an embodiment of the present application.
[0059] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0060] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0061] It should be noted that all directional indications in the embodiments of the present application (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly. The connection can be a direct connection or an indirect connection.
[0062] Reference Figure 1, an automated testing method according to an embodiment of the present application includes:
[0063] S1: When receiving an automated test request, obtain the first address information of the code management repository;
[0064] S2: According to the first address information, obtaining the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0065] S3: generating an automated test script corresponding to the specified code according to the specified code;
[0066] S4: Pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform;
[0067] S5: copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0068] S6: Execute the automated test script in the pod.
[0069] As described above in steps S1 to S6, the execution subject of the embodiment of the method is an automated testing device. In practical applications, the automated testing device can be implemented by a virtual device, such as a software code, or by a physical device with relevant execution code written or integrated, and can interact with the user through a keyboard, mouse, remote control, touchpad or voice control device. The automated testing device provided in this embodiment can quickly and conveniently deploy the corresponding test running environment in the container cloud platform by generating a pod when an abnormality occurs in the test running environment of the automated testing server to ensure the normal operation of the automated test. Specifically, when an automated testing request is received, the first address information of the code management warehouse is first obtained. Then, according to the first address information, the specified code corresponding to the automated testing request is obtained from the code management warehouse through the code management tool in the preset container cloud platform. Among them, before receiving the automated testing request, the container cloud platform will be pre-created. The container cloud platform includes a code management tool and an image warehouse, and the container cloud platform can be automatically created by relying on container technology and cluster scheduling editing management technology through a preset container creation script. After obtaining the above-mentioned specified code, an automated test script corresponding to the above-mentioned specified code is generated according to the above-mentioned specified code. Among them, the above-mentioned automated test script can be generated according to the compilation result generated after the compilation operation of the above-mentioned specified code, and the script template corresponding to the automated test request. After obtaining the above-mentioned automated test script, a preset Docker image is obtained from the image warehouse, and the Docker image is deployed in the above-mentioned container cloud platform. After the Docker image is deployed, the above-mentioned automated test script is copied to the Docker image in the above-mentioned container cloud platform to generate a corresponding pod. Among them, the above-mentioned pod can be regarded as a test running environment required for automated testing by running the automated test script. Finally, after the above-mentioned pod is generated, the above-mentioned automated test script is executed in the above-mentioned pod to realize the test process of automated testing. Among them, if an exception occurs during the execution of the above-mentioned automated test script in the above-mentioned pod, the above-mentioned automated test process can be re-executed to quickly generate a new pod, and then the above-mentioned automated test script is executed by the new pod. In addition, when a new automated test request is received, the above steps are repeated. This embodiment uses container technology and image technology to generate a pod for automated testing, which increases the portability of the test environment of automated testing.When an exception occurs in a pod, a new pod can be quickly generated to redeploy the test running environment for executing automated tests, and the test running environment will not be lost, ensuring the reusability and maintainability of the test running environment for automated testing. This effectively avoids the need for traditional automated testing methods to redeploy the test running environment when an exception occurs in the test running environment deployed on the automated testing server, thereby improving the test efficiency and stability of automated testing.
[0070] Furthermore, in an embodiment of the present application, before the above step S2, the following steps are included:
[0071] S200: receiving an input test code corresponding to an automated test;
[0072] S201: Filtering method names from the test code, wherein the number of the method names includes one or more;
[0073] S202: extracting method data corresponding to the method name from the pre-created pytest decorator;
[0074] S203: Using the method data to update the test code to obtain the specified code;
[0075] S204: Send the specified code to the Gitlab server, so that the specified code is stored in the code management warehouse through the Gitlab server.
[0076] As described in steps S200 to S204 above, before the step of obtaining the specified code corresponding to the automated test request from the code management warehouse through the code management tool preset in the container cloud platform according to the first address information, the process of generating the specified code is also included. Specifically, the test code corresponding to the automated test input by the user is first received. Then the method name is filtered out from the test code, wherein the number of the method names includes one or more. After that, the method data corresponding to the method name is extracted from the pre-created pytest decorator. Among them, the pytest decorator is obtained by encapsulating the public method related to the automated test. After obtaining the method data, the method data is used to update the first test code to obtain the specified code. Finally, the specified code is sent to the Gitlab server so that the Gitlab server stores the specified code in the code management warehouse, so that the specified code can be used to generate the automated test script for automated testing. This embodiment enables users to avoid having to repeatedly write public methods and write all the data contained in the public methods into the test code. Instead, users only need to pass in the method name of the public method, and then intelligently use the pytest decorator to obtain the specified code based on the test code containing the method name, effectively reducing the workload of users' repeated code writing and reducing the limitations of test code writing.
[0077] Furthermore, in an embodiment of the present application, before the above step S202, the following steps are included:
[0078] S2020: Get the public methods corresponding to the automated tests;
[0079] S2021: Encapsulate the common method into a pytest decorator;
[0080] S2022: Store the pytest decorator in a pre-created first designated file.
[0081] As described in steps S2020 to S2022 above, before the step of extracting the method data corresponding to the above method name from the pre-created pytest decorator, it also includes a creation process for creating the pytest decorator. Specifically, first obtain the public method corresponding to the automated test. Among them, there is no specific limitation on the acquisition method of the above public method, and the above public method can be obtained by querying the network resources related to the automated test, or by receiving the commonly used public method input by the developer. After obtaining the above public method, the above public method is encapsulated into a pytest decorator. Among them, the pytest decorator is defined in front of the function by using the pytest.fixture identifier. When the user writes a test function, this function name can be used as an incoming parameter, and the pytest decorator will use the return value of the function as the incoming parameter of the test function in a dependency injection manner. Finally, the above pytest decorator is stored in the first pre-created specified file, wherein the first specified file can be specifically a conftest.py file. By storing the above-mentioned pytest decorator in the first designated file, it is beneficial to process the test code containing the method name written by the user according to the pytest decorator during the subsequent automated testing process, and then generate the designated script required for subsequent automated testing.
[0082] Furthermore, in one embodiment of the present application, the above step S3 includes:
[0083] S300: Compile the specified code.
[0084] S301: Obtaining a compilation result generated after the specified code executes the compilation operation;
[0085] S302: Acquire a script template corresponding to the automated test request from a preset script database;
[0086] S303: Generate the automated test script according to the compilation result and the script template.
[0087] As described in steps S300 to S303 above, the step of generating an automated test script corresponding to the specified code according to the specified code may specifically include: first, performing a compile operation on the specified code. Then, the compilation result generated after the specified code is compiled is obtained, wherein the code can be compiled by a compiler to obtain the compilation result. The compilation method can adopt an existing commonly used code compilation scheme, which is not repeated here. After obtaining the compilation result, the script template corresponding to the automated test request is obtained from a preset script database. Among them, various types of script template files are stored in the script database. Finally, according to the compilation result and the script template, the automated test script is generated, so that the generated automated test script is subsequently copied to the Docker image in the container cloud platform, and the corresponding pod is generated, and then the automated test script is executed in the pod to complete the automated test. Specifically, the script template corresponding to the automated test request can be referred to, and the compilation result can be input into the corresponding position of the script template to obtain the automated test script.
[0088] Furthermore, in an embodiment of the present application, before the above step S4, the following steps are included:
[0089] S400: Acquire a dependency library of a Python program, and package the Python dependency library into a second designated file corresponding to a designated file type;
[0090] S401: Obtain an input Dockerfile file;
[0091] S402: placing the second designated file and the Dockerfile file in the same pre-created designated directory;
[0092] S403: Obtain a basic image, wherein the basic image includes a running environment of a Python program;
[0093] S404: Packing the dependent libraries of the Python program in the specified directory into the basic image through the Docker build command to obtain a corresponding Docker image;
[0094] S405: Send the Docker image to the image repository for storage through the Docker push command;
[0095] The step of pulling the preset Docker image from the image repository in step S4 includes:
[0096] S410: Obtain second address information of the image repository;
[0097] S411: Pull the Docker image from the image repository according to the second address information.
[0098] As described in the above steps S400 to S405, before the step of pulling the preset Docker image from the image warehouse, it also includes a generation process of generating the Docker image, specifically, first obtaining the dependency library of the python program, and packaging the dependency library of the above python program into a second specified file corresponding to the specified file type. Wherein, the dependency library of the above python program is some existing method data that has been developed based on the python language, and the dependency library of the python program can be obtained by downloading from relevant network resources (such as the official website of the python language). In addition, the above specified file type is specifically a tar.gz file type. Then obtain the Dockerfile written and input by the developer, and place the above second specified file and the above Dockerfile file in the same specified directory. Wherein, the above Dockerfile file is a build file for building a Docker image, which is a script file composed of a series of commands and parameters. The Dockerfile file can be written and input by the developer according to actual business needs to obtain. In addition, when building a Docker image, the commands contained in the Dockerfile file, such as the python installation command and the installation command of the dependency library of the python program, will be executed sequentially. After that, the base image is obtained, wherein the base image includes the operating environment of the python program. If the user needs to add some data or modify some data in the operating environment of python, the base image needs to be modified accordingly, and then the modified base image is used to replace the previous base image. After obtaining the base image and the specified directory, the dependency library of the python program in the specified directory is packaged into the base image through the Docker build command to obtain the corresponding Docker image. Wherein, for example, the Docker build command can be specifically Dockerbuild-t image warehouse address / image name: image version. Finally, the Docker image is sent to the preset image warehouse for storage through the Docker push command, so that the preset Docker image can be quickly pulled from the image warehouse in the subsequent automated testing process, and the Docker image is deployed in the container cloud platform. Wherein, after the above-mentioned Docker image is generated, the Docker image needs to be saved and used later, for example, the Docker image can be pushed to the image warehouse for saving, and the Docker image will not be lost after saving, which ensures the security of the Docker image.In addition, for example, the Docker push command may be specifically Docker dockerpush image repository address / image name:image version. Further, as described in steps S410 to S411, the step of obtaining the preset Docker image may specifically include: first obtaining the second address information of the image repository, and then pulling the Docker image from the image repository according to the second address information.
[0099] In one embodiment of the present application, before the above step S1, the following steps are included:
[0100] S100: monitoring the cloud container platform within a preset time period to obtain status information corresponding to the cloud container platform;
[0101] S101: judging whether an abnormality occurs in the container state of the cloud container platform according to the state information;
[0102] S102: If it is determined that there is no abnormality in the container state of the cloud container platform, an acquisition instruction for acquiring first address information of a code management repository is generated.
[0103] As described in the above steps S100 to S102, when an automated test request is received, before the process of obtaining the first address information of the code management warehouse is performed, it is necessary to further monitor whether the pre-created container cloud platform can operate normally, so as to ensure that the subsequent automated test can be smoothly performed according to the cloud container platform. Specifically, the above cloud container platform is first monitored within a preset time period to obtain the status information corresponding to the above cloud container platform. Among them, the above preset time period is not specifically limited, and can be set according to actual needs, for example, it can be set to within 10 minutes after the cloud container platform is successfully created. In addition, the above status information can be obtained by obtaining and analyzing the relevant operation data of the cloud container platform, and the above relevant operation data may specifically include CPU usage, memory usage, network throughput and space utilization, etc. Then, according to the above status information, it is determined whether the container state of the above cloud container platform is abnormal. Among them, the above status information may specifically include normal operation or abnormal operation, and the relevant operation data can be compared with the preset standard threshold. If the relevant operation data is within the range of the standard threshold, the status information is determined to be normal operation, otherwise the status information is determined to be abnormal operation. If it is determined that the container state of the cloud container platform is not abnormal, an acquisition instruction for acquiring the first address information of the code management warehouse is generated. In another embodiment, if it is determined that the container state of the cloud container platform is abnormal, a preset container creation script is called to automatically create a cloud container platform identical to the cloud container platform, and then the newly created cloud container platform is used to execute subsequent automated testing processes, so as to achieve rapid and intelligent reconstruction of the container cloud platform after an abnormality occurs in the container state of the container cloud platform, so that a more reliable automated testing process can be performed subsequently through the regenerated cloud container platform.
[0104] Furthermore, in an embodiment of the present application, after the above step S6, the following steps are included:
[0105] S600: Obtaining the running result of the automated test script;
[0106] S601: Compare the actual output corresponding to the operation result with the expected output to obtain a comparison result;
[0107] S602: Generate a test report of the automated test script according to the running result and the comparison result;
[0108] S603: Display the test report.
[0109] As described in steps S600 to S603, after the step of executing the automated test script in the pod, a corresponding test report can also be generated according to the running result generated after the automated test script is executed. Specifically, the running result of the automated test script is first obtained. Then the actual output corresponding to the running result is compared with the expected output to obtain a comparison result. Among them, the running result of the automated test script is the actual result corresponding to the automated test, and the preset output is the expected result corresponding to the automated test. By comparing the actual result with the expected result, the specific test situation of this automated test can be obtained. When the comparison result is obtained, a test report of the automated test script is generated according to the comparison result. Among them, the content of the test report can specifically include actual output data, and the difference data between the actual output and the expected output. After the test report is generated, the test report is finally displayed so that the user can clearly know the specific test data of this automated test according to the test report, and clearly understand the specific test situation, so that subsequent users can make corresponding improvements to the subsequent automated test process according to the test report.
[0110] Reference Figure 2 In one embodiment of the present application, an automated testing device is also provided, including:
[0111] A first acquisition module 1 is used to acquire first address information of a code management warehouse when receiving an automated test request;
[0112] A second acquisition module 2 is used to acquire, according to the first address information, the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0113] A first generating module 3, used to generate an automated test script corresponding to the specified code according to the specified code;
[0114] Deployment module 4, used to pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform;
[0115] The second generation module 5 is used to copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0116] The execution module 6 is used to execute the automated test script in the pod.
[0117] In this embodiment, the implementation process of the functions and effects of the first acquisition module, the second acquisition module, the first generation module, the deployment module, the second generation module and the execution module in the above-mentioned automated testing device is specifically described in the implementation process of the corresponding steps S1 to S6 in the above-mentioned automated testing method, and will not be repeated here.
[0118] Furthermore, in one embodiment of the present application, the above-mentioned automated testing device includes:
[0119] A first receiving module, used for receiving an input test code corresponding to an automated test;
[0120] A screening module, used for screening out method names from the test code, wherein the number of the method names includes one or more;
[0121] Extraction module, used to extract method data corresponding to the method name from the pre-created pytest decorator;
[0122] An updating module, used for updating the test code using the method data to obtain the specified code;
[0123] The first sending module is used to send the specified code to the Gitlab server, so that the specified code is stored in the code management warehouse through the Gitlab server.
[0124] In this embodiment, the implementation process of the functions and effects of the first receiving module, screening module, extraction module, update module and first sending module in the above-mentioned automated testing device is specifically described in the implementation process of the corresponding steps S200 to S204 in the above-mentioned automated testing method, and will not be repeated here.
[0125] Furthermore, in one embodiment of the present application, the above-mentioned automated testing device includes:
[0126] The third acquisition module is used to acquire the public method corresponding to the automated test;
[0127] Encapsulation module, used to encapsulate the common method into a pytest decorator;
[0128] A storage module is used to store the pytest decorator in a pre-created first specified file.
[0129] In this embodiment, the implementation process of the functions and effects of the third acquisition module, encapsulation module and storage module in the above-mentioned automatic testing device is specifically described in the implementation process of the corresponding steps S2020 to S2022 in the above-mentioned automatic testing method, and will not be repeated here.
[0130] Furthermore, in one embodiment of the present application, the first generating module includes:
[0131] A compiling unit, used to perform a compiling operation on the specified code;
[0132] A first acquisition unit, used to acquire a compilation result generated after the specified code executes the compilation operation;
[0133] A second acquisition unit is used to acquire a script template corresponding to the automated test request from a preset script database;
[0134] A generating unit is used to generate the automated test script according to the compilation result and the script template.
[0135] In this embodiment, the implementation process of the functions and effects of the compiling unit, the first acquisition unit, the second acquisition unit and the generating unit in the above-mentioned automatic testing device is specifically described in the implementation process of the corresponding steps S300 to S303 in the above-mentioned automatic testing method, and will not be repeated here.
[0136] Furthermore, in one embodiment of the present application, the above-mentioned automated testing device includes:
[0137] A fourth acquisition module is used to acquire a dependency library of a Python program, and package the Python dependency library into a second specified file corresponding to a specified file type;
[0138] The fifth acquisition module is used to obtain the input Dockerfile file;
[0139] A placement module, used to place the second specified file and the Dockerfile file in the same pre-created specified directory;
[0140] A sixth acquisition module is used to acquire a basic image, wherein the basic image includes a running environment of a Python program;
[0141] A packaging module is used to package the dependent libraries of the Python program in the specified directory into the basic image through the Docker build command to obtain a corresponding Docker image;
[0142] A second sending module is used to send the Docker image to the image warehouse for storage through a Docker push command;
[0143] The above deployment modules include:
[0144] A third acquisition unit, used to acquire second address information of the image repository;
[0145] A pulling unit is used to pull the Docker image from the image repository according to the second address information.
[0146] In this embodiment, the implementation process of the functions and effects of the fourth acquisition module, the fifth acquisition module, the placement module, the sixth acquisition module, the packaging module and the second sending module in the above-mentioned automated testing device is specifically detailed in the implementation process of the corresponding steps S400 to S405 in the above-mentioned automated testing method, and will not be repeated here. And the implementation process of the functions and effects of the third acquisition unit and the pulling unit in the above-mentioned automated testing device is specifically detailed in the implementation process of the corresponding steps S410 to S411 in the above-mentioned automated testing method, and will not be repeated here.
[0147] Furthermore, in one embodiment of the present application, the above-mentioned automated testing device includes:
[0148] A seventh acquisition module, used to monitor the cloud container platform within a preset time period and obtain status information corresponding to the cloud container platform;
[0149] A judgment module, used to judge whether an abnormality occurs in the container state of the cloud container platform according to the state information;
[0150] The third generating module is used to generate an acquisition instruction for acquiring the first address information of the code management warehouse if it is determined that there is no abnormality in the container status of the cloud container platform.
[0151] In this embodiment, the implementation process of the functions and effects of the seventh acquisition module, the judgment module and the third generation module in the above-mentioned automatic testing device is specifically detailed in the implementation process of the corresponding steps S100 to S102 in the above-mentioned automatic testing method, and will not be repeated here.
[0152] Furthermore, in one embodiment of the present application, the above-mentioned automated testing device includes:
[0153] An eighth acquisition module, used to obtain the running result of the automated test script;
[0154] A comparison module, used to compare the actual output corresponding to the operation result with the expected output to obtain a comparison result;
[0155] A fourth generating module, used to generate a test report of the automated test script according to the running result and the comparison result;
[0156] The display module is used to display the test report.
[0157] In this embodiment, the implementation process of the functions and effects of the eighth acquisition module, comparison module, fourth generation module and display module in the above-mentioned automatic testing device is specifically detailed in the implementation process of the corresponding steps S600 to S603 in the above-mentioned automatic testing method, and will not be repeated here.
[0158] Reference Figure 3 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed for the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as first address information, specified codes and Docker images. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an automated testing method is implemented.
[0159] The above processor executes the steps of the above automated testing method:
[0160] When receiving an automated test request, obtaining first address information of the code management repository;
[0161] According to the first address information, obtaining the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0162] According to the specified code, generate an automated test script corresponding to the specified code;
[0163] Pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform;
[0164] Copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0165] The automated test script is executed in the pod.
[0166] Those skilled in the art will understand that Figure 3 The structure shown in is merely a block diagram of a portion of the structure related to the present application scheme, and does not constitute a limitation on the devices and computer equipment to which the present application scheme is applied.
[0167] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, an automated testing method is implemented, specifically:
[0168] When receiving an automated test request, obtaining first address information of the code management repository;
[0169] According to the first address information, obtaining the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform;
[0170] According to the specified code, generate an automated test script corresponding to the specified code;
[0171] Pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform;
[0172] Copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod;
[0173] The automated test script is executed in the pod.
[0174] In summary, the automated testing method, apparatus, computer equipment, and storage medium provided in the embodiments of the present application obtain the first address information of the code management warehouse when receiving an automated testing request; obtain the specified code corresponding to the automated testing request from the code management warehouse through the code management tool preset in the container cloud platform according to the first address information; generate an automated testing script corresponding to the specified code according to the specified code; pull the preset Docker image from the image warehouse, and deploy the Docker image in the container cloud platform; copy the automated testing script to the Docker image in the container cloud platform to generate a corresponding pod; and execute the automated testing script in the pod. The embodiments of the present application increase the portability of the test environment for automated testing by using container technology and image technology to generate a pod for automated testing. When an exception occurs in a pod, a new pod can be quickly generated to redeploy the test running environment for executing automated tests, and the test running environment will not be lost, ensuring the reusability and maintainability of the test running environment for automated testing. This effectively avoids the need for traditional automated testing methods to redeploy the test running environment when an exception occurs in the test running environment deployed on the automated testing server, thereby improving the test efficiency and stability of automated testing.
[0175] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0176] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0177] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. An automated testing method, characterized in that: include: When receiving an automated test request, obtaining first address information of the code management repository; According to the first address information, obtaining the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform; According to the specified code, generate an automated test script corresponding to the specified code; Pull a preset Docker image from the image repository and deploy the Docker image in the container cloud platform; Copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod; Executing the automated test script in the pod; Before the step of pulling a preset Docker image from the image repository and deploying the Docker image in the container cloud platform, the following steps are included: Obtain a dependent library of a Python program, and package the dependent library of the Python program into a second specified file corresponding to a specified file type; Get the input Dockerfile file; Placing the second designated file and the Dockerfile file in the same pre-created designated directory; Obtain a basic image, wherein the basic image includes a running environment of a Python program; By using the Docker build command, the dependent libraries of the Python program in the specified directory are packaged into the base image to obtain a corresponding Docker image; Send the Docker image to the image warehouse for storage through the Docker push command; The step of pulling the preset Docker image from the image repository includes: Obtaining second address information of the image repository; Pull the Docker image from the image repository according to the second address information.
2. The automated testing method according to claim 1, characterized in that: Before the step of acquiring the specified code corresponding to the automated test request from the code management repository through a code management tool in a preset container cloud platform according to the first address information, the method further includes: receiving input test code corresponding to the automated test; Filtering method names from the test code, wherein the number of the method names includes one or more; Extract the method data corresponding to the method name from the pre-created pytest decorator; Using the method data to update the test code, to obtain the specified code; The specified code is sent to the Gitlab server so that the specified code is stored in the code management warehouse through the Gitlab server.
3. The automated testing method according to claim 2, characterized in that: Before the step of extracting the method data corresponding to the method name from the pre-created pytest decorator, the method includes: Get the public methods corresponding to the automated tests; Encapsulate the public method into a pytest decorator; Store the pytest decorator in the pre-created first specified file.
4. The automated testing method according to claim 1, characterized in that: The step of generating an automated test script corresponding to the specified code according to the specified code comprises: Performing a compile operation on the specified code; Obtaining a compilation result generated after the specified code executes the compilation operation; Acquire a script template corresponding to the automated test request from a preset script database; The automated test script is generated according to the compilation result and the script template.
5. The automated testing method according to claim 1, characterized in that: Before the step of obtaining the first address information of the code management repository when receiving the automated test request, the method includes: Monitoring the container cloud platform within a preset time period to obtain status information corresponding to the container cloud platform; According to the status information, determining whether an abnormality occurs in the container status of the container cloud platform; If it is determined that the container status of the container cloud platform is not abnormal, an acquisition instruction for acquiring the first address information of the code management warehouse is generated.
6. The automated testing method according to claim 1, characterized in that: After the step of executing the automated test script in the pod, the method further comprises: Obtaining the running result of the automated test script; Compare the actual output corresponding to the operation result with the expected output to obtain a comparison result; Generate a test report for the automated test script according to the running result and the comparison result; The test report is displayed.
7. An automated testing device for executing the method according to any one of claims 1 to 6, characterized in that: include: A first acquisition module, configured to acquire first address information of a code management repository when receiving an automated test request; A second acquisition module is used to acquire, according to the first address information, the specified code corresponding to the automated test request from the code management warehouse through a code management tool preset in the container cloud platform; A first generating module, configured to generate an automated test script corresponding to the specified code according to the specified code; A deployment module, used to pull a preset Docker image from an image repository and deploy the Docker image in the container cloud platform; A second generation module is used to copy the automated test script to the Docker image in the container cloud platform to generate a corresponding pod; An execution module is used to execute the automated test script in the pod.
8. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A storage medium having a computer program stored thereon, characterized in that: The computer program When the program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Service node control method and related equipment
CN110995473A
LXC-based continuous integration method and device
WO2017020770A1