Test case screening method, device, electronic device and storage medium

By comparing and filtering the code coverage data of automated test cases, the problem of heavy workload and high cost of maintaining automated test cases is solved, and the screening of effective use cases and the reduction of maintenance costs are achieved.

CN113722234BActive Publication Date: 2024-09-20JINGDONG TECH HLDG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111075142.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-14
Publication Date
2024-09-20
Estimated Expiration
2041-09-14

AI Technical Summary

Technical Problem

Existing automated test case maintenance requires a large workload and high cost, requiring manual maintenance of a large number of test cases.

Method used

By executing test cases one by one, the code coverage data of each test case is obtained, and the data of the current use case is compared with the data of the previous use case, filtered and processed according to the changes, invalid use cases are deleted, and valid use cases are retained.

Benefits of technology

It reduces the workload of testers to manually maintain test cases, reduces maintenance costs, selects effective test case collections, and simplifies the subsequent maintenance process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113722234B
    Figure CN113722234B
Patent Text Reader

Abstract

An embodiment of the present invention relates to a test case screening method, device, electronic device and storage medium, which executes test cases one by one and obtains code coverage data corresponding to each executed test case; compares the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and screens the currently executed test case according to the comparison result. That is, in the embodiment of the present invention, all test cases are executed one by one, and effective test cases are screened according to the changes in the code coverage data corresponding to each executed test case, thereby reducing the workload of testers in manually maintaining test cases and reducing maintenance costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software testing, and in particular to a test case screening method, device, electronic equipment and storage medium. Background Art

[0002] Software testing is a necessary stage in the software project process. Only software that has passed the software testing can be released online. Among them, automated testing is a common software testing method.

[0003] Existing automated testing requires testers to manually maintain automated test cases. However, as the number of automated test cases increases, the automated test maintenance workload of testers increases and the maintenance cost becomes higher and higher. Summary of the invention

[0004] The present invention provides a test case screening method, device, electronic device and storage medium to solve the technical problems of large workload and high cost in manually maintaining automated test cases.

[0005] In a first aspect, the present invention provides a method for screening test cases, comprising: executing test cases one by one and obtaining code coverage data corresponding to each executed test case; comparing the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and screening the currently executed test case according to the comparison result.

[0006] As an optional embodiment, the currently executed test case is screened according to the comparison result, including: if the comparison result is that the code coverage data corresponding to the currently executed test case is unchanged compared with the code coverage data corresponding to the previously executed test case, then deleting the currently executed test case; if the comparison result is that the code coverage data corresponding to the currently executed test case is improved compared with the code coverage data corresponding to the previously executed test case, then retaining the currently executed test case.

[0007] As an optional embodiment, executing the test cases one by one includes: reading multiple test cases into a memory and storing each test case as a line of records; and executing the records line by line.

[0008] As an optional embodiment, the obtaining of code coverage data corresponding to each executed test case includes: after each test case is executed, obtaining corresponding code coverage data through an open source code coverage data calculation tool.

[0009] As an optional embodiment, the method further includes: receiving a query request, and asynchronously displaying code coverage data corresponding to the executed test cases according to the query request.

[0010] In the second aspect, the present invention provides a test case screening device, comprising a scheduling module, a test module and a code coverage data acquisition module; wherein the scheduling module is used to control the test module to execute test cases one by one, and obtain the code coverage data corresponding to each executed test case through the code coverage data acquisition module; the scheduling module is also used to compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and screen the currently executed test case according to the comparison result.

[0011] As an optional embodiment, the scheduling module is specifically used to: if the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, then delete the currently executed test case; if the comparison result is that the code coverage data corresponding to the currently executed test case has improved compared with the code coverage data corresponding to the previously executed test case, then retain the currently executed test case.

[0012] As an optional embodiment, the device also includes a monitoring module; the scheduling module is specifically used to: receive a query request, and asynchronously display the code coverage data corresponding to the executed test case through the monitoring module according to the query request.

[0013] In a third aspect, the present invention provides an electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; the memory is used to store computer programs; and the processor is used to implement the steps of the test case screening method described in any one of the first aspects when executing the program stored in the memory.

[0014] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of the test case screening method as described in any one of the first aspects are implemented.

[0015] The test case screening method, device, electronic device and storage medium provided in the embodiments of the present invention execute test cases one by one and obtain code coverage data corresponding to each executed test case; compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and screen the currently executed test case according to the comparison result; that is, in the embodiments of the present invention, all test cases are executed one by one, and effective test cases are screened according to the changes in the code coverage data corresponding to each executed test case, thereby reducing the workload of testers in manually maintaining test cases and reducing maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0018] Figure 1 A flowchart of a method for screening test cases provided by an embodiment of the present invention;

