A method, device, electronic equipment and medium for calculating test resources

By splitting and combining automated test tasks, optimizing resource allocation and utilization, the problems of waste and inefficiency in automated tests are solved, and the execution of test cases is effectively completed within the specified time.

CN114911714BActive Publication Date: 2025-05-02SANGFOR TECH INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210681484.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-16
Publication Date
2025-05-02
Estimated Expiration
2042-06-16

AI Technical Summary

Technical Problem

In automated testing, it is difficult for the prior art to efficiently complete the execution of test cases within a specified time, resulting in waste of resources and inefficient utilization.

Method used

By obtaining each test module and its dependent test environment, splitting and combining test tasks according to preset rules to optimize resource allocation and utilization. The specific steps include obtaining the first test task, merging the tasks that depend on the same test environment into the second test task, and calculating the required number of test environments based on the number of unmerged tasks and merged tasks.

Benefits of technology

The minimum test environment resources required to complete the execution of test cases within the specified time are achieved, reducing resource waste and improving the efficiency of automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114911714B_ABST
    Figure CN114911714B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, electronic device and medium for calculating test resources, and relates to the field of automated testing. The method includes obtaining the first test task corresponding to each test module when it depends on each test environment; merging the test cases in the first test task that depends on the same test environment to obtain the second test task; obtaining the number of test cases in the first test task that have not been merged and the number of second test tasks; and taking the sum of the number of test cases in the first test task that have not been merged and the number of second test tasks as the number of test environments required to execute the test case. In this method, the execution time of each test task is less than or equal to the preset duration; considering that the test cases may share the same test background and test environment, the minimum test environment resources required to complete the execution of the test case within the preset duration are calculated, reducing the waste of resources, while achieving the execution efficiency expected by the user.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of automated testing, and in particular to a method, device, electronic device and medium for estimating test resources. Background Art

[0002] As the number of automated test cases increases, the time and efficiency requirements for completing the execution of automated test cases are also getting higher and higher. Usually, the execution of automated test cases needs to be completed within the time specified by the user.

[0003] A test module contains multiple automated test cases. In order to complete the automated tests required for version release within the specified time, the test cases can only be distributed to as many test environments as possible for execution at any cost. Since there may be information associations between the test cases in the test module, such as the same or similar execution steps or shared resources, if the information associations between the test cases are ignored, it may result in low test environment configuration reusability, redundant operations, and thus resource waste; in addition, when running multiple test environments concurrently, the construction of the test environment increases the number of overall automated test resources, resulting in resource waste.

[0004] It can be seen that how to reduce the waste of resources as much as possible while achieving the execution efficiency expected by users is an urgent problem to be solved by technical personnel in this field. Summary of the invention

[0005] The purpose of this application is to provide a method, device, electronic device and medium for calculating test resources, so as to ensure that the execution of test cases is completed within the specified time as much as possible, maximize the utilization rate of the test environment, and avoid waste of resources.

[0006] In order to solve the above technical problems, the present application provides a method for estimating test resources, including:

[0007] Obtain each test module and the test environment that each test case in the test module depends on;

[0008] Obtaining the first test tasks corresponding to each of the test modules when relying on each test environment according to a first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each of the first test tasks is less than or equal to a preset time length;

[0009] Merging the test cases in the first test tasks that depend on the same test environment according to a second preset rule to obtain a second test task; wherein the second preset rule is that the execution time of each second test task is less than or equal to the preset duration;

[0010] Obtaining the number of the test cases in the first test task that have not been merged and the number of the second test tasks;

[0011] The sum of the number of the test cases in the first test task that has not been merged and the number of the second test tasks is used as the number of test environments required to execute the test cases so as to perform resource allocation according to the number of the test environments.

[0012] Preferably, the obtaining of the first test task corresponding to each of the test modules when depending on each test environment comprises:

[0013] Extracting each of the test cases of the current test module, the test environment on which each of the test cases depends, and the time taken to execute each of the test cases;

[0014] When the sum of the total time consumption of the current test case in the current test case set and the time consumption of the test case to be added to the test case set next time is less than or equal to the preset time length, adding the test case to be added next time to the current test case set;

[0015] Otherwise, stop adding the test case to be added next time to the current test case set, and create a new test case set so as to add the test case to be added next time to the test case set, until there is no test case to be added next time;

[0016] Each of the test case sets is used as the first test task corresponding to the current test module when it depends on each of the test environments, and the steps of extracting each of the test cases of the current test module, the test environment that each of the test cases depends on, and the time-consuming steps of executing each of the test cases are returned.

[0017] Preferably, obtaining the test case to be added to the test case set next time includes:

[0018] sorting the test cases to be added according to the test environment on which the test cases depend and the time taken to execute the test cases;

[0019] The test cases that take the longest time are selected one by one as the test cases to be added to the test case set next time.

[0020] Preferably, merging the test cases in the first test task that depend on the same test environment to obtain the second test task includes:

[0021] Obtaining the test cases in the first test task that depend on the same current test environment and the test case switching time;

