Method and device for determining target thread, storage medium and electronic equipment
By classifying and determining the thread interval of the test class files in the TestNG test framework, the problem of not being able to reasonably determine the number of threads is solved, and efficient test operation and resource management are achieved.
Patent Information
- Application Number
- CN202411864596.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-12-16
AI Technical Summary
When using the TestNG test framework, the number of threads cannot be reasonably determined, resulting in inefficient test runs.
By classifying the test class files in the test case set, the thread interval required for each test class file set is determined, and the predicted run time is calculated based on the test case run time and thread interval, and the target number is finally determined.
The reasonable determination of the number of threads is achieved, the test operation efficiency is improved, and resource consumption is reduced.
Smart Images

Figure CN119807047A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the computer field, and in particular, to a method and device for determining a target thread, a storage medium, and an electronic device. Background Art
[0002] The next generation test framework (Test Next Generation, referred to as TestNG) provides rich annotations, powerful dependency management and flexible configuration. Through different listeners, auxiliary testing is performed on the test cases in the test case set. For different test case sets, the specific environment, number of threads and other test information for running the test class files in the test case set can be set. However, there is a problem that the number of threads cannot be reasonably determined in the specific test run. Summary of the invention
[0003] The embodiments of the present application provide a method and device for determining a target thread, a storage medium, and an electronic device, so as to at least solve the problem in the related art that the number of threads cannot be reasonably determined.
[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 of the test class file sets belongs to a test environment, the test environment is an environment for testing the test cases in the test case set, each of the test class files includes at least one test case, the N is a natural number greater than 1, and the M is a natural number less than or equal to the N, or equal to 1; based on the number of the test class files included in each of the test class file sets, determining a first thread interval required to run the test cases included in each of the test class file sets, wherein the first thread interval is used Represents the number of threads required to run the above test cases; based on the running time of the test cases included in each of the above test class file sets and the above first thread interval, calculate the predicted running time of each of the above test class file sets to obtain M of the above predicted running times, wherein the above running time includes the debugging time of each test step in the above test case; 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 threads required to run the test cases included in the above target test class file set, wherein the above target test class file set is any test class file set in the M test class file sets, and the above target predicted running time is the longest time among the M predicted running times.
[0005] In an exemplary embodiment, before performing a classification operation on N test class files in a test case set to obtain M test class file sets, the method further includes: identifying the test environment annotations in the N test class files through 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 cases in the test class files.
[0006] In an exemplary embodiment, based on the running time of the test cases included in each of the above-mentioned test class file sets and the above-mentioned first thread interval, the predicted running time of each of the above-mentioned test class file sets is calculated to obtain M of the above-mentioned predicted running times, including: for each of the above-mentioned test class file sets, the above-mentioned predicted running time is calculated through the following steps to obtain M of the above-mentioned predicted running times: debugging the above-mentioned test cases; obtaining the debugging time of each test step in the above-mentioned test case during the debugging of the above-mentioned test case through a running time listener, wherein one of the above-mentioned test cases includes multiple of the above-mentioned test steps, and the above-mentioned running time listener is set in the above-mentioned test case; based on the debugging time and time weight information of each test step in the above-mentioned test case, determining the running time weight of the above-mentioned test case, wherein the above-mentioned time weight information is used to describe the mapping relationship between the above-mentioned debugging time and the time weight; adding the above-mentioned running time weight to the weight annotation of the above-mentioned test case, wherein the above-mentioned weight annotation is used to describe the time weight information in debugging the above-mentioned test case; based on the running time weight of the test case included in the above-mentioned test class file set and the above-mentioned first thread interval, calculating the above-mentioned predicted running time of each of the above-mentioned test class file sets.
[0007] In an exemplary embodiment, based on the runtime weights of the test cases included in the test class file set and the first thread interval, the predicted runtime of each of the test class file sets is calculated, including: using a weight listener to identify the weight annotation of the test case to obtain the runtime weight of the test case, wherein the weight listener is set in the test case; calculating the first runtime weight of the test class file, wherein the first runtime weight is the sum of the runtime weights of all the test cases included in the test class file; calculating the second runtime weight of the test class file set, wherein the second runtime weight is the sum of the first runtime weights of all the 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 to obtain M of the predicted runtimes.
[0008] In an exemplary embodiment, a target thread required to run the test cases included in the target test class file set is calculated based on the target predicted running time and the running time of the test cases included in the target test class file set, including: calculating the target second time weight of the target test class file set, wherein the target second time weight is a weight among the M second time weights; and determining the ratio between the target second time weight and the target predicted running time as the target thread.
[0009] In an exemplary embodiment, after calculating the target thread required to run the test case included in the target test class file set based on the target predicted running time and the running time of the test case included in the target test class file set, the method further includes: running the test case 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 case; and updating the running time weight included in the weight annotation of the test case based on the running information included in the running result.
[0010] In an exemplary embodiment, based on the debugging time and time weight information of each test step in the above test case, the running time weight of the above test case is determined, including: obtaining the time weight of the debugging time of each of the above test steps from the above time weight information to obtain multiple time weights; performing a sum operation on the multiple time weights to obtain the running time weight of the above test case.
[0011] According to another embodiment of the present application, a device for determining a target thread is provided, the device comprising: a first execution module, used to perform 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 a test environment, the test environment is an environment for testing the test cases in the test case set, each of the test class files includes at least one test case, the N is a natural number greater than 1, the M is a natural number less than or equal to the N, or equal to 1; a first determination module, used to determine a first thread interval required to run the test cases included in each of the test class file sets based on the number of the test class files included in each of the test class file sets, wherein the first thread interval is used The first calculation module is used to calculate the predicted running time of each of the above test class file sets based on the running time of the test cases included in each of the above test class file sets and the above first thread interval, so as to obtain the M predicted running times, wherein the above running time includes the debugging time of each test step in the above test case; the second calculation module is used to calculate the target threads required to run the test cases included in the above 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, wherein the above target test class file set is any test class file set in the M test class file sets, and the above target predicted running time is the longest time among the M predicted running times.
[0012] In an exemplary embodiment, the above-mentioned device also includes: a first acquisition module, which is used to perform a classification operation on N test class files in a test case set, and before obtaining M test class file sets, identify the test environment annotations in the N above-mentioned test class files through a test environment listener, and obtain the N above-mentioned test environments of the N above-mentioned test class files, wherein the above-mentioned test environment listener is set in the above-mentioned test class file, and the above-mentioned test environment annotation is used to describe the environment for testing the above-mentioned test cases in the above-mentioned test class files.
[0013] In an exemplary embodiment, the above-mentioned first calculation module includes: a first calculation submodule, which is used to calculate the above-mentioned predicted running time for each of the above-mentioned test class file sets through the following steps to obtain M of the above-mentioned predicted running times: a first debugging unit, which is used to debug the above-mentioned test case; obtaining the debugging time of each test step in the above-mentioned test case during the debugging of the above-mentioned test case through a runtime listener, wherein one of the above-mentioned test cases includes multiple test steps, and the above-mentioned runtime listener is set in the above-mentioned test case; a first determination unit, which is used to determine the runtime weight of the above-mentioned test case based on the debugging time and time weight information of each test step in the above-mentioned test case, wherein the above-mentioned time weight information is used to describe the mapping relationship between the above-mentioned debugging time and the time weight; a first adding unit, which is used to add the above-mentioned runtime weight to the weight annotation of the above-mentioned test case, wherein the above-mentioned weight annotation is used to describe the time weight information in debugging the above-mentioned test case; a first calculation unit, which is used to calculate the above-mentioned predicted running time of each of the above-mentioned test class file sets based on the runtime weight of the test case included in the above-mentioned test class file set and the above-mentioned first thread interval.
[0014] In an exemplary embodiment, the above-mentioned first calculation unit includes: a first acquisition subunit, used to use a weight listener to identify the weight annotation of the above-mentioned test case to obtain the runtime weight of the above-mentioned test case, wherein the above-mentioned weight listener is set in the above-mentioned test case; a first calculation subunit, used to calculate the first runtime weight of the above-mentioned test class file, wherein the above-mentioned first runtime weight is the sum of the runtime weights of all test cases included in the above-mentioned test class file; a second calculation subunit, used to calculate the second runtime weight of the above-mentioned test class file set, wherein the above-mentioned second runtime weight is the sum of the first runtime weights of all test class files included in the above-mentioned test class file set; a third calculation subunit, used to calculate the ratio of the above-mentioned second time weight of the above-mentioned test class file set to the number of threads in the above-mentioned first thread interval, and obtain M of the above-mentioned predicted runtimes.
[0015] In an exemplary embodiment, the above-mentioned second calculation module includes: a second calculation submodule, used to calculate the target second time weight of the above-mentioned target test class file set, wherein the above-mentioned target second time weight is a weight among the M above-mentioned second time weights; a first determination submodule, used to determine the ratio between the above-mentioned target second time weight and the above-mentioned target predicted running time as the above-mentioned target thread.
[0016] In an exemplary embodiment, the above-mentioned device also includes: a first running module, which is used to calculate the target thread required to run the test case included in the target test class file set based on the target predicted running time and the running time of the test case included in the target test class file set, and then run the test case included in the target test class file set based on the above-mentioned target thread to obtain an running result, wherein the above-mentioned running result includes the running information of the above-mentioned test case; a first updating module, which is used to update the running time weight included in the weight annotation of the above-mentioned test case based on the above-mentioned running information included in the above-mentioned running result.
[0017] In an exemplary embodiment, the above-mentioned first determination unit includes: a first acquisition subunit, used to obtain the time weight of the debugging time of each of the above-mentioned test steps from the above-mentioned time weight information to obtain multiple time weights; a first execution subunit, used to perform an addition operation on the multiple above-mentioned time weights to obtain the running time weight of the above-mentioned test case.
[0018] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when running.
[0019] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0020] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0021] Through this application, the test class files in the test case set are classified based on the test environment to obtain the test class file set; based on the running time of the test case included in each test class file set and the first thread interval, the predicted running time of each test class file set is calculated; the target predicted running time with the longest time is determined from multiple 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 this application can calculate the predicted running time of the test class file set according to the test environment type and test environment resources, and reasonably determine the number of threads started by running the test case, it can solve the problem that the number of threads cannot be reasonably determined in the related technology, and achieve the effect of reasonably starting threads and reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1It 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;
[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 This is a process of a method for determining a target thread according to a specific embodiment of the present application. Figure 1 ;
[0025] Figure 4 This is a process of a method for determining a target thread according to a specific embodiment of the present application. Figure 2 ;
[0026] Figure 5 It is a structural block diagram of a device for determining a target thread according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily 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 device. Taking running on a server device as an example, Figure 1 1 is a hardware structure block diagram of a server device of a method for determining a target thread in an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may 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 may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0030] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a method for determining a target thread in an embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to a server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0031] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as 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 (RF) module, which is used to communicate with the Internet wirelessly.
[0032] In this embodiment, a method for determining a target thread is provided. Figure 2 is a flow chart of a method for determining a target thread according to an embodiment of the present application. Figure 2 As shown, the process includes the following steps:
[0033] Step S202, performing a classification operation on N test class files in the 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 the 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;
[0034] Optionally, the test environment includes but is not limited to physical machine testing, virtual machine testing, and multi-node testing, wherein physical machine testing is testing test cases on real hardware devices, virtual machine testing is testing using software-simulated virtual machine environments with complete hardware system functions running on physical machines, and multi-node testing is testing performed simultaneously on multiple computing nodes, which can be physical machines, virtual machines, or containers, etc.
[0035] Step S204, determining a first thread interval required to run the test case 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 to run the test case;
[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 test class file set A includes 10 test class files, the first thread interval of test class file set A is [1,10], which means that when running the test cases of the test class files in test class file set A, at least 1 thread and at most 10 threads can be started. Test class file set B includes 5 test class files, then the first thread interval of test class file set B is [1,5], which means that when running the test cases of the test class files in test class file set B, at least 1 thread and at most 5 threads can be started.
[0037] Step S206, based on the running time of the test case included in each test class file set and the first thread interval, calculate the predicted running time of each test class file set to obtain M predicted running times, wherein the running time includes the debugging time of each test step in the test case;
[0038] Optionally, the running time is determined in the process of writing and debugging test cases, including the debugging time of each test step in the test case. Assuming that test case A includes 4 test steps, the running time required for debugging test step 1 is 8 minutes, the running time required for debugging test step 2 is 2 minutes, the running time required for debugging test step 3 is 15 minutes, and the running time required for debugging test step 4 is 25 minutes, then the running time of test case A is: 8 minutes, 2 minutes, 15 minutes, 25 minutes. Assuming that test case B includes 3 test steps, the running time required for debugging test step 1 is 3 minutes, the running time required for debugging test step 2 is 4 minutes, and the running time required for debugging test step 3 is 5 minutes, then the running time of test case A is: 3 minutes, 4 minutes, 5 minutes.
[0039] Step S208, calculate the target threads 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, wherein the target test class file set is any test class file set among the M test class file sets, and the target predicted running time is the longest time among the M predicted running times.
[0040] Alternatively, assuming that 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, 88] minutes, the target predicted running time is 88 minutes.
[0041] Alternatively, if Figure 3 As shown, the following steps are included:
[0042] S302, start.
[0043] S304, assuming that the test case set includes 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, among which, the test environment of test class file A, test class file B, and test class file C is physical machine testing, the test environment of test class file D and test class file E is virtual machine testing, and the test environment of test class file F and test class file G is multi-node testing.
[0044] S306, classify the above 7 test class files based on the test environment, test environment 1 physical machine test - test class file set A includes 3 test class files: test class file A, test class file B, test class file C; test environment 2 virtual machine test - test class file set B includes 2 test class files: test class file D, test class file E; test environment 3 multi-node test - test class file set C includes 2 test class files: test class file F, test class file G.
[0045] S308: Calculate a 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 longest target predicted running time from the above three predicted running times.
[0048] S314, allocating a target number of threads of 1 for test class file set A, a target number of threads of 2 for test class file set B, and a target number of threads of 3 for test class file set C based on the target predicted running time.
[0049] S316, end.
[0050] In this embodiment, the execution subject of the above steps can be a terminal, a server, a specific processor set in the terminal or server, or a processor or processing device set relatively independently from the terminal or server, but is not limited thereto.
[0051] Through the above steps, the test class files in the test case set are classified based on the test environment to obtain the test class file set; based on the running time of the test cases included in each test class file set and the first thread interval, the predicted running time of each test class file set is calculated; the target predicted running time with the longest time is determined from multiple 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 test environment resources, and reasonably determine the number of threads started by running the test case, it can solve the problem that the number of threads cannot be reasonably determined in the related technology, and achieve the effect of reasonably starting threads and reducing resource consumption.
[0052] In an exemplary embodiment, before performing a classification operation on N test class files in a test case set to obtain M test class file sets, the method further includes: identifying the test environment annotations in the N test class files through 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 cases in the test class files.
[0053] Optionally, for example, the @Test annotation is used to describe the test environment of the above test case in the test class file, and the TestNG listener is used to listen to the test environment annotation. 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 achieves the purpose of accurately and efficiently obtaining the test environment of the test class file by using the test environment listener to identify the test environment annotation in the test file, so as to perform classification operations on the test class file.
[0054] In an exemplary embodiment, based on the running time of the test cases included in each of the above-mentioned test class file sets and the above-mentioned first thread interval, the predicted running time of each of the above-mentioned test class file sets is calculated to obtain M of the above-mentioned predicted running times, including: for each of the above-mentioned test class file sets, the above-mentioned predicted running time is calculated through the following steps to obtain M of the above-mentioned predicted running times: debugging the above-mentioned test cases; obtaining the debugging time of each test step in the above-mentioned test case during the debugging of the above-mentioned test case through a running time listener, wherein one of the above-mentioned test cases includes multiple of the above-mentioned test steps, and the above-mentioned running time listener is set in the above-mentioned test case; based on the debugging time and time weight information of each test step in the above-mentioned test case, determining the running time weight of the above-mentioned test case, wherein the above-mentioned time weight information is used to describe the mapping relationship between the above-mentioned debugging time and the time weight; adding the above-mentioned running time weight to the weight annotation of the above-mentioned test case, wherein the above-mentioned weight annotation is used to describe the time weight information in debugging the above-mentioned test case; based on the running time weight of the test case included in the above-mentioned test class file set and the above-mentioned first thread interval, calculating the above-mentioned predicted running time of each of the above-mentioned test class file sets.
[0055] Optionally, for example, the @Test annotation is used to describe the time weight information in the debugging test case, and the TestNG listener is used to listen to the test case. The running time weight is obtained by calculating the sum value, and the time weight information is shown in Table 1. Test case A includes 4 test steps. The running time required for debugging test step 1 is 8 minutes, and the corresponding time weight is 3. The running time required for debugging test step 2 is 2 minutes, and the corresponding time weight is 2. The running time required for debugging test step 3 is 15 minutes, and the corresponding time weight is 4. The running time required for debugging test step 4 is 25 minutes, and the corresponding time weight is 5. 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, and the corresponding time weight is 2. The running time required for debugging test step 2 is 4 minutes, and the corresponding time weight is 2. The running time required for debugging test step 3 is 5 minutes, and 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. This embodiment obtains the debugging time and time weight information of each test step in the test case to determine the running time weight of the test case, thereby achieving the purpose of setting a high weight for test cases with high time consumption and complexity.
[0056] Table 1:
[0057]
[0058] In an exemplary embodiment, based on the runtime weights of the test cases included in the test class file set and the first thread interval, the predicted runtime of each of the test class file sets is calculated, including: using a weight listener to identify the weight annotation of the test case to obtain the runtime weight of the test case, wherein the weight listener is set in the test case; calculating the first runtime weight of the test class file, wherein the first runtime weight is the sum of the runtime weights of all the test cases included in the test class file; calculating the second runtime weight of the test class file set, wherein the second runtime weight is the sum of the first runtime weights of all the 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 to obtain M of the predicted runtimes.
[0059] Optionally, the @Test annotation of the test case is identified by the TestNG listener to obtain the runtime weight of the test case, 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 2 test class files: test class file A and test class file B, the test class file A includes 2 test cases: test case A and test case B, the test class file B includes 3 test cases: test case C, test case D and test case E, and the first thread interval is [1,2]. The TestNG listener recognizes that the running time weight recorded in the @Test annotation of test case A is 14, and the running time weight recorded in the @Test annotation of test case B is 6, and the first running time weight of test class file A is 20 (6+14=20). The TestNG listener recognizes that the running time weight recorded in the @Test annotation of test case C is 10, the running time weight recorded in the @Test annotation of test case D is 16, and the running time weight recorded in the @Test annotation of test case E is 26, and the first running time weight of test class file B is 52 (10+16+26=52). The second running time weight of 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 achieves the purpose of accurately predicting the running time of the test class file set by calculating the ratio of the number of threads in the first thread interval of the second time weight of the test class file set.
[0060] In an exemplary embodiment, a target thread required to run the test cases included in the target test class file set is calculated based on the target predicted running time and the running time of the test cases included in the target test class file set, including: calculating the target second time weight of the target test class file set, wherein the target second time weight is a weight among the M second time weights; and 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 test class file set among the M test class file sets, and the calculation method of the target second time weight is the same as the method for calculating the second running time weight mentioned above, which will not be repeated 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, then 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, then 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 that need to be started in the test class file set with the longest running time, thereby achieving the purpose of reducing the consumption of test environment resources by test cases under other test environment types.
[0062] In an exemplary embodiment, after calculating the target thread required to run the test case included in the target test class file set based on the target predicted running time and the running time of the test case included in the target test class file set, the method further includes: running the test case 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 case; and updating the running time weight included in the weight annotation of the test case based on the running information included in the running result.
[0063] Optionally, the running information is used to describe the information of the test cases that failed to run and the information of the test cases that ran successfully. For example, the running results of the test class file set A include: the test cases A and B that failed to run and the test cases C, D and E that ran successfully. The running time weights of the test cases A and B are increased. After the subsequent test cases A and B run successfully again, the running time weights of the test cases A and B are reduced. This embodiment achieves the purpose of reducing the loss of the failed test cases to the test environment and resources, affecting the subsequent test case class running, and improving the pass rate of the test case class by updating the running time weights of the test cases based on the running results.
[0064] In an exemplary embodiment, based on the debugging time and time weight information of each test step in the above test case, the running time weight of the above test case is determined, including: obtaining the time weight of the debugging time of each of the above test steps from the above time weight information to obtain multiple time weights; performing a sum operation on the multiple time weights to obtain the running time weight of the above test case.
[0065] Optionally, the time weight information is as shown in Table 1. Test case A includes 4 test steps, the running time required for debugging test step 1 is 8 minutes, and the corresponding time weight is 3, the running time required for debugging test step 2 is 2 minutes, and the corresponding time weight is 2, the running time required for debugging test step 3 is 15 minutes, and the corresponding time weight is 4, the running time required for debugging test step 4 is 25 minutes, and the corresponding time weight is 5, then the running time weight of test case A is 3+2+4+5=14. Test case B includes 3 test steps, the running time required for debugging test step 1 is 3 minutes, and the corresponding time weight is 2, the running time required for debugging test step 2 is 4 minutes, and the corresponding time weight is 2, the running time required for debugging test step 3 is 5 minutes, and the corresponding time weight is 2, then the running time weight of test case B is 2+2+2=6. This embodiment determines the running time weight of the test case by obtaining the debugging time and time weight information of each test step in the test case, thereby achieving the purpose of setting a high weight for test cases with high time consumption and complexity.
[0066] The present application is described below in conjunction with specific embodiments:
[0067] In this specific embodiment, Figure 4 This is a process of a method for determining a target thread according to a specific embodiment of the present application. Figure 2 ,like Figure 4 As shown, the specific steps include:
[0068] S402, start to determine the target thread for 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: a test case A and a test case B, the test class file B includes three test cases: a test case C, a test case D and a test case E, the test class file C includes two test cases: a test case F and a test case G, and the test class file D includes two test cases: a test case H and a test case I;
[0069] S404, the classification device uses the TestNG listener to listen to the @Test annotation to obtain the test environment of the test case in the test class file. The TestNG listener identifies the @Test annotation of the test class file A to obtain that the test environment is a physical machine test, identifies the @Test annotation of the test class file B to obtain that the test environment is a physical machine test, identifies the @Test annotation of the test class file C to obtain that the test environment is a multi-node test, and identifies the @Test annotation of the test class file D to obtain that the test environment is a multi-node test.
[0070] The classification device classifies the test class file A, the test class file B, the test class file C and the test class file D in the test case set A based on the acquired test environment, and obtains the test class file set A and the 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 during the debugging of the test case. Test case A includes 4 test steps. The running time required for debugging test step 1 is 8 minutes, and the corresponding time weight is 3. The running time required for debugging test step 2 is 2 minutes, and the corresponding time weight is 2. The running time required for debugging test step 3 is 15 minutes, and the corresponding time weight is 4. The running time required for debugging test step 4 is 25 minutes, and the corresponding time weight is 5. Then 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 of 14. Test case B includes 3 test steps. The running time required for debugging test step 1 is 3 minutes, and the corresponding time weight is 2. The running time required for debugging test step 2 is 4 minutes, and the corresponding time weight is 2. The running time required for debugging test step 3 is 5 minutes, and the corresponding time weight is 2. Then 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 of 6. A similar weight configuration device determines the runtime weight 8 of test case C, the runtime weight 10 of test case D, the runtime weight 6 of test case E, the runtime weight 8 of test case F, the runtime weight 12 of test case G, the runtime weight 12 of test case H and the runtime weight 14 of test case I.
[0072] The weight configuration device calculates the first runtime weight 20 of the test class file A based on the runtime weights of the test cases A and B; calculates the first runtime weight 24 of the test class file B based on the runtime weights of the test cases C, D, and E; calculates the first runtime weight 20 of the test class file C based on the runtime weights of the test cases F and G; calculates the first runtime weight 26 of the test class file D based on the runtime weights of the test cases H and I;
[0073] The weight configuration device calculates the second runtime weight 44 of the test class file set A based on the first runtime weight 20 of the test class file A and the first runtime weight 24 of the test class file B; and calculates the second runtime weight 46 of the test class file set B based on the first runtime weight 20 of the test class file C and the first runtime 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] Based on the ratio of the second running time weight of test class file set A to the first thread interval, the predicted running time of test class file set A is determined to be [22, 44], the second running time weight of test class file set B is determined to be [23, 46], and the target predicted running time of 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 thread tree ages to the test cases in the test class file set based on the target thread, runs the test cases, and feeds back the running results to the weight configuration device, the weight configuration device updates the test running time weight based on the information of the test cases that failed to run and the information of the test cases that ran successfully. For example, the running results include: the test cases A and B that failed to run and the test cases C, D and E that ran successfully, the running time weights of the test cases A and B are increased, and after the test cases A and B run successfully again, the running time weights of the test cases A and B are reduced;
[0078] S412, end.
[0079] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, 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 number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0080] In the present embodiment, a device for determining a target thread is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the descriptions that have been made are not repeated here. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0081] Figure 5 is a structural block diagram of a device for determining a target thread according to an embodiment of the present application, such as Figure 5 As shown, the device comprises:
[0082] The first execution module 502 is used to perform a classification operation on N test class files in the test case set to obtain M test class file sets, wherein one of the test class file sets belongs to a test environment, the test environment is an environment for testing the test cases in the test case set, each of the test class files includes at least one test case, the N is a natural number greater than 1, and the M is a natural number less than or equal to the N, or equal to 1;
[0083] A first determination module 504 is configured to determine a first thread interval required to run a test case included in each of the test class file sets based on the number of the 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 to run the test case;
[0084] A first calculation module 506 is used to calculate 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, wherein the running time includes the debugging time of each test step in the test case;
[0085] The second calculation module 508 is used to calculate the target threads 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, wherein the target test class file set is any test class file set among the M test class file sets, and the target predicted running time is the longest time among the M predicted running times.
[0086] In an exemplary embodiment, the above-mentioned device also includes: a first acquisition module, which is used to perform a classification operation on N test class files in a test case set, and before obtaining M test class file sets, identify the test environment annotations in the N above-mentioned test class files through a test environment listener, and obtain the N above-mentioned test environments of the N above-mentioned test class files, wherein the above-mentioned test environment listener is set in the above-mentioned test class file, and the above-mentioned test environment annotation is used to describe the environment for testing the above-mentioned test cases in the above-mentioned test class files.
[0087] In an exemplary embodiment, the above-mentioned first calculation module includes: a first calculation submodule, which is used to calculate the above-mentioned predicted running time for each of the above-mentioned test class file sets through the following steps to obtain M of the above-mentioned predicted running times: a first debugging unit, which is used to debug the above-mentioned test case; obtaining the debugging time of each test step in the above-mentioned test case during the debugging of the above-mentioned test case through a runtime listener, wherein one of the above-mentioned test cases includes multiple test steps, and the above-mentioned runtime listener is set in the above-mentioned test case; a first determination unit, which is used to determine the runtime weight of the above-mentioned test case based on the debugging time and time weight information of each test step in the above-mentioned test case, wherein the above-mentioned time weight information is used to describe the mapping relationship between the above-mentioned debugging time and the time weight; a first adding unit, which is used to add the above-mentioned runtime weight to the weight annotation of the above-mentioned test case, wherein the above-mentioned weight annotation is used to describe the time weight information in debugging the above-mentioned test case; a first calculation unit, which is used to calculate the above-mentioned predicted running time of each of the above-mentioned test class file sets based on the runtime weight of the test case included in the above-mentioned test class file set and the above-mentioned first thread interval.
[0088] In an exemplary embodiment, the above-mentioned first calculation unit includes: a first acquisition subunit, used to use a weight listener to identify the weight annotation of the above-mentioned test case to obtain the runtime weight of the above-mentioned test case, wherein the above-mentioned weight listener is set in the above-mentioned test case; a first calculation subunit, used to calculate the first runtime weight of the above-mentioned test class file, wherein the above-mentioned first runtime weight is the sum of the runtime weights of all test cases included in the above-mentioned test class file; a second calculation subunit, used to calculate the second runtime weight of the above-mentioned test class file set, wherein the above-mentioned second runtime weight is the sum of the first runtime weights of all test class files included in the above-mentioned test class file set; a third calculation subunit, used to calculate the ratio of the above-mentioned second time weight of the above-mentioned test class file set to the number of threads in the above-mentioned first thread interval, and obtain M of the above-mentioned predicted runtimes.
[0089] In an exemplary embodiment, the above-mentioned second calculation module includes: a second calculation submodule, used to calculate the target second time weight of the above-mentioned target test class file set, wherein the above-mentioned target second time weight is a weight among the M above-mentioned second time weights; a first determination submodule, used to determine the ratio between the above-mentioned target second time weight and the above-mentioned target predicted running time as the above-mentioned target thread.
[0090] In an exemplary embodiment, the above-mentioned device also includes: a first running module, which is used to calculate the target thread required to run the test case included in the target test class file set based on the target predicted running time and the running time of the test case included in the target test class file set, and then run the test case included in the target test class file set based on the above-mentioned target thread to obtain an running result, wherein the above-mentioned running result includes the running information of the above-mentioned test case; a first updating module, which is used to update the running time weight included in the weight annotation of the above-mentioned test case based on the above-mentioned running information included in the above-mentioned running result.
[0091] In an exemplary embodiment, the above-mentioned first determination unit includes: a first acquisition subunit, used to obtain the time weight of the debugging time of each of the above-mentioned test steps from the above-mentioned time weight information to obtain multiple time weights; a first execution subunit, used to perform an addition operation on the multiple above-mentioned time weights to obtain the running time weight of the above-mentioned test case.
[0092] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0093] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0094] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0095] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0096] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0097] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0098] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0099] The embodiments of the present application also provide a computer program, which includes 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 the processor executes the computer instructions, so that the computer device performs the steps of any one of the above method embodiments.
[0100] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0101] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0102] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for determining a target thread, characterized in that: include: Performing a classification operation on N test class files in the test case set to obtain M test class file sets, wherein one of the test class file sets belongs to a test environment, the test environment is an environment for testing the 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; Determine, based on the number of the test class files included in each of the test class file sets, a first thread interval required to run the test case included in each of the test class file sets, wherein the first thread interval is used to represent the number of threads required to run the test case; 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 M predicted running times, wherein the running time includes the debugging time of each test step in the test case; According to the target predicted running time and the running time of the test cases included in the target test class file set, the target threads required to run the test cases included in the target test class file set are calculated, wherein the target test class file set is any test class file set among 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 according to claim 1, characterized in that: Before performing classification operations on the N test class files in the test case set to obtain the M test class file sets, the method further includes: The test environment annotations in the N test class files are identified through a test environment listener to obtain 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 annotations are used to describe the environment for testing the test cases in the test class files.
3. The method according to claim 1, characterized in that Calculating 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 includes: For each of the test class file sets, the predicted running time is calculated by the following steps to obtain M predicted running times: debugging the test case; Acquiring, through a runtime listener, a debugging time of each test step in the test case during debugging of the test case, wherein one test case includes a plurality of the test steps, and the runtime listener is set in the test case; 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, wherein the time weight information is used to describe the mapping relationship between the debugging time and the time weight; Adding the runtime 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; The predicted running time of each of the test class file sets is calculated based on the running time weights of the test cases included in the test class file set and the first thread interval.
4. The method according to claim 3, characterized in that Calculating the predicted running time of each of the test class file sets based on the running time weights of the test cases included in the test class file set and the first thread interval includes: identifying a weight annotation of the test case using a weight listener to obtain a runtime weight of the test case, wherein the weight listener is set in the test case; Calculating a first runtime weight of the test class file, wherein the first runtime weight is a sum of runtime weights of all test cases included in the test class file; Calculating a second runtime weight of the test class file set, wherein the second runtime weight is a sum of first runtime weights of all test class files included in the test class file set; The ratio of the second time weight of the test class file set to the number of threads in the first thread interval is calculated to obtain M of the predicted running times.
5. The method according to claim 3, characterized in that: Calculating target threads 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 includes: 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; The ratio between the target second time weight and the target predicted running time is determined as the target thread.
6. The method according to claim 3, characterized in that: After calculating the target threads 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 includes: Running the test case 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 case; Based on the running information included in the running result, the running time weight included in the weight annotation of the test case is updated.
7. The method according to claim 3, characterized in that Determining 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 includes: Acquire the time weight of the debugging time of each of the test steps from the time weight information to obtain a plurality of time weights; An addition operation is performed on a plurality of the time weights to obtain a running time weight of the test case.
8. A device for determining a target thread, characterized in that: The device comprises: A first execution module is used to perform 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 a test environment, the test environment is an environment for testing the 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 is used to determine a first thread interval required to run a test case included in each test class file set based on the number of the test class files included in each test class file set, wherein the first thread interval is used to represent the number of threads required to run the test case; A first calculation module, configured to calculate 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, wherein the running time includes the debugging time of each test step in the test case; The second calculation module is used to calculate the target threads 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, wherein the target test class file set is any test class file set among the M test class file sets, and the target predicted running time is the 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 implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Automatic testing method and device
CN113760709A
Test method and system, storage medium and equipment
CN115629997A
Chip test data analysis method and device, electronic equipment and storage medium
CN116820853A
Test method and device of storage system, storage medium and electronic equipment
CN118132400A
Retrying failed test cases in software testing using parallel threads
US11720482B1