[0019] Figure 2 A schematic diagram of a flow chart of another test case screening method provided by an embodiment of the present invention;

[0020] Figure 3 A flowchart of a test case screening method provided by an embodiment of the present invention;

[0021] Figure 4 A schematic diagram of the structure of a test case screening device provided by an embodiment of the present invention;

[0022] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0024] Software testing is a necessary stage in the software project process. Only software that has passed the software testing can be released online. Among them, automated testing is a common software testing method.

[0025] Existing automated testing requires testers to manually maintain automated test cases, where manual maintenance requires testers to manually save valid test cases based on the software to be tested and operate the test cases to test the software. However, as the number of automated test cases increases, the workload of testers in automated testing maintenance increases, and the maintenance cost becomes higher and higher.

[0026] In response to the above technical problems, the technical concept of the present invention is to provide a test case screening method, that is, before the tester maintains the automated test cases, all test cases are first executed one by one, and then the automated test cases are screened according to the changes in the code coverage data corresponding to each test case, thereby reducing the number and difficulty of automated test cases and reducing maintenance costs.

[0027] Figure 1 The present invention provides a flowchart of a method for screening test cases. The execution subject of the present invention is an electronic device equipped with a test case screening device. Figure 1 As shown, the screening method of this test case includes:

[0028] Step S101: execute test cases one by one, and obtain code coverage data corresponding to each executed test case.

[0029] In this embodiment, a large number of automated test cases are initially collected for each software to be tested. In this step, all of these large number of test cases are executed one by one, and after each test case is executed, the calculation of code coverage data is triggered, so as to obtain the code coverage data corresponding to each test case. Optionally, the code coverage data is the code coverage rate, which is a metric in software testing, describing the proportion and degree of the program source code corresponding to the software to be tested being tested.

[0030] As an optional embodiment, executing the test cases one by one in step S101 includes: reading multiple test cases into a memory, and storing each test case as a line of records; and executing the records line by line.

[0031] Specifically, a large number of test cases are first read into the memory, each test case corresponds to a line of records, and then the records are executed line by line, that is, the test cases are executed one by one. Optionally, each line of records is marked with a corresponding sequence number.

[0032] As an optional embodiment, the obtaining of code coverage data corresponding to each executed test case in step S101 includes: after each test case is executed, obtaining corresponding code coverage data through an open source code coverage data calculation tool.

[0033] Specifically, an open source code coverage data calculation tool, such as Jacoco dump, wherein Jacoco is a way to count code coverage and is also a command line command supported by Jacoco. In this embodiment, after each test case is executed, the current code coverage of the program source code is counted by Jacoco dump as the code coverage data corresponding to the currently executed test case.

[0034] Step S102: Compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the last executed test case to obtain a comparison result.

[0035] Step S103: screening the currently executed test cases according to the comparison result.

[0036] In this embodiment, according to the change of the code coverage data corresponding to the currently executed test case relative to the code coverage data corresponding to the previously executed test case, it is determined whether to delete or retain the currently executed test case. And so on, all test cases are screened once, reducing the workload of subsequent testers in automated test maintenance.

[0037] As an optional embodiment, the method further includes: receiving a query request, and asynchronously displaying the code coverage data corresponding to the executed test case according to the query request.

[0038] Specifically, the code coverage data corresponding to each executed test case can be asynchronously queried, and the queried code coverage data can be displayed on the front-end device.

[0039] The test case screening method provided in the embodiment of the present invention executes the test cases one by one and obtains the code coverage data corresponding to each executed test case; compares the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and screens the currently executed test case according to the comparison result; that is, in the embodiment of the present invention, all test cases are executed one by one, and effective test cases are screened out according to the changes in the code coverage data corresponding to each executed test case, thereby reducing the workload of testers in manually maintaining test cases and reducing maintenance costs.

[0040] Based on the above embodiments, Figure 2 A flow chart of another test case screening method provided by an embodiment of the present invention is as follows: Figure 2 As shown, the screening method of this test case includes:

[0041] Step S201: Execute test cases one by one, and obtain code coverage data corresponding to each executed test case.

[0042] Step S202: Compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the last executed test case to obtain a comparison result.