[0022] In the case where the sum of the total time consumed by the current test case and the test case to be merged next time and the test case switching time is less than or equal to the preset duration, merging the test case to be merged next time into the current second test task;

[0023] Otherwise, stop merging the test case to be merged next time into the current second test task, and create a new second test task until there is no test case to be merged next time;

[0024] Return to the step of obtaining the test cases in the first test task that depend on the same current test environment and the test case switching time.

[0025] Preferably, obtaining the test case to be merged next time includes:

[0026] sorting the test cases according to the time consumption of the test cases;

[0027] The test cases with the shortest time consumption are selected one by one as the test cases to be merged next time.

[0028] Preferably, the time consumed to execute the first test task is less than or equal to the difference between the preset time and the time consumed to prepare the test environment and the time consumed to prepare and remove the test background in the first test task;

[0029] The time taken to execute the second test task is less than or equal to the difference between the preset time and the test environment preparation time, the test background preparation and removal time, and the test case switching time within the second test task.

[0030] Preferably, before obtaining the first test task corresponding to each of the test modules when depending on each test environment, the method further includes:

[0031] Obtain the test cases in each of the test modules that take longer than the preset time;

[0032] Eliminate the test case.

[0033] In order to solve the above technical problems, the present application also provides a device for estimating test resources, including:

[0034] A first acquisition module is used to acquire each test module and the test environment on which each test case in the test module depends;

[0035] A second acquisition module is used to acquire the first test tasks corresponding to each of the test modules when relying on each test environment according to a first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each of the first test tasks is less than or equal to a preset time length;

[0036] A merging module, used for merging the test cases in the first test tasks that depend on the same test environment according to a second preset rule so as to obtain a second test task; wherein the second preset rule is that the execution time of each of the second test tasks is less than or equal to the preset duration;

[0037] A third acquisition module, used to acquire the number of the test cases in the first test task that have not been merged and the number of the second test tasks;

[0038] As a module, it is used to use the sum of the number of the test cases in the first test task that has not been merged and the number of the second test tasks as the number of test environments required to execute the test cases so as to allocate resources according to the number of test environments.

[0039] In order to solve the above technical problems, the present application also provides an electronic device, including:

[0040] Memory for storing computer programs;

[0041] A processor is used to implement the steps of the above-mentioned method for calculating test resources when executing the computer program.

[0042] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method for calculating test resources are implemented.

[0043] The method for calculating test resources provided in the present application includes obtaining the first test task corresponding to each test module when it depends on each test environment; merging the test cases in the first test task that depends on the same test environment to obtain the second test task; obtaining the number of test cases in the first test task that has not been merged and the number of second test tasks; using the sum of the number of test cases in the first test task that has not been merged and the number of second test tasks as the number of test environments required to execute the test case to allocate resources according to the number of test environments. In this method, the execution time of each first test task and the execution time of each second test task are both less than or equal to the preset duration; in addition, considering that the test cases share the same test background and the same test environment, the minimum test environment resources required to complete the execution of the test case within the preset duration are calculated, which reduces the waste of resources and achieves the execution efficiency expected by the user.

[0044] In addition, the present application also provides a device for estimating test resources, an electronic device, and a computer-readable storage medium, which correspond to the method for estimating test resources mentioned above and have the same effect as above. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0046] Figure 1 A schematic diagram of the hardware architecture of a test resource for inference provided in this application;

[0047] Figure 2 A flowchart of a method for estimating test resources provided in an embodiment of the present application;

[0048] Figure 3 A flowchart for obtaining a first test task provided in an embodiment of the present application;

[0049] Figure 4 A flowchart for obtaining a second test task provided in an embodiment of the present application;

[0050] Figure 5 A structural diagram of a device for estimating test resources provided in one embodiment of the present application;

[0051] Figure 6 A structural diagram of an electronic device provided in another embodiment of the present application. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0053] The core of this application is to provide a method, device, electronic device and medium for calculating test resources, which are used to ensure that the execution of test cases is completed within the specified time as much as possible, maximize the utilization of the test environment, and avoid waste of resources.

[0054] To facilitate understanding, the hardware structure used in the technical solution of this application is introduced below. Figure 1 A schematic diagram of the hardware architecture of a test resource for inference provided in this application. Figure 1As shown, the monitoring device is connected to multiple devices to collect the time consumed by each device to execute the test case, the time consumed to set up the test environment, etc. Automated test cases are codes that convert test cases into codes and are executed by computers. In this application, a device can be understood as a test environment for executing automated test cases. Concurrent execution of test cases can be understood as executing automated test cases simultaneously on multiple test environments.

[0055] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Figure 2 A flowchart of a method for estimating test resources provided in an embodiment of the present application. Figure 2 As shown, the method includes:

[0056] S10: Obtain the test environment that each test module and each test case in the test module depends on.

[0057] When executing automated testing tasks, there may be multiple test cases using the same test environment. The preparation and construction of a test environment may take a lot of time. Therefore, the efficiency of executing test cases can be improved by reducing the time spent on preparing and building the same test environment multiple times.

