Method and device for determining target thread, storage medium and electronic device
By classifying and calculating the test case set, the number of threads can be reasonably determined, thus solving the problem of inappropriate resource consumption in the existing technology and improving the running efficiency of test cases.
Patent Information
- Application Number
- CN202411864596.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2044-12-16
AI Technical Summary
Existing technologies have the problem of not being able to reasonably determine the number of threads, leading to inappropriate resource consumption.
By classifying the test class files in the test case set, the predicted runtime is calculated based on the runtime and thread range of the test cases included in each test class file set, and the target thread is determined based on the target predicted runtime.
This approach allows for the reasonable determination of the number of threads, reducing resource consumption and improving the efficiency of test case execution.
Smart Images

Figure CN119807047B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the computer field, and in particular, to a method and apparatus for determining a target thread, a storage medium, and an electronic device. BACKGROUND
[0002] Test Next Generation (TestNG) provides rich annotations, powerful dependency management and flexible configuration. Through different listeners, test cases in a test case set are assisted in testing, and for different test case sets, specific environments for running test class files in the test case set, the number of threads, and other test information can be set, but there is a problem of being unable to reasonably determine the number of threads in specific test running. SUMMARY
[0003] Embodiments of the present application provide a method and apparatus for determining a target thread, a storage medium, and an electronic device, to at least solve the problem of being unable to reasonably determine the number of threads in related technologies.
[0004] According to an embodiment of the present application, a method for determining a target thread is provided, the method comprising: performing a classification operation on N test class files in a test case set to obtain M test class file sets, wherein one test class file set belongs to one test environment, the test environment is an environment for testing test cases in the test case set, each test class file includes at least one test case, N is a natural number greater than 1, M is a natural number less than or equal to N, or equal to 1; determining a first thread interval required for running test cases included in each test class file set based on the number of test class files included in each test class file set, wherein the first thread interval is used to represent the number of threads required for running the test cases; calculating a predicted running time of each test class file set based on the running time of test cases included in each test class file set and the first thread interval, to obtain M predicted running times, wherein the running time includes the debugging time of each test step in the test cases; and calculating a target thread required for running test cases included in a target test class file set based on a target predicted running time and the running time of test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is the longest time among the M predicted running times.
[0005] In an example embodiment, before the classification operation is performed on the N test class files in the test case set to obtain the M test class file sets, the method further comprises: identifying, by a test environment listener, a test environment annotation in the N test class files, to obtain N test environments of the N test class files, wherein the test environment listener is set in the test class files, and the test environment annotation is used to describe an environment for testing the test cases in the test class files.
[0006] In an example embodiment, based on the running time of the test cases included in each of the test class file sets and the first thread interval, the predicted running time of each of the test class file sets is calculated to obtain the M predicted running times, which comprises: for each of the test class file sets, the predicted running time is calculated by the following steps to obtain the M predicted running times: debugging the test cases; obtaining, by a running time listener, a debugging time of each test step in the test cases in the process of debugging the test cases, wherein one test case includes a plurality of test steps, and the running time listener is set in the test case; determining a running time weight of the test case based on the debugging time of each test step in the test case and time weight information, wherein the time weight information is used to describe a mapping relationship between the debugging time and the time weight; adding the running time weight to a weight annotation of the test case, wherein the weight annotation is used to describe the time weight information in debugging the test case; and calculating the predicted running time of each of the test class file sets based on the running time weight of the test cases included in the test class file set and the first thread interval.
[0007] In an example embodiment, based on the running time weight of the test cases included in each of the test class file sets and the first thread interval, the predicted running time of each of the test class file sets is calculated, which comprises: identifying, by a weight listener, a weight annotation of the test case to obtain the running time weight of the test case, wherein the weight listener is set in the test case; calculating a first running time weight of the test class file, wherein the first running time weight is a sum value of the running time weights of all the test cases included in the test class file; calculating a second running time weight of the test class file set, wherein the second running time weight is a sum value of the first running time weights of all the test class files included in the test class file set; and calculating a ratio of the second time weight of the test class file set to the number of threads in the first thread interval to obtain the M predicted running times.
[0008] In an example embodiment, the target thread required for running the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set is calculated by: calculating a target second time weight of the target test class file set, wherein the target second time weight is a weight among M second time weights; and determining a ratio between the target second time weight and the target predicted running time as the target thread.
[0009] In an example embodiment, after the target thread required for running the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set is calculated, the method further includes: running the test cases included in the target test class file set based on the target thread to obtain a running result, wherein the running result includes running information of the test cases; and updating the running time weight included in the weight annotation of the test cases based on the running information included in the running result.
[0010] In an example embodiment, the running time weight of the test case is determined based on the debugging time and time weight information of each test step in the test case by: obtaining the time weight of the debugging time of each test step from the time weight information to obtain a plurality of time weights; and performing a sum operation on the plurality of time weights to obtain the running time weight of the test case.
[0011] According to another embodiment of the present application, a device for determining a target thread is provided. The device comprises: a first execution module configured to perform a classification operation on N test class files in a test case set to obtain M test class file sets, wherein each of the test class file sets belongs to a test environment, the test environment is an environment for testing test cases in the test case set, each of the test class files includes at least one test case, N is a natural number greater than 1, and M is a natural number less than or equal to N or equal to 1; a first determination module configured to determine a first thread interval required for running test cases included in each of the test class file sets based on a number of the test class files included in each of the test class file sets, wherein the first thread interval is used to represent a number of threads required for running the test cases; a first calculation module configured to calculate a predicted running time of each of the test class file sets based on a running time of the test cases included in each of the test class file sets and the first thread interval, and obtain M predicted running times; and a second calculation module configured to calculate a target thread required for running test cases included in a target test class file set based on a target predicted running time and a running time of the test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is a longest time among the M predicted running times.
[0012] In an example embodiment, the device further comprises: a first acquisition module configured to, before performing the classification operation on the N test class files in the test case set to obtain the M test class file sets, identify test environment annotations in the N test class files through a test environment listener, and acquire N test environments of the N test class files, wherein the test environment listener is arranged in the test class file, and the test environment annotation is used to describe an environment for testing the test cases in the test class file.
[0013] In an example embodiment, the first calculating module comprises: a first calculating submodule for calculating the predicted running time of each test class file set by the following steps: a first debugging unit for debugging the test case; obtaining the debugging time of each test step in the test case in the process of debugging the test case through a running time listener, wherein one test case comprises a plurality of test steps, and the running time listener is set in the test case; a first determining unit for determining the running time weight of the test case based on the debugging time of each test step in the test case and time weight information, wherein the time weight information is used to describe the mapping relationship between the debugging time and the time weight; a first adding unit for adding the running time weight to the weight annotation of the test case, wherein the weight annotation is used to describe the time weight information in the debugging of the test case; and a first calculating unit for calculating the predicted running time of each test class file set based on the running time weight of the test case included in the test class file set and the first thread interval.
[0014] In an example embodiment, the first calculating unit comprises: a first obtaining submodule for identifying the weight annotation of the test case by using a weight listener to obtain the running time weight of the test case, wherein the weight listener is set in the test case; a first calculating submodule for calculating the first running time weight of the test class file, wherein the first running time weight is the sum of the running time weights of all test cases included in the test class file; a second calculating submodule for calculating the second running time weight of the test class file set, wherein the second running time weight is the sum of the first running time weights of all test class files included in the test class file set; and a third calculating submodule for calculating the ratio of the second time weight of the test class file set to the number of threads in the first thread interval to obtain M predicted running times.
[0015] In an example embodiment, the second calculating module comprises: a second calculating submodule for calculating the target second time weight of the target test class file set, wherein the target second time weight is a weight in the M second time weights; a first determining submodule for determining the ratio between the target second time weight and the target predicted running time as the target thread.
[0016] In an example embodiment, the apparatus further includes a first running module configured to, after calculating the target thread required for running the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set, run the test cases included in the target test class file set based on the target thread to obtain a running result, wherein the running result includes running information of the test cases.
[0017] In an example embodiment, the first determining unit includes a first obtaining sub-unit configured to obtain the time weight of the debugging time of each test step from the time weight information to obtain a plurality of time weights, and a first executing sub-unit configured to perform a sum operation on the plurality of time weights to obtain the running time weight of the test case.
[0018] According to yet another embodiment of the present application, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program is configured to perform the steps in any of the method embodiments when executed.
[0019] According to yet another embodiment of the present application, an electronic device is provided, which includes a memory and a processor. The memory stores a computer program, and the processor is configured to execute the computer program to perform the steps in any of the method embodiments.
[0020] According to yet another embodiment of the present application, a computer program product is provided, which includes a computer program. The computer program is executed by a processor to perform the steps in any of the method embodiments.
[0021] According to the present application, the test class files in the test case set are classified based on the test environment to obtain a test class file set, the predicted running time of each test class file set is calculated based on the running time of the test cases included in each test class file set and the first thread interval, the target predicted running time with the longest time is determined from the plurality of predicted running times, and the target thread is determined according to the target predicted running time and the running time of the test cases. Since the present application can calculate the predicted running time of the test class file set according to the test environment type and the test environment resource, and reasonably determine the number of threads started for running the test cases, the problem that the number of threads cannot be reasonably determined in the related art can be solved, and the effects of reasonably starting threads and reducing resource consumption are achieved. BRIEF DESCRIPTION OF DRAWINGS
[0022] Figure 1is a hardware structure block diagram of a server device of a method for determining a target thread according to an embodiment of the present application;
[0023] Figure 2 is a flow chart of a method for determining a target thread according to an embodiment of the present application;
[0024] Figure 3 is a flow chart of a method for determining a target thread according to an embodiment of the present application Figure 1 ;
[0025] Figure 4 is a flow chart of a method for determining a target thread according to an embodiment of the present application Figure 2 ;
[0026] Figure 5 is a structure block diagram of an apparatus for determining a target thread according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] Hereinafter, the embodiments of the present application will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0028] It should be noted that the terms “first”, “second”, and the like in the specification and claims of the present application and the above-described accompanying drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence.
[0029] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing apparatus. Taking an example of running on a server device, Figure 1 is a hardware structure block diagram of a server device of a method for determining a target thread according to an embodiment of the present application. As Figure 1 indicated, the server device can include one or more (only one is shown in Figure 1 ) processor 102 (the processor 102 can include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned server device can further include a transmission device 106 for communication function and an input and output device 108. Those skilled in the art can understand that Figure 1 the structure shown is only schematic, which does not limit the structure of the above-mentioned server device. For example, the server device can further include more or less components than those shown in Figure 1 , or have a different configuration from that shown in Figure 1 .
[0030] The memory 104 can be used to store computer programs, such as software programs of application software and modules, for example, a computer program corresponding to the method for determining a target thread in the embodiments of the present application. The processor 102 performs various functional applications and data processing, that is, implements the above method, by running the computer program stored in the memory 104. The memory 104 can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include a memory remotely arranged with respect to the processor 102, which can be connected to a server device through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0031] The transmission device 106 is used to receive or send data via a network. The specific examples of the above network can include a wireless network provided by a communication provider of a server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC) which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, RF) module which is used to communicate with the Internet in a wireless manner.
[0032] In the embodiments, a method for determining a target thread is provided, Figure 2 The flow chart of the method for determining a target thread according to the embodiments of the present application is shown in FIG. 2, which includes the following steps: Figure 2 The flow chart of the method for determining a target thread according to the embodiments of the present application is shown in FIG. 2, which includes the following steps:
[0033] In step S202, a classification operation is performed on N test class files in a test case set to obtain M test class file sets, wherein one test class file set belongs to one test environment, the test environment is an environment for testing a test case in the test case set, each test class file includes at least one test case, N is a natural number greater than 1, and M is a natural number less than or equal to N or equal to 1.
[0034] Optionally, the test environment includes but is not limited to physical machine testing, virtual machine testing, and multi-node testing, wherein the physical machine testing is testing a test case on a real hardware device, the virtual machine testing is testing in a virtual machine environment simulated by software and having complete hardware system functions and running on a physical machine, and the multi-node testing is testing simultaneously on multiple computing nodes, which can be physical machines, virtual machines, or containers, etc.
[0035] In step S204, a first thread interval required for running test cases included in each test class file set is determined based on the number of test class files included in each test class file set, wherein the first thread interval is used to represent the number of threads required for running the test cases.
[0036] Optionally, the minimum value of the first thread interval is 1, and the maximum value is the total number of test class files in the test class file set. Assuming that the test class file set A includes 10 test class files, the first thread interval of the test class file set A is [1, 10], which represents that when running the test cases of the test class files in the test class file set A, a minimum of 1 thread and a maximum of 10 threads can be started. The test class file set B includes 5 test class files, and the first thread interval of the test class file set B is [1, 5], which represents that when running the test cases of the test class files in the test class file set B, a minimum of 1 thread and a maximum of 5 threads can be started.
[0037] In step S206, the predicted running time of each test class file set is calculated based on the running time of the test cases included in each test class file set and the first thread interval, and M predicted running times are obtained, wherein the running time includes the debugging time of each test step in the test case.
[0038] Optionally, the running time is determined during the process of writing and debugging the test case, and includes the debugging time of each test step in the test case. Assuming that the test case A includes 4 test steps, the debugging time required for debugging the test step 1 is 8 minutes, the debugging time required for debugging the test step 2 is 2 minutes, the debugging time required for debugging the test step 3 is 15 minutes, and the debugging time required for debugging the test step 4 is 25 minutes, then the running time of the test case A is: 8 minutes, 2 minutes, 15 minutes, and 25 minutes. Assuming that the test case B includes 3 test steps, the debugging time required for debugging the test step 1 is 3 minutes, the debugging time required for debugging the test step 2 is 4 minutes, and the debugging time required for debugging the test step 3 is 5 minutes, then the running time of the test case A is: 3 minutes, 4 minutes, and 5 minutes.
[0039] In step S208, a target thread required for running test cases included in a target test class file set is calculated according to a target predicted running time and the running time of the test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is the longest time among the M predicted running times.
[0040] Optionally, assuming that the predicted running time of the test class file set A is [39, 78] minutes, the predicted running time of the test class file set B is [30, 78] minutes, and the predicted running time of the test class file set C is [39, 88] minutes, the target predicted running time is 88 minutes.
[0041] Optionally, as shown in FIG. 1, the method comprises the following steps: Figure 3
[0042] S302, start.
[0043] S304, assuming that the test case set comprises 7 test class files: test class file A, test class file B, test class file C, test class file D, test class file E, test class file F, and test class file G, wherein the test environment of the test class file A, the test class file B, and the test class file C is physical machine testing, the test environment of the test class file D and the test class file E is virtual machine testing, and the test environment of the test class file F and the test class file G is multi-node testing.
[0044] S306, classifying the 7 test class files based on the test environment, wherein test environment 1 physical machine testing-test class file set A comprises 3 test class files: test class file A, test class file B, and test class file C; test environment 2 virtual machine testing-test class file set B comprises 2 test class files: test class file D and test class file E; and test environment 3 multi-node testing-test class file set C comprises 2 test class files: test class file F and test class file G.
[0045] S308, calculating the second time weight.
[0046] S310, calculating the predicted running time 1 of the test class file set A, the predicted running time 2 of the test class file set B, and the predicted running time 3 of the test class file set C.
[0047] S312, obtaining the target predicted running time with the longest time from the 3 predicted running times.
[0048] S314, distributing the target thread number 1 of the test class file set A, the target thread number 2 of the test class file set B, and the target thread number 3 of the test class file set C based on the target predicted running time.
[0049] S316, end.
[0050] The execution subject of the above steps in the embodiment can be a terminal, a server, a specific processor arranged in the terminal or the server, or a processor or processing device arranged independently of the terminal or the server, but is not limited thereto.
[0051] By the above steps, the test class file set in the test case set is classified based on the test environment, and the test class file set is obtained; the predicted running time of each test class file set is calculated based on the running time of the test case included in each test class file set and the first thread interval; the target predicted running time with the longest time is determined from the plurality of predicted running times, and the target thread is determined according to the target predicted running time and the running time of the test case. Since the present application can calculate the predicted running time of the test class file set according to the test environment type and the test environment resource, and reasonably determine the number of threads started to run the test case, the problem that the number of threads cannot be reasonably determined in the related art can be solved, and the effects of reasonably starting threads and reducing resource consumption are achieved.
[0052] In one example embodiment, before the classification operation is performed on the N test class files in the test case set to obtain the M test class file sets, the method further includes: identifying the test environment annotation in the N test class files by a test environment listener, and obtaining the N test environments of the N test class files, wherein the test environment listener is set in the test class file, and the test environment annotation is used to describe the environment for testing the test case in the test class file.
[0053] Optionally, the test environment for the test case in the test class file is described by, for example, using the @Test annotation, and the test environment annotation is listened to by using the TestNG listener. The TestNG listener identifies the @Test annotation of the test class file A to obtain that the test environment is a physical machine test, the TestNG listener identifies the @Test annotation of the test class file B to obtain that the test environment is a physical machine test, the TestNG listener identifies the @Test annotation of the test class file C to obtain that the test environment is a virtual machine test, the TestNG listener identifies the @Test annotation of the test class file D to obtain that the test environment is a virtual machine test, and the TestNG listener identifies the @Test annotation of the test class file E to obtain that the test environment is a multi-node test. This embodiment identifies the test environment annotation in the test file by the test environment listener, and achieves the purpose of accurately and efficiently obtaining the test environment of the test class file, so as to perform the classification operation on the test class file.
[0054] In an example embodiment, the predicted running time of each of the above-mentioned test class file set is calculated based on the running time of the test case included in each of the above-mentioned test class file set and the above-mentioned first thread interval, and M predicted running times are obtained, including: for each of the above-mentioned test class file set, the predicted running time is calculated by the following steps to obtain M predicted running times: debugging the test case; obtaining the debugging time of each test step in the test case in the process of debugging the test case through a running time listener, wherein one test case includes a plurality of test steps, and the running time listener is set in the test case; determining the running time weight of the test case based on the debugging time of each test step in the test case and time weight information, wherein the time weight information is used to describe the mapping relationship between the debugging time and the time weight; adding the running time weight to the weight annotation of the test case, wherein the weight annotation is used to describe the time weight information in debugging the test case; and calculating the predicted running time of each of the test class file set based on the running time weight of the test case included in the test class file set and the first thread interval.
[0055] Optionally, the time weight information in debugging the test case is described by, for example, using the @Test annotation, the test case is monitored by using the TestNG listener, the running time weight is obtained by using the sum value calculation method, and the time weight information is as shown in Table 1. Test case A includes four test steps, the running time required for debugging test step 1 is 8 minutes, the corresponding time weight is 3, the running time required for debugging test step 2 is 2 minutes, the corresponding time weight is 2, the running time required for debugging test step 3 is 15 minutes, the corresponding time weight is 4, and the running time required for debugging test step 4 is 25 minutes, the corresponding time weight is 5, so the running time weight of test case A is 3+2+4+5=14, and the @Test annotation of test case A records the running time weight 14. Test case B includes three test steps, the running time required for debugging test step 1 is 3 minutes, the corresponding time weight is 2, the running time required for debugging test step 2 is 4 minutes, the corresponding time weight is 2, the running time required for debugging test step 3 is 5 minutes, the corresponding time weight is 2, so the running time weight of test case B is 2+2+2=6, and the @Test annotation of test case B records the running time weight 6. In this embodiment, the debugging time of each test step in the test case and the time weight information are obtained, the running time weight of the test case is determined, and the purpose of setting a high weight for a test case with high time consumption and complexity is achieved.
[0056] Table 1:
[0057]
[0058] In one example embodiment, the predicted running time of each of the test class file set is calculated based on the running time weight of the test cases included in the test class file set and the first thread interval, including: identifying the weight annotation of the test case by using a weight listener to obtain the running time weight of the test case, wherein the weight listener is set in the test case; calculating the first running time weight of the test class file, wherein the first running time weight is the sum of the running time weights of all test cases included in the test class file; calculating the second running time weight of the test class file set, wherein the second running time weight is the sum of the first running time weights of all test class files included in the test class file set; calculating the ratio of the second time weight of the test class file set to the number of threads in the first thread interval, obtaining M predicted running times.
[0059] Optionally, the running time weight of the test case is obtained by identifying the @Test annotation of the test case by using the TestNG listener, which supports both single-class test environment test cases and multi-class test environment test cases. For example, the test class file set A includes two test class files: test class file A and test class file B, the test class file A includes two test cases: test case A and test case B, the test class file B includes three test cases: test case C, test case D and test case E, and the first thread interval is [1, 2]. The TestNG listener identifies the running time weight 14 recorded in the @Test annotation of test case A, the running time weight 6 recorded in the @Test annotation of test case B, and obtains the first running time weight 20 (6+14=20) of the test class file A, the TestNG listener identifies the running time weight 10 recorded in the @Test annotation of test case C, the running time weight 16 recorded in the @Test annotation of test case D, and the running time weight 26 recorded in the @Test annotation of test case E, and obtains the first running time weight 52 (10+16+26=52) of the test class file B. The second running time weight of the test class file set A is 78 (26+52=78), and the predicted running time is [39, 78] (78 / [1, 2]= [39, 78]). This embodiment realizes the purpose of accurately predicting the running time of the test class file set by calculating the ratio of the second time weight of the test class file set to the number of threads in the first thread interval.
[0060] In an example embodiment, the target thread required to run the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set comprises: calculating a target second time weight of the target test class file set, wherein the target second time weight is a weight of the M second time weights; determining the ratio between the target second time weight and the target predicted running time as the target thread.
[0061] Optionally, the target test class file set is any one of the M test class file sets, and the target second time weight is calculated in the same way as the second running time weight, which will not be described here. The target predicted running time is the longest time among the M predicted running times. For example, the predicted running time of test class file set A is [39, 78] minutes, the predicted running time of test class file set B is [30, 78] minutes, and the predicted running time of test class file set C is [39, 48] minutes. The target predicted running time is 78 minutes. Assuming that the second running time weight of test class file set A is 78, the second running time weight of test class file set B is 39, and the second running time weight of test class file set C is 40, the target thread of test class file set A is 1, the target thread of test class file set B is 2, and the target thread of test class file set C is 40. This embodiment calculates the minimum number of threads required to start the longest running time test class file set, which achieves the purpose of reducing the consumption of test environment resources by test cases in other test environment types.
[0062] In an example embodiment, after calculating the target thread required to run the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set, the method further comprises: running the test cases included in the target test class file set based on the target thread to obtain a running result, wherein the running result includes the running information of the test cases; and updating the running time weight included in the weight annotation of the test cases based on the running information included in the running result.
[0063] Optionally, the running information is used to describe information of a running failed test case and information of a running successful test case. For example, the running result of the test class file set A includes: a running failed test case A, a test case B, and a running successful test case C, a test case D, and a test case E. The running time weight of the test case A and the test case B is increased. After the subsequent test case A and the test case B are successfully run again, the running time weight of the test case A and the test case B is reduced again. In the embodiment, the running time weight of the test case is updated based on the running result, so that the loss of the test environment and resources caused by the failed test case is reduced, the subsequent test case class running is affected, and the purpose of improving the test case class pass rate is achieved.
[0064] In one example embodiment, based on the debugging time and the time weight information of each test step in the test case, the running time weight of the test case is determined, including: obtaining the time weight of the debugging time of each test step from the time weight information, to obtain a plurality of time weights; performing a sum operation on the plurality of time weights to obtain the running time weight of the test case.
[0065] Optionally, the time weight information is as shown in Table 1. The test case A includes 4 test steps. The running time required for debugging the test step 1 is 8 minutes, and the corresponding time weight is 3. The running time required for debugging the test step 2 is 2 minutes, and the corresponding time weight is 2. The running time required for debugging the test step 3 is 15 minutes, and the corresponding time weight is 4. The running time required for debugging the test step 4 is 25 minutes, and the corresponding time weight is 5. Therefore, the running time weight of the test case A is 3+2+4+5=14. The test case B includes 3 test steps. The running time required for debugging the test step 1 is 3 minutes, and the corresponding time weight is 2. The running time required for debugging the test step 2 is 4 minutes, and the corresponding time weight is 2. The running time required for debugging the test step 3 is 5 minutes, and the corresponding time weight is 2. Therefore, the running time weight of the test case B is 2+2+2=6. In the embodiment, the debugging time and the time weight information of each test step in the test case are obtained to determine the running time weight of the test case, so that the purpose of setting a high weight for a test case with high time consumption and complexity is achieved.
[0066] The application will be described in detail below with reference to specific embodiments:
[0067] In the specific embodiment, Figure 4 is a flow of a method for determining a target thread according to the specific embodiment of the application Figure 2 As shown in the figure, Figure 4 specifically includes the following steps:
[0068] S402, start to determine the target thread of running the test cases in the test case set A, wherein the test case set A includes a test class file A, a test class file B, a test class file C and a test class file D, the test class file A includes two test cases: test case A and test case B, the test class file B includes three test cases: test case C, test case D and test case E, the test class file C includes two test cases: test case F and test case G, and the test class file D includes two test cases: test case H and test case I;
[0069] S404, the classification device uses a TestNG listener to listen to the @Test annotation and obtain the test environment of the test cases in the test class files. The TestNG listener identifies the @Test annotation of the test class file A to obtain the test environment as physical machine test, identifies the @Test annotation of the test class file B to obtain the test environment as physical machine test, identifies the @Test annotation of the test class file C to obtain the test environment as multi-node test, and identifies the @Test annotation of the test class file D to obtain the test environment as multi-node test.
[0070] The classification device classifies the test class files A, B, C and D in the test case set A based on the obtained test environment, and obtains a test class file set A and a test class file set B, wherein the test class file set A includes two test class files: the test class file A and the test class file B, and the test class file set B includes two test class files: the test class file C and the test class file D.
[0071] S406, the weight configuration device records the running time weight of the test case in the process of debugging the test case. Test case A includes 4 test steps, the running time required for debugging test step 1 is 8 minutes, the corresponding time weight is 3, the running time required for debugging test step 2 is 2 minutes, the corresponding time weight is 2, the running time required for debugging test step 3 is 15 minutes, the corresponding time weight is 4, and the running time required for debugging test step 4 is 25 minutes, the corresponding time weight is 5, then the running time weight of test case A is 3+2+4+5=14, and the running time weight 14 is recorded in the @Test annotation of test case A. Test case B includes 3 test steps, the running time required for debugging test step 1 is 3 minutes, the corresponding time weight is 2, the running time required for debugging test step 2 is 4 minutes, the corresponding time weight is 2, the running time required for debugging test step 3 is 5 minutes, the corresponding time weight is 2, then the running time weight of test case B is 2+2+2=6, and the running time weight 6 is recorded in the @Test annotation of test case B. Similarly, the weight configuration device determines that the running time weight of test case C is 8, the running time weight of test case D is 10, the running time weight of test case E is 6, the running time weight of test case F is 8, the running time weight of test case G is 12, the running time weight of test case H is 12, and the running time weight of test case I is 14.
[0072] The weight configuration device calculates the first running time weight 20 of the test class file A based on the running time weights of test case A and test case B; calculates the first running time weight 24 of the test class file B based on the running time weights of test case C, test case D and test case E; calculates the first running time weight 20 of the test class file C based on the running time weights of test case F and test case G; and calculates the first running time weight 26 of the test class file D based on the running time weights of test case H and test case I.
[0073] The weight configuration device calculates the second running time weight 44 of the test class file set A based on the first running time weight 20 of the test class file A and the first running time weight 24 of the test class file B; and calculates the second running time weight 46 of the test class file set B based on the first running time weight 20 of the test class file C and the first running time weight 26 of the test class file D.
[0074] S408, the computing device determines that the first thread interval of the test class file set A is [1, 2] and the first thread interval of the test class file set B is [1, 2] based on the number of test class files in the test class file set.
[0075] The second running time weight of the test class file set A is divided by the first thread interval to determine that the predicted running time of the test class file set A is [22, 44], the second running time weight of the test class file set B is divided by the first thread interval to determine that the predicted running time of the test class file set B is [23, 46], and the target predicted running time of the test case set A is determined to be 46;
[0076] The computing device calculates the target thread 1 of the test class file set A and the target thread 1 of the test class file set B based on the ratio of the target predicted running time and the second running time weight;
[0077] S410, the management device assigns a thread tree age to the test cases in the test class file set based on the target thread, and runs the test cases, and feeds back the running result to the weight configuration device, and the weight configuration device updates the test running time weight based on the information of the test cases that fail to run and the information of the test cases that successfully run, for example, the running result includes test case A and test case B that fail to run and test case C, test case D and test case E that successfully run, and the running time weight of test case A and test case B is increased, and the running time weight of test case A and test case B is reduced again after test case A and test case B successfully run again;
[0078] S412, end.
[0079] Through the description of the above implementation, those skilled in the art can clearly understand that the method according to the above embodiment can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases the former is a better implementation. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions for making a terminal device (which can be a mobile phone, computer, server, or network device, etc.) execute the method described in each embodiment of the present application.
[0080] In the present embodiment, a device for determining a target thread is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments, and will not be described again. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware is also possible and contemplated.
[0081] Figure 5 is a structural block diagram of a device for determining a target thread according to an embodiment of the present application, as shown in Figure 5 the device comprises:
[0082] The first execution module 502 is configured to perform a classification operation on N test class files in a test case set to obtain M test class file sets, wherein one test class file set belongs to one test environment, the test environment is an environment for testing test cases in the test case set, each test class file includes at least one test case, N is a natural number greater than 1, and M is a natural number less than or equal to N or equal to 1;
[0083] The first determination module 504 is configured to determine a first thread interval required for running test cases included in each test class file set based on a number of test class files included in the test class file set, wherein the first thread interval is used to represent a number of threads required for running the test cases.
[0084] The first calculation module 506 is configured to calculate a predicted running time of each test class file set based on a running time of test cases included in each test class file set and the first thread interval, to obtain M predicted running times, wherein the running time includes a debugging time of each test step in the test cases.
[0085] The second calculation module 508 is configured to calculate a target thread required for running test cases included in a target test class file set based on a target predicted running time and a running time of test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is a longest time in the M predicted running times.
[0086] In an example embodiment, the apparatus further includes a first acquisition module configured to, before obtaining M test class file sets by performing a classification operation on N test class files in a test case set, identify test environment annotations in the N test class files through a test environment listener to acquire N test environments of the N test class files, wherein the test environment listener is arranged in the test class file, and the test environment annotation is used to describe an environment for testing the test cases in the test class file.
[0087] In an example embodiment, the first calculating module comprises: a first calculating submodule for calculating the predicted running time of each test class file set by the following steps: a first debugging unit for debugging the test case; obtaining the debugging time of each test step in the test case in the process of debugging the test case through a running time listener, wherein one test case comprises a plurality of test steps, and the running time listener is set in the test case; a first determining unit for determining the running time weight of the test case based on the debugging time of each test step in the test case and time weight information, wherein the time weight information is used to describe the mapping relationship between the debugging time and the time weight; a first adding unit for adding the running time weight to the weight annotation of the test case, wherein the weight annotation is used to describe the time weight information in the debugging of the test case; and a first calculating unit for calculating the predicted running time of each test class file set based on the running time weight of the test case included in the test class file set and the first thread interval.
[0088] In an example embodiment, the first calculating unit comprises: a first obtaining submodule for identifying the weight annotation of the test case by using a weight listener to obtain the running time weight of the test case, wherein the weight listener is set in the test case; a first calculating submodule for calculating the first running time weight of the test class file, wherein the first running time weight is the sum of the running time weights of all test cases included in the test class file; a second calculating submodule for calculating the second running time weight of the test class file set, wherein the second running time weight is the sum of the first running time weights of all test class files included in the test class file set; and a third calculating submodule for calculating the ratio of the second time weight of the test class file set to the number of threads in the first thread interval to obtain M predicted running times.
[0089] In an example embodiment, the second calculating module comprises: a second calculating submodule for calculating the target second time weight of the target test class file set, wherein the target second time weight is a weight in the M second time weights; a first determining submodule for determining the ratio between the target second time weight and the target predicted running time as the target thread.
[0090] In an example embodiment, the apparatus further includes: a first running module configured to, after calculating the target thread required for running the test cases included in the target test class file set according to the target prediction running time and the running time of the test cases included in the target test class file set, run the test cases included in the target test class file set based on the target thread to obtain a running result, wherein the running result includes running information of the test cases; and a first updating module configured to update the running time weight included in the weight annotation of the test cases based on the running information included in the running result.
[0091] In an example embodiment, the first determining unit includes: a first obtaining sub-unit configured to obtain the time weight of the debugging time of each test step from the time weight information to obtain a plurality of time weights; and a first executing sub-unit configured to perform a sum operation on the plurality of time weights to obtain the running time weight of the test case.
[0092] It should be noted that each of the above modules can be implemented by software or hardware, and for the latter, the following implementation manners can be used, but are not limited thereto: all of the modules are located in the same processor; or each of the modules is located in a different processor in any combination.
[0093] Embodiments of the present application also provide a computer readable storage medium, which stores a computer program, and the computer program is configured to execute the steps in any of the above method embodiments when running.
[0094] In an example embodiment, the computer readable storage medium can include, but is not limited to: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0095] Embodiments of the present application also provide an electronic device, which includes a memory storing a computer program and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
[0096] In an example embodiment, the electronic device can further include a transmission device connected to the processor and an input and output device connected to the processor.
[0097] The embodiment of the present application further provides a computer program product, which comprises a computer program, and the computer program realizes the steps in any of the method embodiments when executed by a processor.
[0098] The embodiment of the present application further provides another computer program product, which comprises a nonvolatile computer readable storage medium, and the nonvolatile computer readable storage medium stores a computer program, and the computer program realizes the steps in any of the method embodiments when executed by a processor.
[0099] The embodiment of the present application further provides a computer program, which comprises computer instructions stored in a computer readable storage medium; a processor of a computer device reads the computer instructions from the computer readable storage medium, and executes the computer instructions, so that the computer device executes the steps in any of the method embodiments.
[0100] The specific examples in the embodiment can refer to the examples described in the above embodiments and exemplary embodiments, and the embodiment will not be repeated here.
[0101] Obviously, those skilled in the art should understand that the modules or steps of the present application described above can be realized by general computing devices, which can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, which can be realized by program codes executable by computing devices, so that they can be stored in storage devices and executed by computing devices, and in some cases, the steps shown or described can be executed in different order, or they can be manufactured into individual integrated circuit modules, or multiple modules or steps can be manufactured into a single integrated circuit module. Thus, the present application is not limited to any specific combination of hardware and software.
[0102] The above only describes the preferred embodiments of the present application and is not used to limit the present application. Those skilled in the art can make various modifications and changes to the present application. Any modification, equivalent replacement, improvement, etc. within the principles of the present application should be included in the protection scope of the present application.
Claims
1. A method of determining a target thread, the method comprising: The method comprises the following steps: performing a classification operation on N test class files in a test case set to obtain M test class file sets, wherein one of the test class file sets belongs to one test environment, the test environment is an environment for testing test cases in the test case set, each of the test class files comprises at least one test case, N is a natural number greater than 1, and M is a natural number less than or equal to N or equal to 1; determining a first thread interval required for running test cases included in each of the test class file sets based on the number of test class files included in each of the test class file sets, wherein the first thread interval is used to represent the number of threads required for running the test cases; calculating a predicted running time of each of the test class file sets based on the running time of the test cases included in each of the test class file sets and the first thread interval, to obtain M predicted running times, wherein the running time is determined during the process of writing the test cases and comprises the debugging time of each test step in the test cases; calculating a target thread required for running test cases included in a target test class file set based on a target predicted running time and the running time of the test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is the longest time among the M predicted running times.
2. The method of claim 1, wherein, Before performing the classification operation on the N test class files in the test case set to obtain the M test class file sets, the method further comprises the following steps: recognizing test environment annotations in the N test class files through a test environment listener to obtain N test environments of the N test class files, wherein the test environment listener is arranged in the test class files, and the test environment annotations are used to describe the environment for testing the test cases in the test class files.
3. The method of claim 1, wherein, The calculating of the predicted running time of each of the test class file sets based on the running time of the test cases included in each of the test class file sets and the first thread interval to obtain M predicted running times comprises the following steps: for each of the test class file sets, the predicted running time is calculated through the following steps to obtain M predicted running times: debugging the test cases; obtaining the debugging time of each test step in the test cases during the process of debugging the test cases through a running time listener, wherein one test case comprises a plurality of test steps, and the running time listener is arranged in the test case; determining a running time weight of the test case based on the debugging time of each test step in the test case and time weight information, wherein the time weight information is used to describe the mapping relationship between the debugging time and the time weight; adding the running time weight to a weight annotation of the test case, wherein the weight annotation is used to describe the time weight information in the process of debugging the test case. Calculate the predicted running time of each test class file set based on the running time weight of the test cases included in the test class file set and the first thread interval.
4. The method of claim 3, wherein, Calculate the predicted running time of each test class file set based on the running time weight of the test cases included in the test class file set and the first thread interval, comprising: Identify the weight annotation of the test case using a weight listener to obtain the running time weight of the test case, wherein the weight listener is set in the test case; Calculate the first running time weight of the test class file, wherein the first running time weight is the sum of the running time weights of all test cases included in the test class file; Calculate the second running time weight of the test class file set, wherein the second running time weight is the sum of the first running time weights of all test class files included in the test class file set; Calculate the ratio of the second running time weight of the test class file set to the number of threads in the first thread interval to obtain M predicted running times.
5. The method of claim 4, wherein, According to the target predicted running time and the running time of the test cases included in the target test class file set, calculate the target thread required to run the test cases included in the target test class file set, comprising: Calculate the target second time weight of the target test class file set, wherein the target second time weight is the weight of the M second running time weights; Determine the ratio between the target second time weight and the target predicted running time as the target thread.
6. The method of claim 3, wherein, After calculating the target thread required to run the test cases included in the target test class file set according to the target predicted running time and the running time of the test cases included in the target test class file set, the method further comprises: Run the test cases included in the target test class file set based on the target thread to obtain a running result, wherein the running result includes running information of the test cases; Update the running time weight included in the weight annotation of the test case based on the running information included in the running result.
7. The method of claim 3, wherein, Determine the running time weight of the test case based on the debugging time and time weight information of each test step in the test case, comprising: Obtain the time weight of the debugging time of each test step from the time weight information to obtain multiple time weights; Perform a sum operation on multiple time weights to obtain the running time weight of the test case.
8. An apparatus for determining a target thread, the apparatus comprising: The device comprises: A first execution module for performing classification operation on N test class files in a test case set to obtain M test class file sets, wherein one test class file set belongs to one test environment, the test environment is an environment for testing test cases in the test case set, each test class file includes at least one test case, N is a natural number greater than 1, and M is a natural number less than or equal to N or equal to 1; The first determination module is configured to determine a first thread interval required for running test cases included in each of the test class file sets based on a number of the test class files included in each of the test class file sets, wherein the first thread interval is used to represent a number of threads required for running the test cases; The first calculation module is configured to calculate a predicted running time of each of the test class file sets based on a running time of the test cases included in each of the test class file sets and the first thread interval, to obtain M predicted running times, wherein the running time is determined in a process of writing the test cases and includes a debugging time of each test step in the test cases; The second calculation module is configured to calculate a target thread required for running test cases included in a target test class file set based on a target predicted running time and a running time of the test cases included in the target test class file set, wherein the target test class file set is any one of the M test class file sets, and the target predicted running time is a longest time among the M predicted running times.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, wherein the computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 7.
10. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to implement the steps of the method in any one of claims 1 to 7.
Citation Information
Patent Citations
Automatic testing method and device
CN113760709A
Retrying failed test cases in software testing using parallel threads
US11720482B1