[0043] If the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, execute step S203; if the comparison result is that the code coverage data corresponding to the currently executed test case has improved compared with the code coverage data corresponding to the previously executed test case, execute step S204.

[0044] Step S203: Delete the currently executed test case.

[0045] Step S204: retain the currently executed test case.

[0046] The implementation methods of step S201 and step S202 in this embodiment are similar to the implementation methods of step S101 and step S102 in the above embodiments, and will not be repeated here.

[0047] The difference from the above embodiment is that this embodiment further limits the specific screening method of test cases. In this embodiment, if the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, the currently executed test case is deleted; if the comparison result is that the code coverage data corresponding to the currently executed test case is improved compared with the code coverage data corresponding to the previously executed test case, the currently executed test case is retained.

[0048] Specifically, if the code coverage data corresponding to the currently executed test case has not changed compared to the code coverage data corresponding to the previously executed test case, it means that the currently executed test case has not tested the software to be tested and is an invalid test case, which can be directly deleted; if the code coverage data corresponding to the currently executed test case has increased compared to the code coverage data corresponding to the previously executed test case, it means that the currently executed test case can test the software to be tested and is a valid test case, which needs to be retained. In this way, a new set of automated test cases can be screened out from the initial massive automated test cases, and subsequent testers only need to maintain this new set of automated test cases.

[0049] The test case screening method provided by the embodiment of the present invention, if the comparison result is that the code coverage data corresponding to the currently executed test case has not changed relative to the code coverage data corresponding to the previously executed test case, then the currently executed test case is deleted; if the comparison result is that the code coverage data corresponding to the currently executed test case is improved relative to the code coverage data corresponding to the previously executed test case, then the currently executed test case is retained; that is, the embodiment of the present invention screens out effective automation cases according to the changes in the code coverage data of each test case during the execution process, and finally generates a new parameter file. In this way, the workload of testers in maintaining automation cases can be reduced.

[0050] In order to further understand the embodiments of the present invention, Figure 3 A flowchart of a test case screening method provided by an embodiment of the present invention, such as Figure 3 As shown, the electronic device executing the screening method includes a scheduling module, a testing module (also referred to as an automated testing module), a code coverage data acquisition module, and a monitoring module. The test case screening method includes:

[0051] Step S00: The scheduling module pre-processes the initial parameter file.

[0052] Step S01: The scheduling module controls the automated testing module to execute a line of test cases.

[0053] Step S02: The scheduling module triggers the code coverage data acquisition module to calculate the code coverage data corresponding to the currently executed test case.

[0054] If the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, execute step S05; if the code coverage data corresponding to the currently executed test case has improved compared with the code coverage data corresponding to the previously executed test case, execute step S06.

[0055] Step S05: Delete the currently executed test case.

[0056] Step S06: retain the currently executed test case.

[0057] In this embodiment, the scheduling module first preprocesses the initial parameter file. Preprocessing refers to reading a large number of automated test cases into the memory, and storing each test case as a line with a serial number; then the scheduling module controls the automated test module to execute a line of test cases, and after the execution is completed, triggers the code coverage data acquisition module to calculate the degree to which the program source code of the current software to be tested is tested, that is, the code coverage rate, as the code coverage data corresponding to the currently executed test case; then the code coverage data corresponding to the currently executed test case is compared with the code coverage data corresponding to the previous test case. If the code coverage data has not changed, the currently executed test case is deleted. If the code coverage data has improved, the test case is retained and a new parameter file is generated. Later testers only need to maintain the automated test cases stored in the new parameter file.

[0058] In addition, this embodiment also includes: step S03, querying the code coverage rate corresponding to the executed test case; step S04, displaying the code coverage data corresponding to the executed test case through the monitoring module. That is, the scheduling module will receive the user's query request, and query the corresponding code coverage data from the code coverage data acquisition module according to the query request, and display it on the front-end page of the monitoring module.

[0059] In summary, the embodiments of the present invention screen out effective test cases through changes in code coverage data corresponding to each executed test case, thereby reducing the workload of testers in manually maintaining test cases and lowering maintenance costs.

[0060] Figure 4 A schematic diagram of the structure of a test case screening device provided by an embodiment of the present invention. Figure 4 As shown, the test case screening device includes a scheduling module 10, a testing module 20 and a code coverage data acquisition module 30;

[0061] Among them, the scheduling module 10 is used to control the testing module 20 to execute test cases one by one, and obtain the code coverage data corresponding to each executed test case through the code coverage data acquisition module 30; the scheduling module 10 is also used to compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and filter and process the currently executed test case according to the comparison result.