[0058] Each test module usually contains one or more test cases, and each test case is executed in a corresponding test environment. Therefore, in order to calculate the test resources required for the execution of automated tests, each test module is first obtained as well as the test environment that each test case in each test module depends on. It should be noted that obtaining each test module can be obtaining all test modules or only obtaining the modules to be tested. In implementation, in order to reduce the time required to calculate the test resources required for the execution of automated tests, obtaining each test module here refers to obtaining each module to be tested.

[0059] S11: Obtain the first test task corresponding to each test module when it depends on each test environment according to the first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each first test task is less than or equal to the preset time.

[0060] In order to complete the execution of the test case within the time specified by the user as much as possible, when the test case is divided into multiple test tasks for execution, it is necessary to ensure that the time consumed for executing each test task is less than or equal to the preset time as much as possible. It should be noted that the preset time here refers to the time consumed for executing the test case specified by the user. Preferably, the time consumed for executing each test task is equal to the time consumed for executing the test case specified by the user, thereby maximizing the utilization rate of the test environment. The first test task contains one or more test cases, and the number of the first test tasks can be one or more. The number of test cases contained in the first test task and the number of the first test tasks are both dependent on the time consumed for executing each test case. When the time consumed for executing a test case is less than or equal to the time consumed for executing the user, the test case is used as a first test task, or when the time consumed for executing a test case plus the time consumed for executing other test cases is less than or equal to the time consumed for executing the user, the test case and other test cases are used together as the first test task. In implementation, the first test task corresponding to each test module when it depends on each test environment is analyzed.

[0061] In addition, considering the information association between the test cases of a test module, such as the same or similar execution steps or shared resources, when the number of automated test cases of a test module reaches the scale that needs to be executed concurrently, in the design of the automated test cases, the general test configuration required by the test cases is extracted to become the test background. Ultimately, the information integrity of a test case will be composed of the module test background and the inherent information of the test case, so that the structural content of the test case is more compact, redundant steps in multiple test cases are eliminated, and the number of steps required to execute the automated test is reduced. Therefore, preferably, the same test task shares the same test background. Finally, the first test task that shares the same test background and the execution time of each first test task that is less than or equal to the preset time length is used as the first test rule to obtain the first test task corresponding to each test module when relying on each test environment.

[0062] S12: Merging the test cases in the first test tasks that depend on the same test environment according to a second preset rule to obtain a second test task; wherein the second preset rule is that the execution time of each second test task is less than or equal to a preset duration.

[0063] In the above steps, the repeated steps between test cases are reduced by means of test background, which improves the execution efficiency of test cases. However, it also introduces new efficiency-related issues: when the preparation and construction of a test environment is time-consuming, when the number of test cases in a test task is small, it will still cause waste of resources and the cost of preparing the test environment is too high. In implementation, each test task may come from different test modules and have different test backgrounds, but they may require the same type of test environment. In order to alleviate the problem of high environment construction cost when executing automated tests in multiple environments concurrently, by scheduling test tasks that rely on the same type of test environment to one test environment, the impact of test environment construction on the overall number of automated test resources can be effectively reduced.

[0064] Specifically, in the above steps, the first test tasks corresponding to each test module when it depends on each test environment are obtained according to the first preset rule. Therefore, in this step, the first test tasks in different test modules that depend on the same test environment can be merged to obtain the second test task. It should be noted that in order to ensure that the execution of the test case can be completed within the preset time, that is, the time specified by the user, according to the second test rule, the execution time of each second test task is less than or equal to the preset time. Preferably, the time consumed to execute the second test task is equal to the time specified by the user, so that the test environment can be maximized.

[0065] In the process of merging the test cases in the first test task that rely on the same test environment, the test cases in the first test task may be merged or not merged. When the execution time of a test case in the first test task is less than or equal to the preset time, if the execution time of the test case plus the execution time of another test case exceeds the preset time, then the test case is the test case in the first test task that has not been merged; if the execution time of the test case plus the execution time of another test case is less than or equal to the preset time, when the execution time of a certain test case is added, the total time is greater than the preset time, then the test case is merged with the other test case to obtain a second test task. The time to complete a second test task is equal to the sum of the execution time of each test case and the test background deployment and cleanup time.

[0066] S13: Obtain the number of test cases in the first test task that have not been merged and the number of the second test task.

[0067] In order to allocate a reasonable test environment to the test case specified by the user, this embodiment calculates the test environment required to execute the test case. After the above steps, the first test task is merged to obtain the test cases and the second test task in the first test task that are not merged, and the number of test cases and the number of the second test task in the first test task that are not merged are obtained respectively.

[0068] S14: taking the sum of the number of test cases in the unmerged first test task and the number of the second test task as the number of test environments required to execute the test cases, so as to allocate resources according to the number of test environments.

[0069] Finally, the number of test environments required to execute the test cases is equal to the sum of the number of test cases in the unmerged first test task and the number of the second test task. The corresponding execution strategy is to allocate independent test environments for the test cases in the unmerged first test task and the second test task, respectively, to achieve resource allocation.

[0070] It should be noted that in the above steps, the time consumption of each test case, the time consumption of test environment preparation, the time consumption of test background preparation of test tasks, etc. can all be obtained in a simple way, and only needs to be collected during the automated testing process.

[0071] The method for calculating test resources provided in this embodiment includes obtaining the first test task corresponding to each test module when it depends on each test environment; merging the test cases in the first test task that depends on the same test environment to obtain the second test task; obtaining the number of test cases in the first test task that have not been merged and the number of second test tasks; taking the sum of the number of test cases in the first test task that have not been merged and the number of second test tasks as the number of test environments required to execute the test case to allocate resources according to the number of test environments. In this method, the execution time of each first test task and the execution time of each second test task are both less than or equal to the preset duration; in addition, considering that the test cases share the same test background and the same test environment, the minimum test environment resources required to complete the execution of the test case within the preset duration are calculated, which reduces the waste of resources and achieves the execution efficiency expected by the user.

[0072] Because different test modules do not share the test background, and even one test module often needs to rely on different types of test environments, it is not possible to directly combine test cases of different or the same module. Therefore, in order to more accurately calculate the test resources, the test tasks are first split within the test module. As a preferred implementation, obtaining the first test task corresponding to each test module when relying on each test environment includes:

[0073] Extract the test cases of the current test module, the test environment that each test case depends on, and the time required to execute each test case;

[0074] When the sum of the total time consumption of the current test case in the current test case set and the time consumption of the test case to be added to the test case set next time is less than or equal to the preset time length, adding the test case to be added next time to the current test case set;

[0075] Otherwise, stop adding the next test case to be added to the current test case set, and create a new test case set to add the next test case to be added to the test case set, until there is no next test case to be added;

[0076] Each test case set is used as the first test task corresponding to the current test module when it depends on each test environment, and the steps of extracting each test case of the current test module, the test environment that each test case depends on, and the time-consuming step of executing each test case are returned.

[0077] In this embodiment, the test modules are analyzed one by one. The test cases that rely on the same test environment are gathered together to create a test case set, which is the first test task. When creating a test case set, the total time consumed to execute each test case in the test case set is less than or equal to the preset duration. Preferably, the total time consumed to execute each test case is equal to the preset duration. It should be noted that there is no limitation on the method for creating a test case set. In this embodiment, the method for creating a test case set is to add test cases one by one to the test case set so that the total time consumed by the test cases in the test case set is within the preset duration. In implementation, other methods may also be used to create a test case set, such as pre-storing multiple test cases in the test case set. When the total time consumed by these test cases is greater than the preset duration, the test case is removed from the test case set so that the total time consumed by the test cases in the test case set is less than or equal to the preset duration.

[0078] Add test cases one by one to the test case set, and judge whether it is necessary to add the next test case to be added to the test case set according to the relationship between the total time consumption of the test cases in the test case set and the time consumption of the next test case to be added and the preset environment. When the sum is less than or equal to the preset time, add the next test case to be added to the test case set; when the sum is greater than the preset time, stop adding the next test case to be added to the test case set. When the test case set is just created, there are no test cases in the test case set. At this time, the total time consumption of the test cases in the test case set is 0s, and the next test case to be added is the first test case in the test case set. After the first test case is added to the test case set, the total time consumption of the test cases in the test case set is the time consumption of the first test case, and then add the next test case to be added to the test case set, and so on, until the total time consumption of the test cases in the test case set and the time consumption of the next test case to be added is greater than the preset time, stop adding the next test case to be added to the test case set. It should be clear that before the judgment is made, the next test case to be added is not added to the test case set, but after the judgment is made, it is determined whether to add the next test case to be added to the test case set.

[0079] The embodiment provides adding a test case to the test case set and using the test case set as the first test task. Compared with directly combining test cases of different or the same test modules, the embodiment first splits the test tasks within the test module according to the dependent test environment, which can more accurately infer the test resources.

[0080] On the basis of the above embodiment, in order to reduce the impact of the escort effect of the case and facilitate the creation of the test case set, as a preferred implementation method, obtaining the test case to be added to the test case set next time includes:

[0081] Sort the test cases to be added according to the test environment that each test case depends on and the time it takes to execute each test case;

[0082] The test cases that take the longest time are selected one by one as the test cases to be added to the test case set next time.

[0083] In implementation, in order to reduce the impact of the case escort effect and facilitate the creation of a test case set, for each test module, each test case is sorted according to the execution time of the test case in each test environment. Each test case in each test module is a test case to be added. When sorting, the test cases can be arranged in order from long to short or from short to long according to the time consumption, which is not limited here. After sorting the test cases to be added in each test module, starting with the test case with the longest time consumption, they are added one by one as test cases to be added to the test case set.