[0062] As an optional embodiment of the present invention, the scheduling module 10 is specifically used to: if the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, then delete the currently executed test case; if the comparison result is that the code coverage data corresponding to the currently executed test case is improved compared with the code coverage data corresponding to the previously executed test case, then retain the currently executed test case.

[0063] As an optional embodiment of the present invention, the scheduling module 10 is specifically used to: read multiple test cases into the memory, and store each test case as a line of records; control the test module 20 to execute the records line by line.

[0064] As an optional embodiment of the present invention, the code coverage data acquisition module 30 is specifically used to: after each test case is executed, obtain the corresponding code coverage data through an open source code coverage data calculation tool.

[0065] As an optional embodiment of the present invention, the device also includes a monitoring module 40, and the scheduling module 10 is specifically used to: receive a query request, and asynchronously display the code coverage data corresponding to the executed test case through the monitoring module 40 according to the query request.

[0066] The implementation principle and technical effect of the test case screening device provided in this embodiment are similar to those of the above embodiments and will not be described in detail here.

[0067] The test case screening device provided in an embodiment of the present invention comprises a scheduling module, a testing module, and a code coverage data acquisition module; wherein the scheduling module is used to control the testing module to execute test cases one by one, and obtain the code coverage data corresponding to each executed test case through the code coverage data acquisition module; the scheduling module is also used to compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and the currently executed test case is screened according to the comparison result; that is, in an embodiment of the present invention, by executing all test cases one by one and screening out effective test cases according to the changes in the code coverage data corresponding to each executed test case, the workload of testers in manually maintaining test cases is reduced, and the maintenance cost is reduced.

[0068] like Figure 5 As shown, an embodiment of the present invention provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.

[0069] Memory 113, used for storing computer programs;

[0070] In one embodiment of the present invention, the processor 111 is used to implement the steps of the test case screening method provided by any one of the aforementioned method embodiments when executing the program stored in the memory 113.

[0071] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the test case generation method provided in any one of the aforementioned method embodiments are implemented.

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

[0073] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for screening test cases, characterized in that: include: Execute test cases one by one and obtain code coverage data corresponding to each executed test case, wherein the code coverage data refers to the proportion and degree of the program source code corresponding to the software to be tested being tested after the current and previous test cases are executed; Compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; The currently executed test cases are screened according to the comparison results.

2. The method according to claim 1, characterized in that The screening process of the currently executed test cases according to the comparison result includes: If the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, then deleting the currently executed test case; If the comparison result is that the code coverage data corresponding to the currently executed test case is improved relative to the code coverage data corresponding to the previously executed test case, the currently executed test case is retained.

3. The method according to claim 1, characterized in that The test cases executed one by one include: Read multiple test cases into memory and store each test case as a row of records; The recording is performed line by line.

4. The method according to any one of claims 1 to 3, characterized in that: The obtaining of code coverage data corresponding to each executed test case includes: After each test case is executed, the corresponding code coverage data is obtained through an open source code coverage data calculation tool.

5. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Receive a query request and asynchronously display code coverage data corresponding to the executed test cases according to the query request.

6. A test case screening device, characterized in that: Includes scheduling module, testing module and code coverage data acquisition module; The scheduling module is used to control the test module to execute test cases one by one, and obtain the code coverage data corresponding to each executed test case through the code coverage data acquisition module. The code coverage data refers to the proportion and degree of the program source code corresponding to the software to be tested being tested after the current and previous test cases are executed; The scheduling module is also used to compare the code coverage data corresponding to the currently executed test case with the code coverage data corresponding to the previously executed test case to obtain a comparison result; and to filter and process the currently executed test case based on the comparison result.

7. The device according to claim 6, characterized in that The scheduling module is specifically used for: If the comparison result is that the code coverage data corresponding to the currently executed test case has not changed compared with the code coverage data corresponding to the previously executed test case, then deleting the currently executed test case; If the comparison result is that the code coverage data corresponding to the currently executed test case is improved relative to the code coverage data corresponding to the previously executed test case, the currently executed test case is retained.

8. The device according to claim 6 or 7, characterized in that The device also includes a monitoring module; The scheduling module is specifically used to: receive a query request, and asynchronously display the code coverage data corresponding to the executed test cases through the monitoring module according to the query request.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the steps of the test case screening method described in any one of claims 1 to 5 when executing a program stored in a memory.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the test case screening method according to any one of claims 1 to 5 are implemented.