[0084] Figure 3 A flowchart of obtaining a first test task is provided in an embodiment of the present application. Figure 3 As shown, the process includes the following steps:

[0085] S15: Determine whether the time taken to execute the slowest case is greater than the user requirement; if so, proceed to step S16; if not, proceed to step S17;

[0086] S16: End the test case that takes the longest time;

[0087] S17: Obtain each test module and start creating a first test task according to each test module;

[0088] S18: Extract all test cases of the current module and sort them by dependent test environment and time consumption;

[0089] S19: Start executing the following process for each test environment;

[0090] S20: Create a test case set and add the test case that takes the longest time in the test environment;

[0091] S21: Calculate the total time margin of the test case set, where the total time margin is equal to the difference between the preset time and the current time;

[0092] S22: starting from the test case with the longest time consumption, determine whether there is a test case whose time consumption is less than or equal to the margin; if not, return to S20; if so, proceed to step S23;

[0093] S23: Add the test case to the test case set;

[0094] S24: Determine whether there are still test cases; if so, return to S21; if not, proceed to step S25;

[0095] S25: Determine whether there are still test modules; if so, return to step S18; if not, end.

[0096] According to the above process, it is assumed that the test modules that the user needs to execute include the first test module and the second test module, and the preset duration is 15s. The first test module contains 3 test cases, namely test case 1, test case 2, and test case 3, among which test case 1 depends on test environment 1, and the execution time of test case 1 is 10s; test case 2 depends on test environment 2, and the execution time of test case 2 is 5s; test case 3 depends on test environment 1, and the execution time of test case 3 is 4s. The second test module contains 2 test cases, namely test case 4 and test case 5, among which test case 4 depends on test environment 1, and the execution time of test case 4 is 2s; test case 5 depends on test environment 2, and the execution time of test case 5 is 7s. Analyze the first test module and the second test module respectively. In the first test module, according to the time consuming order of the test environment and the test case, the time consuming order is as follows: test case 1, test case 3, the corresponding time consuming is 10s, 4s respectively. First, add the test case with the longest time consumption, i.e., test case 1, to the test case set. According to the fact that the total time consumption margin of the test case set is equal to the difference between the time required by the user and the current time consumption, the total time consumption margin of the test case set is equal to 15s-10s=5s; the next test case to be added is test case 3, and the time consumption of test case 3 is 4s, which is less than the margin of 5s, so test case 3 can be added to the test case set. Since the test cases that depend on test environment 1 in the first test module are only test case 1 and test case 3, after adding test case 1 and test case 3 to the test case set, there are no test cases in the first test module, so the test task set for the first test module in test environment 1 is completed. The test task set is also the first test task. Similarly, a test task set for the first test module in test environment 2 and a test task set for the second test module in test environment 1 and test environment 2 can be created. The test task set finally created is: in the test environment 1 of the first test module, the test task set includes test case 1 and test case 3; in the test environment 2 of the first test module, the test task set includes test case 2; in the test environment 1 of the second test module, the test task set includes test case 4; in the test environment 2 of the second test module, the test task set includes test case 5. So far, the test task set of each test module in each test environment is obtained, that is, the first test task.

[0097] The present embodiment provides a method for sorting test cases in each test environment according to the execution time of the test cases. After sorting, starting from the test case with the longest execution time, each test case is added to the test case set one by one, which can reduce the impact of the case escort effect and facilitate the creation of the test case set to obtain the first test task.

[0098] In order to reduce the time consumption of setting up the test environment, in implementation, as a preferred implementation mode, merging the test cases in the first test task that depends on the same test environment to obtain the second test task includes:

[0099] Obtain test cases in the first test task that depend on the same current test environment and the test case switching time;

[0100] In the case where the sum of the total time consumption of the current test case and the next test case to be merged and the test case switching time is less than or equal to the preset duration, the next test case to be merged is merged into the current second test task;

[0101] Otherwise, stop merging the next test case to be merged into the current second test task, and create a new second test task until there is no next test case to be merged;

[0102] Return to the step of obtaining the test cases in the first test task that depend on the same current test environment and the test case switching time.

[0103] In this embodiment, the test cases in the first test task that rely on the same test environment are merged to obtain the second test task. The time consumption of the second test task is less than or equal to the preset duration. Preferably, the time consumption of the second test task is equal to the preset duration. It should be noted that there is no limitation on the way to obtain the second test task. The way to obtain the second test task in this embodiment is to determine one by one whether the test cases are merged into the second test task. The merger here can also be understood as adding. In implementation, other methods can also be used to obtain the second test task, such as pre-storing multiple test cases in the second test task. When the total time consumption of these test cases is greater than the preset duration, the test cases are removed from the second test task, so that the time consumption of the second test task is less than or equal to the preset duration.

[0104] The test cases in the first test task that rely on the same test environment are merged to obtain the second test task. Compared with obtaining the first test task, this embodiment has a test case switching time when obtaining the second test task. According to the total time consumption of the current test case and the next test case to be merged and the relationship between the sum of the test case switching time and the preset time length, determine whether to merge the next test case to be merged into the current second test task. When the sum is less than or equal to the preset time length, merge the next test case to be merged into the current second test task; when the sum is greater than the preset time length, stop merging the next test case to be merged into the current second test task. When the second test task is just being obtained, there is no test case in the second test task. At this time, the time consumption of the current test case is 0s, and the test case switching time is 0s. Determine the relationship between the time consumption of the next test case to be merged and the preset time length. When the time consumption of the next test case to be merged is less than or equal to the preset time length, merge the test case to be merged into the current second test task, and then return to determine whether to merge the next test case to be merged into the current second test task based on the total time consumption of the current test case and the next test case to be merged and the relationship between the sum of the test case switching time and the preset time length. It should be clear that before the merging, the next test case to be merged is not merged into the second test task, but after the judgment is made, it is determined whether to merge the next test case to be merged into the second test task. The switching time for the test case is usually determined based on prior knowledge.

[0105] The present embodiment provides a method of returning the test cases in the first test task that depends on the same test environment to obtain the second test task, which can reduce the time spent in preparing and setting up the test environment and improve the efficiency of automated testing.

[0106] In practice, if the longest test task is merged, it is easy for short-time tasks and long-time tasks to be merged into the same second test task, resulting in a phenomenon in which more short-time tasks are waiting for the long-time task to be completed, i.e., the phenomenon of case escort occurs. As a preferred implementation method, obtaining the next test case to be merged includes:

[0107] Sort the test cases by their time consumption;

[0108] The test cases with the shortest test time are selected one by one as the test cases to be merged next time.

[0109] In order to reduce the impact of the case escort effect and facilitate the acquisition of the second test task, the test cases are sorted according to the time taken by the test cases. When sorting, the test cases can be arranged in order from long to short or from short to long in terms of time taken, which is not limited here. Starting from the test cases with the shortest time taken, they are taken as the test cases to be merged next time one by one.

[0110] Figure 4 A flowchart of obtaining a second test task is provided in an embodiment of the present application. Figure 4 As shown, the process includes the following steps:

[0111] S26: Classify all test tasks according to the type of test environment they depend on;

[0112] S27: Under each test environment category, sort the first test tasks according to the time consumption of the test cases;

[0113] S28: Obtain the test cases with the shortest time consumption one by one;

[0114] S29: Determine whether the sum of the total time of the current test case and the next test case to be merged and the test case switching time is less than or equal to the preset time length; if so, return to step S28; if not, proceed to step S30;

[0115] S30: completing the generation of the second test task under the test environment;

[0116] S31: Determine whether there are other types of test environments that need to be processed; if so, return to step S27, if not, end.

[0117] According to the above process, based on the examples listed in the embodiments above, it is assumed that the switching time of a test case is 2s. The test cases in the first test task in the test environment 1 include case 1, which takes 10s; case 3, which takes 4s; and case 4, which takes 2s. First, the test case with the shortest time, namely test case 4, is added to the second test task. Since the second test task does not contain any test cases at the beginning, the time taken by the current test case is 0s, and the next test case to be merged, namely test case 4, takes 2s, and the switching time of the test case is 0s. Therefore, the sum of the total time taken by the current test case and the next test case to be merged and the test case switching time is 2s, and the preset duration is 15s, so the next test case to be merged can be judged again. At this time, the time consumption of the current test case is 2s, and the time consumption of the next test case to be merged is test case 3, which consumes 4s. There is a test case switching time of 2s. According to the various time lengths, the total time consumption of the current test case and the next test case to be merged and the sum of the test case switching time can be calculated to be 8s, which is still less than the preset time length, so the next test case to be merged can be judged again. At this time, the total time consumption of the current test case is 6s, and the time consumption of the next test case to be merged is test case 1, which consumes 10s. There are two test case switching times of 4s. According to the various time lengths, the total time consumption of the current test case and the next test case to be merged and the sum of the test case switching time is 20s, which is greater than the preset time length, so test case 1 cannot be merged into the second test task. By analogy, the merging results of the test cases in the first test task in test environment 2 are obtained. The second test task obtained after merging is: Test Case 3 and Test Case 4 are a second test task, and Test Case 2 and Test Case 5 are a second test task. Test Case 1 is a test case in the first test task that has not been merged. The number of test cases in the first test task that has not been merged that is finally obtained is 1, that is, Test Case 1, and the number of second test tasks obtained is 2. The number of allocated test environments is equal to the number of test cases in the first test task that has not been merged and the number of second test tasks, that is, 3 independent test environments need to be allocated. If the traditional method is adopted, a test environment may be allocated to each test case, and 5 test environments may be required in the end. However, by adopting the method of the embodiment of the present application, only 3 test environments are needed to complete the execution of the test case. It can be seen that the method provided in this embodiment calculates the minimum test environment resources required to complete the execution of the test case within the preset time length, reduces the waste of resources, and achieves the execution efficiency expected by the user.

[0118] The merging from the shortest test task provided in this embodiment can avoid the phenomenon of case escort as much as possible, thereby improving the efficiency of automated testing.

[0119] In order to more accurately determine the time required to execute the first test task and the second test task, it is necessary to take into account the time required to set up the test environment and prepare and dismantle the test background. In implementation, as a preferred implementation, the time required to execute the first test task is less than or equal to the difference between the preset time and the time required to prepare the test environment and the time required to prepare and dismantle the test background in the first test task;

[0120] The time consumed to execute the second test task is less than or equal to the difference between the preset time and the test environment preparation time, the test background preparation and removal time, and the test case switching time in the second test task.

[0121] Compared with the time consumption of obtaining the first test task, the test case switching time needs to be taken into consideration when obtaining the time consumption of the second test task.

[0122] The method for calculating the execution time of the first test task and the second test task provided in this embodiment can more accurately estimate the execution time of the first test task and the second test task compared to directly making the execution time of the first test task and the second test task less than the preset time length, so that the automated test case can be completed within the time length specified by the user.

[0123] In implementation, in order to improve the efficiency of automated testing, as a preferred implementation method, before obtaining the first test task corresponding to each test module when relying on each test environment, it also includes:

[0124] Obtain the test cases in each test module that take longer than the preset time;

[0125] Eliminate test cases.

[0126] Automated test cases must be completed within the preset time, so the time consumed by each test case should not exceed the preset time. Therefore, test cases that consume more than the preset time need to be processed; secondly, when obtaining the first test task, it is necessary to judge whether it is necessary to add the next test case to be added to the test case set based on the total time consumed by the test case and the time consumed by the next test case to be added and the relationship with the preset environment. If the time consumed by the current test case has exceeded the preset time, when it is added with the time consumed by the next test case to be added, the total time consumed must still be greater than the preset time. Therefore, in order to simplify the calculation of test cases, test cases that consume more than the preset time can be directly eliminated.

[0127] The method provided in this embodiment of eliminating test cases that take longer than a preset time period before acquiring the first test task can ensure that each test task is completed within the preset time period as much as possible.

[0128] In the above embodiments, the method for estimating test resources is described in detail, and the present application also provides embodiments of the apparatus and electronic device for estimating test resources. It should be noted that the present application describes the embodiments of the apparatus part from two perspectives, one is based on the functional module perspective, and the other is based on the hardware perspective.

[0129] Figure 5 A structural diagram of a device for estimating test resources provided in an embodiment of the present application. This embodiment is based on the perspective of functional modules and includes:

[0130] A first acquisition module 10 is used to acquire each test module and the test environment on which each test case in the test module depends;

[0131] The second acquisition module 11 is used to acquire the first test tasks corresponding to each test module when it depends on each test environment according to the first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each first test task is less than or equal to the preset time length;

[0132] A merging module 12 is used to merge the test cases in the first test tasks that depend on the same test environment according to a second preset rule so as to obtain a second test task; wherein the second preset rule is that the execution time of each second test task is less than or equal to a preset time length;

[0133] A third acquisition module 13 is used to acquire the number of test cases in the first test task that have not been merged and the number of the second test tasks;

[0134] As module 14, it is used to use the sum of the number of test cases in the unmerged first test task and the number of the second test tasks as the number of test environments required to execute the test cases so as to allocate resources according to the number of test environments.

[0135] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.

[0136] The device for calculating test resources provided in this embodiment realizes the calculation of the number of test environments required to execute the test case through the first acquisition module, the second acquisition module, the merging module, and the third acquisition module as modules. In the device, the execution time of each first test task and the execution time of each second test task are both less than or equal to the preset duration; in addition, considering that the test cases share the same test background and the same test environment, the minimum test environment resources required to complete the execution of the test case within the preset duration are calculated, which reduces the waste of resources and achieves the execution efficiency expected by the user.

[0137] Figure 6 This is a structural diagram of an electronic device provided in another embodiment of the present application. This embodiment is based on the hardware perspective, such as Figure 6 As shown, the electronic equipment includes:

[0138] A memory 20, used for storing computer programs;

[0139] The processor 21 is used to implement the steps of the method for estimating test resources mentioned in the above embodiment when executing a computer program.

[0140] The electronic device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0141] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0142] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the method for calculating test resources disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. Data 203 may include, but is not limited to, the data involved in the method for calculating test resources mentioned above, etc.

[0143] In some embodiments, the electronic device may further include a display screen 22 , an input / output interface 23 , a communication interface 24 , a power source 25 , and a communication bus 26 .

[0144] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.

[0145] The electronic device provided in the embodiment of the present application includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the following method: a method for calculating test resources, with the same effect as above.

[0146] Finally, the present application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.

[0147] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0148] The computer-readable storage medium provided in the present application includes the above-mentioned method for estimating test resources, and the effect is the same as above.

[0149] The above is a detailed introduction to a method, device, electronic device and medium for calculating test resources provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can refer to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

[0150] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A method for estimating test resources, characterized in that: include: Obtain each test module and the test environment that each test case in the test module depends on; Each test module contains one or more test cases, and each test case is executed in the corresponding test environment; Obtaining the first test task corresponding to each of the test modules when relying on each test environment according to the first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each of the first test tasks is less than or equal to the preset time, and the test background is extracted from the general test configuration required by the test case; The test cases in the first test task that depend on the same test environment are merged according to a second preset rule to obtain a second test task; wherein the second preset rule is that the execution time of each of the second test tasks is less than or equal to the preset duration; when obtaining the second test task, there is a switching time of the test cases, and according to the total time of the current test case and the next test case to be merged and the relationship between the sum of the test case switching time and the preset duration, it is determined whether to merge the next test case to be merged into the current second test task; Obtaining the number of the test cases in the first test task that have not been merged and the number of the second test tasks; The sum of the number of the test cases in the first test task that has not been merged and the number of the second test tasks is used as the number of test environments required to execute the test cases so as to perform resource allocation according to the number of the test environments.

2. The method for estimating test resources according to claim 1, characterized in that: The obtaining of the first test task corresponding to each of the test modules when depending on each test environment includes: Extracting each of the test cases of the current test module, the test environment on which each of the test cases depends, and the time taken to execute each of the test cases; When the sum of the total time consumption of the current test case in the current test case set and the time consumption of the test case to be added to the test case set next time is less than or equal to the preset time length, adding the test case to be added next time to the current test case set; Otherwise, stop adding the test case to be added next time to the current test case set, and create a new test case set so as to add the test case to be added next time to the test case set, until there is no test case to be added next time; Each of the test case sets is used as the first test task corresponding to the current test module when it depends on each of the test environments, and the steps of extracting each of the test cases of the current test module, the test environment that each of the test cases depends on, and the time-consuming steps of executing each of the test cases are returned.

3. The method for estimating test resources according to claim 2, characterized in that: Acquiring the test case to be added to the test case set next time includes: sorting the test cases to be added according to the test environment on which the test cases depend and the time taken to execute the test cases; The test cases that take the longest time are selected one by one as the test cases to be added to the test case set next time.

4. The method for estimating test resources according to any one of claims 1 to 3, characterized in that: The merging of the test cases in the first test task that depend on the same test environment to obtain a second test task includes: Obtaining the test cases in the first test task that depend on the same current test environment and the test case switching time; In the case where the sum of the total time consumed by the current test case and the test case to be merged next time and the test case switching time is less than or equal to the preset time length, merging the test case to be merged next time into the current second test task; Otherwise, stop merging the test case to be merged next time into the current second test task, and create a new second test task until there is no test case to be merged next time; Return to the step of obtaining the test cases in the first test task that depend on the same current test environment and the test case switching time.

5. The method for estimating test resources according to claim 4, characterized in that: Obtaining the test cases to be merged next time includes: sorting the test cases according to the time consumption of the test cases; The test cases with the shortest time consumption are selected one by one as the test cases to be merged next time.

6. The method for estimating test resources according to claim 5, characterized in that: The time taken to execute the first test task is less than or equal to the difference between the preset time and the time taken to prepare the test environment and the time taken to prepare and remove the test background in the first test task; The time taken to execute the second test task is less than or equal to the difference between the preset time and the test environment preparation time, the test background preparation and removal time, and the test case switching time within the second test task.

7. The method for estimating test resources according to claim 1, characterized in that: Before obtaining the first test task corresponding to each of the test modules when depending on each test environment, the method further includes: Obtain the test cases in each of the test modules that take longer than the preset time; Eliminate the test case.

8. A device for estimating test resources, characterized in that: include: A first acquisition module is used to acquire each test module and the test environment on which each test case in the test module depends; Each test module contains one or more test cases, and each test case is executed in the corresponding test environment; A second acquisition module is used to acquire the first test tasks corresponding to each of the test modules when relying on each test environment according to a first preset rule; wherein the first preset rule is that the same first test task shares the same test background, and the execution time of each of the first test tasks is less than or equal to a preset time, and the test background is extracted from the general test configuration required by the test case; A merging module, used for merging the test cases in the first test task that depend on the same test environment according to a second preset rule so as to obtain a second test task; wherein the second preset rule is that the execution time of each of the second test tasks is less than or equal to the preset duration; when obtaining the second test task, there is a switching time of the test cases, and according to the total time of the current test case and the next test case to be merged and the relationship between the sum of the test case switching time and the preset duration, it is determined whether to merge the next test case to be merged into the current second test task; A third acquisition module, used to acquire the number of the test cases in the first test task that have not been merged and the number of the second test tasks; As a module, it is used to use the sum of the number of the test cases in the first test task that has not been merged and the number of the second test tasks as the number of test environments required to execute the test cases so as to allocate resources according to the number of test environments.

9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for estimating test resources as claimed in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for estimating test resources according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Automatic test case processing method and device, server and storage medium

    CN111897722A

  • Dynamic allocation method and device, storage medium and electronic equipment

    CN114185763A