Application Testing Method, Device, Computer Equipment and Storage Medium

By calculating code coverage and distribution relationships, the problem of low application test accuracy is solved and more accurate test results are achieved.

CN114064497BActive Publication Date: 2025-08-05PING AN SECURITIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111386205.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-22
Publication Date
2025-08-05
Estimated Expiration
2041-11-22

AI Technical Summary

Technical Problem

In the prior art, the accuracy of application testing is low, mainly because the test case design is difficult to cover everything, resulting in frequent missed tests.

Method used

By obtaining the test case set, calculate the code coverage of each test case, filter out test cases with lower than the preset coverage, determine their distribution relationship with the code, pool the total distribution relationship, filter out the uninvoked target code, adjust the test case set to generate the target test case, and perform retesting.

Benefits of technology

Improve the accuracy of application testing and avoid missed testing. The test range is more objective and accurate than manual evaluation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064497B_ABST
    Figure CN114064497B_ABST
Patent Text Reader

Abstract

The present application relates to the field of test case technology, and provides an application testing method, apparatus, computer equipment, and storage medium, wherein the method comprises: testing an application in sequence using each test case in an acquired test case set, calculating the code coverage of each test case when testing the application, screening out first test cases whose code coverage is lower than a preset coverage from the test case set, determining the distribution relationship between each first test case and the called code, aggregating the distribution relationships between all first test cases and the code to obtain a total distribution relationship, screening out the code that is not called during the test of the application based on the total distribution relationship, obtaining a target code, adjusting the first test case in the test case set as a target test case according to the target code, and retesting the application using the target test case to obtain a test result, so as to avoid missed tests and improve the accuracy of application testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of test cases, and in particular to an application testing method, apparatus, computer equipment, and storage medium. Background Art

[0002] Generally speaking, the current application testing process generally involves formulating a test plan based on requirements and design, and writing test cases to test the application. However, everyone has different understandings of requirements and design, which makes it difficult to design comprehensive test cases. This often leads to some missed tests, resulting in low accuracy in application testing. Summary of the Invention

[0003] The main purpose of this application is to provide an application testing method, apparatus, computer equipment and storage medium to improve the accuracy of application testing.

[0004] To achieve the above-mentioned object of the invention, the present application provides an application testing method, which comprises the following steps:

[0005] Obtaining a test case set, and testing the application program in sequence using each test case in the test case set;

[0006] Calculating the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0007] When there are test cases with code coverage lower than the preset coverage, filter out the test cases with code coverage lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0008] Determining a distribution relationship between each of the first test cases and the called code;

[0009] Gathering the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0010] Filter out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code;

[0011] Adjust the first test case of the test case set according to the target code to obtain a target test case;

[0012] The application is retested using the target test case to obtain a test result.

[0013] Preferably, adjusting the first test case of the test case set according to the target code to obtain a target test case includes:

[0014] Determine a first test case in the test case set that is related to the target code, and obtain a second test case;

[0015] Obtaining the source code of the second test case;

[0016] Comparing the source code with the target code to obtain code difference information;

[0017] The source code of the second test case is adjusted according to the distribution relationship of the second test case and the code difference information to obtain a target test case.

[0018] Preferably, the code difference information includes incremental information, and adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain the target test case includes:

[0019] Determine method information where the incremental information is located according to the incremental information of the code difference information;

[0020] Recursively querying the first method information that calls the method information based on the method information, and using the first method information finally found in the recursive query as the target method information; wherein the target method information is used to represent the impact range of the new content added between the current version and the previous version of the application;

[0021] A second test case that must be adjusted is determined according to the distribution relationship and the target method information, and a target test case is obtained after adjusting the second test case that must be adjusted.

[0022] Furthermore, after retesting the application using the target test case and obtaining the test result, the method further includes:

[0023] Obtaining a change code for the application;

[0024] Determining the incremental coverage of the target test case on the changed code, wherein the incremental coverage represents the coverage of the changed code when the application executes the target test case;

[0025] Determining whether the incremental coverage ratio is greater than a preset incremental coverage ratio;

[0026] If so, the target test case is added to the pre-built test case library.

[0027] Furthermore, after adding the target test case to the pre-built test case library, the method further includes:

[0028] In response to a user's test case recommendation request, obtaining code change information from the recommendation request; wherein the code change information includes a code change file number and a code change line number;

[0029] Filtering target test cases corresponding to the code change information from the use case library to obtain test cases to be recommended;

[0030] The test case to be recommended is sent to the user.

[0031] Preferably, sending the test case to be recommended to the user includes:

[0032] When it is detected that there are multiple test cases to be recommended, obtaining the code coverage of each test case to be recommended;

[0033] Sort all the test cases to be recommended in descending order of code coverage to obtain a sorting result;

[0034] According to the sorting result, the code coverage rate ranked first is used as the target code coverage rate;

[0035] The test cases to be recommended corresponding to the target code coverage are recommended to the user.

[0036] Preferably, calculating the code coverage of each test case when testing the application includes:

[0037] When the application loads the application code according to each test case, determining the class file to be loaded of the application;

[0038] Performing bytecode modification on the class file to be loaded to obtain a modified class file to be executed of the application program;

[0039] Obtain the executed code through the class file to be executed;

[0040] The code coverage of the test case is calculated based on the executed code.

[0041] The present application also provides an application testing device, which includes:

[0042] An acquisition module, configured to acquire a test case set, and test the application program in sequence using each test case in the test case set;

[0043] A calculation module, configured to calculate the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0044] A first screening module is configured to, when there are test cases whose code coverage is lower than a preset coverage, screen out the test cases whose code coverage is lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0045] A determination module, configured to determine a distribution relationship between each of the first test cases and the called code;

[0046] A collection module, configured to collect the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0047] A second screening module is used to screen out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code;

[0048] An adjustment module, configured to adjust the first test case of the test case set according to the target code to obtain a target test case;

[0049] The retest module is used to retest the application program using the target test case to obtain a test result.

[0050] The present application also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any of the above methods when executing the computer program.

[0051] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.

[0052] The present application provides an application testing method, apparatus, computer device, and storage medium. Each test case in an acquired test case set is used to sequentially test an application, and the code coverage of each test case when testing the application is calculated. When a test case with a code coverage lower than a preset coverage exists, a first test case with a code coverage lower than the preset coverage is screened out from the test case set. The distribution relationship between each first test case and the called code is determined. The distribution relationships between all first test cases and the code are aggregated to obtain a total distribution relationship. Based on the total distribution relationship, code that was not called during the test of the application is screened out to obtain a target code. The first test case in the test case set is adjusted as a target test case based on the target code. The application is retested using the target test case to obtain a test result. The distribution relationship between the test case and the code is determined by calculating the code coverage, so that the code that was not called during the test of the application is accurately determined based on the total distribution relationship between all test cases and the code. The test case is adjusted to eliminate the influence of personal factors such as personal experience and development test records. This is more objective, and the test scope is more accurate than manual evaluation, avoiding missed tests and improving the accuracy of application testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 A flowchart of an application testing method according to an embodiment of the present application is shown;

[0054] Figure 2 This is a schematic block diagram of the structure of an application testing device according to an embodiment of the present application;

[0055] Figure 3 This is a schematic block diagram of the structure of a computer device according to an embodiment of the present application.

[0056] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0058] An application testing method proposed in this application uses a server as the execution body. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0059] This application testing method is used to solve the technical problem that the current test case design is difficult to be comprehensive and often has some missed tests, resulting in low accuracy of application testing.

[0060] refer to Figure 1 In one embodiment, the application testing method includes the following steps:

[0061] S11, obtaining a test case set, and testing the application program in sequence using each test case in the test case set;

[0062] S12. Calculate the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0063] S13. When there are test cases whose code coverage is lower than the preset coverage, filter out the test cases whose code coverage is lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0064] S14. Determine the distribution relationship between each of the first test cases and the called code;

[0065] S15. Collect the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0066] S16. Filter out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code;

[0067] S17, adjusting the first test case of the test case set according to the target code to obtain a target test case;

[0068] S18. Retest the application using the target test case to obtain a test result.

[0069] As described in step S11 above, after obtaining a test case set in this embodiment, the test case set generally includes multiple test cases, each of which tests a specific function of the application, such as the application's display. Therefore, each pre-edited test case in the test case set is used to test the application separately to test the application's execution.

[0070] In one embodiment, a weight may also be set for each test case in the test case set, where the weight is proportional to the importance of the test case. When testing an application, the corresponding test cases are called in order according to the weight to test the application, so as to give priority to testing important items of the application.

[0071] In software engineering, a test case is a set of conditions or variables that testers use to determine whether an application or software system functions correctly. A test case is a scientifically organized summary of application testing activities, designed to transform them into a manageable model. It also serves as a method for quantifying testing, with different test cases for different application categories. The method for determining whether an application or system passes testing is called a test criterion.

[0072] As described in step S12 above, the code coverage of a single test case is calculated using the code coverage statistics service. Code coverage is an important indicator of the degree to which a test case covers the application under test. It is a reference value used to measure test completeness and is equal to the code covered by the test divided by the total code. This embodiment uses code coverage data to assess the adequacy of testing.

[0073] As described in the above step S13, this embodiment can separately determine whether the code coverage of each test case is lower than the preset coverage. The preset coverage can be customized as needed. When there are test cases with code coverage lower than the preset coverage, the test cases with code coverage lower than the preset coverage are filtered out from the test case set, and the test cases with code coverage lower than the preset coverage are used as the first test cases.

[0074] As described in step S14 above, this embodiment determines the distribution relationship between each first test case and the called code, that is, which codes of the application program are called by each first test case, wherein the distribution relationship is used to reflect the code corresponding to each test case.

[0075] As described in the above steps S15-S16, this embodiment summarizes the distribution relationship between each test case and the code, merges the repeated parts, and obtains the total distribution relationship. Based on the total distribution relationship, the code that is not called by the application during the test is screened out, and the code that is not called by the application during the test is used as the target code, so that it can be easily determined which codes are not covered and which test case designs are repeated, providing a basis for increasing, reducing, and optimizing test cases, thereby adjusting the test cases of the test case set according to the target code.

[0076] As described in steps S17-S18 above, this embodiment adjusts the first test case of the test case set based on the target code, uses the adjusted first test case as the target test case, and enables the target test case to call part or all of the target code when testing the application. Finally, the application is retested using the target test case to obtain a test result. The test result includes whether each function of the application operates as expected.

[0077] The present application provides an application testing method, which uses each test case in an obtained test case set to test the application in sequence, calculates the code coverage of each test case when testing the application, and when there is a test case with a code coverage lower than a preset coverage, filters out the first test case with a code coverage lower than the preset coverage from the test case set, determines the distribution relationship between each first test case and the called code, aggregates the distribution relationships between all first test cases and the code to obtain a total distribution relationship, filters out the code that was not called during the test of the application based on the total distribution relationship to obtain the target code, adjusts the first test case of the test case set as the target test case according to the target code, and retests the application using the target test case to obtain a test result, thereby determining the distribution relationship between the test case and the code by calculating the code coverage, so as to accurately determine the code that was not called during the test of the application based on the total distribution relationship between all test cases and the code, and adjusts the test case to eliminate the influence of personal factors such as personal experience and development test records, making it more objective and the test scope more accurate than manual evaluation, avoiding the occurrence of missed tests and improving the accuracy of application testing.

[0078] In one embodiment, adjusting the first test case of the test case set according to the target code to obtain a target test case may specifically include:

[0079] Determine a first test case in the test case set that is related to the target code, and obtain a second test case;

[0080] Obtaining the source code of the second test case;

[0081] Comparing the source code with the target code to obtain code difference information;

[0082] The source code of the second test case is adjusted according to the distribution relationship of the second test case and the code difference information to obtain a target test case.

[0083] This embodiment identifies test cases within a test case set that are relevant to the target code. Specifically, it retrieves test cases related to code that was required but not called during test case design, and uses the test cases related to the target code as target test cases. The source code of the target test cases is then obtained, compared with the target code to obtain code difference information. The source code of the target test cases is then adjusted based on the distribution relationship and code difference information to generate an adjusted test case set, thereby precisely adjusting the test cases. For example, common feature information is obtained between the uncalled code in the distribution relationship and the code difference information, and the source code of the target test cases is adjusted based on this common feature information.

[0084] In one embodiment, the code difference information includes incremental information, and adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain the target test case may specifically include:

[0085] Determine method information where the incremental information is located according to the incremental information of the code difference information;

[0086] Recursively querying the first method information that calls the method information based on the method information, and using the first method information finally found in the recursive query as the target method information; wherein the target method information is used to represent the impact range of the new content added between the current version and the previous version of the application;

[0087] A second test case that must be adjusted is determined according to the distribution relationship and the target method information, and a target test case is obtained after adjusting the second test case that must be adjusted.

[0088] This embodiment determines the method information where the incremental information is located based on the incremental information of the code difference information; wherein, the method information that determines whether the application or system has passed the test is called the test criterion. According to the method information, the first method information of the calling method information is recursively queried, and in the process of multiple recursive queries, the first method information finally recursively queried is used as the target method information; wherein, the target method information is used to characterize the scope of influence of the new content of the current version and the previous version of the application; according to the distribution relationship and the target method information, the test cases that must be executed are determined, and after the test cases that must be executed are adjusted, an adjusted test case set is generated, thereby combining the code coverage rate to determine whether the use case design is comprehensive and effective, and avoid the problem of missing other functions that call the common module; in addition, according to the distribution relationship and the target method information, the test cases that must be executed are determined, and the "minimum necessary test case set" can be accurately determined for testing, which greatly reduces the number of cases that need to be executed during regression testing and improves testing efficiency.

[0089] In one embodiment, after retesting the application using the target test case and obtaining the test result, the method may further include:

[0090] Obtaining a change code for the application;

[0091] Determining the incremental coverage of the target test case on the changed code, wherein the incremental coverage represents the coverage of the changed code when the application executes the target test case;

[0092] Determining whether the incremental coverage ratio is greater than a preset incremental coverage ratio;

[0093] If so, the target test case is added to the pre-built test case library.

[0094] The changed code of the application is understood to be the code updated relative to the source code, which may include newly added code and / or modified code, such as the code that implements new requirements.

[0095] The preset incremental coverage can be a preset value determined based on actual needs or empirical values. In one embodiment, the preset incremental coverage is an incremental coverage calculated based on the test cases already in the use case library. This embodiment only needs to determine whether the incremental coverage is greater than the preset incremental coverage. When the incremental coverage is greater than the preset incremental coverage, the target test case is added to the use case library. If it is only necessary to determine whether the code covered by the test case is more than the code covered by the existing test cases, the target test cases to be added to the use case library can be screened in a relatively simple way.

[0096] In this embodiment, by selecting reasonable standards to screen target test cases and / or newly added target test cases, and effectively storing them in the library, it is possible to ensure that the test case set is minimized, provide more effective candidate cases for testing, and thus improve test efficiency. In this embodiment, the incremental coverage generated by the test cases is introduced, and the incremental coverage is used as the judgment standard for whether to store the test cases in the library. That is, the target test cases added to the use case library are screened based on the incremental coverage, so as to achieve the screening of historical test cases and / or newly added test cases, etc., reduce the use case library, and improve test efficiency, in order to select the minimum set for storage, ensure that the test case library is minimized, and improve test efficiency.

[0097] In one embodiment, after adding the target test case to the pre-built test case library, the following steps may also be performed:

[0098] In response to a user's test case recommendation request, obtaining code change information from the recommendation request; wherein the code change information includes a code change file number and a code change line number;

[0099] Filtering target test cases corresponding to the code change information from the use case library to obtain test cases to be recommended;

[0100] The test case to be recommended is sent to the user.

[0101] When a user needs to test any target application, the user can initiate a recommendation request for the test cases required to test the target application to the server. The recommendation request includes the code change information of the target application. The server responds to the user's test case recommendation request and obtains the code change information from the recommendation request. The code change information refers to the relevant information of the code changes, including the code change part and the code change file number corresponding to the code change part. The so-called code change part includes the code change line number. The code change file number is used to identify the code file where the code change part is located, and the code change line number is used to identify the code line information where the code change department is located.

[0102] Specifically, when the target application undergoes version iteration or code changes, the server can obtain the code change file number and code change line number where the code change occurs. Specifically, the code change file number and code change line number can be obtained through a code snapshot to obtain code change information, wherein the code snapshot here is used to record code files and codes, and the code file number and the specific code line number where the change occurs can be quickly found through the code snapshot, and then the target test cases corresponding to the code change information are filtered out from the use case library to obtain the test cases to be recommended, and the test cases to be recommended are sent to the user. The correspondence between the code change information and the target test cases is pre-established in the use case library, and the target test cases corresponding to the code change information are obtained based on the correspondence.

[0103] In one embodiment, sending the test case to be recommended to the user may specifically include:

[0104] When it is detected that there are multiple test cases to be recommended, obtaining the code coverage of each test case to be recommended;

[0105] Sorting all the test cases to be recommended in descending order of code coverage to obtain a sorting result;

[0106] According to the sorting result, the code coverage rate ranked first is used as the target code coverage rate;

[0107] The test cases to be recommended corresponding to the target code coverage are recommended to the user.

[0108] This embodiment obtains the code coverage of each test case to be recommended, sorts the obtained code coverage in descending order, and takes the code coverage ranked first as the target code coverage according to the sorting result. Then, the recommended test case corresponding to the target code coverage is used as the recommended test case that needs to be recommended to the user, thereby achieving accurate judgment on whether the recommended test case meets the test requirements and ensuring the reliability of the test case recommendation results.

[0109] In one embodiment, calculating the code coverage of each test case when testing the application may specifically include:

[0110] When the application loads the application code according to each test case, determining the class file to be loaded of the application;

[0111] Performing bytecode modification on the class file to be loaded to obtain a modified class file to be executed of the application program;

[0112] Obtain the executed code through the class file to be executed;

[0113] The code coverage of the test case is calculated based on the executed code.

[0114] In this embodiment, when the application runs according to each test case, it first loads the part of the code that needs to be executed, that is, the part of the code corresponding to the application function that needs to be tested. At this time, the JavaAgent (Java agent) is used to intercept the loading of the code that the application needs to load and execute, and the class file (Javaclass file, class file) in the intercepted code is determined as the class file to be loaded by the application.

[0115] Among them, the full name of the class file is Java class file. The task of the class file in terms of platform independence is to provide binary services for Java programs that are independent of the underlying host platform. Java Agent is an interceptor that runs before the main method. The default method of Java Agent is called premain (the method before the main method). Therefore, Java Agent can be used to intercept the loading process of the class file to be loaded, so that the JVM can inject code into the class file when loading the class file.

[0116] When the Java Agent intercepts the application's to-be-loaded class file, it modifies the bytecode of the application's to-be-loaded class file without changing the execution target of the application's to-be-loaded class file, and then automatically packages it to obtain the application's to-be-executed class file. The application's to-be-executed class file is equivalent to adding timers before and after the method in the application code. If the application executes the to-be-executed class file, the to-be-executed class file will record the execution time of the method, indicating that the current test case covers the application's to-be-executed code (executed code) corresponding to the application's to-be-executed class file. If the test case does not cover the application code corresponding to the method (that is, it does not cover the to-be-executed class file), the to-be-executed class file will not have the time record, thereby enabling the class file to obtain the function of monitoring whether the code is executed.

[0117] After the JVM loads the application's pending class files, the application is tested according to the current test case, executing a portion of the code in the pending class files. This portion represents the application's executed code. If the application executes the pending class files, the current test case covers the pending code (executed code) corresponding to the pending class files. The time it takes for the processor to execute the application's code reflects the application's code execution trajectory. After determining the application's executed code from the application's class files, the code coverage of the current test case can be accurately calculated based on the obtained application's executed code.

[0118] Reference Figure 2 , an embodiment of the present application further provides an application testing device, comprising:

[0119] An acquisition module 11 is configured to acquire a test case set and test the application program in sequence using each test case in the test case set;

[0120] A calculation module 12 is used to calculate the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0121] A first screening module 13 is configured to, when there are test cases whose code coverage is lower than a preset coverage, screen out the test cases whose code coverage is lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0122] A determination module 14 is configured to determine a distribution relationship between each of the first test cases and the called code;

[0123] A collection module 15 is used to collect the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0124] A second screening module 16 is configured to screen out the code of the application that is not called during the test based on the total distribution relationship to obtain the target code;

[0125] An adjustment module 17 is configured to adjust the first test case of the test case set according to the target code to obtain a target test case;

[0126] The retest module 18 is configured to retest the application program using the target test case to obtain a test result.

[0127] After acquiring a test case set in this embodiment, the test case set typically includes multiple test cases, each of which tests a specific function of the application, such as the application's display. Therefore, each pre-edited test case in the test case set is used to test the application separately to test the application's execution.

[0128] In one embodiment, a weight may also be set for each test case in the test case set, where the weight is proportional to the importance of the test case. When testing an application, the corresponding test cases are called in order according to the weight to test the application, so as to give priority to testing important items of the application.

[0129] In software engineering, a test case is a set of conditions or variables that testers use to determine whether an application or software system functions correctly. A test case is a scientifically organized summary of application testing activities, designed to transform them into a manageable model. It also serves as a method for quantifying testing, with different test cases for different application categories. The method for determining whether an application or system passes testing is called a test criterion.

[0130] This embodiment uses a code coverage statistics service to calculate the code coverage of a single test case. Code coverage is an important indicator of the degree to which a test case covers the application under test. It is a reference value used to measure test completeness. Its value is equal to the code covered by the test divided by the total code. This embodiment uses code coverage data to assess the adequacy of testing.

[0131] This embodiment can separately determine whether the code coverage of each test case is lower than the preset coverage. The preset coverage can be customized as needed. When there are test cases with code coverage lower than the preset coverage, the test cases with code coverage lower than the preset coverage are filtered out from the test case set, and the test cases with code coverage lower than the preset coverage are used as the first test cases.

[0132] This embodiment determines the distribution relationship between each first test case and the called code, that is, which codes of the application program are called by each first test case, wherein the distribution relationship is used to reflect the code corresponding to each test case.

[0133] This embodiment summarizes the distribution relationship between each test case and the code, merges the repeated parts, and obtains the total distribution relationship. Based on the total distribution relationship, the code that was not called by the application during the test is screened out, and the code that was not called by the application during the test is used as the target code. This makes it easy to find which codes are not covered and which test case designs are repeated, providing a basis for increasing, reducing, and optimizing test cases, thereby adjusting the test cases of the test case set according to the target code.

[0134] This embodiment adjusts the first test case in the test case set based on the target code, uses the adjusted first test case as the target test case, and enables the target test case to call part or all of the target code when testing the application. Finally, the application is retested using the target test case to obtain test results. The test results include whether each function of the application operates as expected.

[0135] As described above, it can be understood that the various components of the application testing device proposed in this application can realize the functions of any of the application testing methods described above, and the specific structure will not be repeated.

[0136] Reference Figure 3 , the embodiment of the present application also provides a computer device, the internal structure of which can be as follows Figure 3 The computer device includes a processor, a memory, a network interface, and a database connected via a system bus. The processor of the computer is used to provide computing and control capabilities.

[0137] The computer device's memory includes a storage medium and internal memory. The storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operating system and computer program in the storage medium to run. The computer device's database is used to store data such as test cases.

[0138] The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by a processor, an application program testing method is implemented.

[0139] The processor executes the application testing method, including:

[0140] Obtaining a test case set, and testing the application program in sequence using each test case in the test case set;

[0141] Calculating the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0142] When there are test cases with code coverage lower than the preset coverage, filter out the test cases with code coverage lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0143] Determining a distribution relationship between each of the first test cases and the called code;

[0144] Gathering the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0145] Filter out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code;

[0146] Adjust the first test case of the test case set according to the target code to obtain a target test case;

[0147] The application is retested using the target test case to obtain a test result.

[0148] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, an application program testing method is implemented, including the steps of:

[0149] Obtaining a test case set, and testing the application program in sequence using each test case in the test case set;

[0150] Calculating the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code;

[0151] When there are test cases with code coverage lower than the preset coverage, filter out the test cases with code coverage lower than the preset coverage from the test case set to obtain a plurality of first test cases;

[0152] Determining a distribution relationship between each of the first test cases and the called code;

[0153] Gathering the distribution relationships of all the first test cases and codes to obtain a total distribution relationship;

[0154] Filter out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code;

[0155] Adjust the first test case of the test case set according to the target code to obtain a target test case;

[0156] The application is retested using the target test case to obtain a test result.

[0157] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double-speed data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0158] In summary, the greatest beneficial effects of this application are:

[0159] The present application provides an application testing method, apparatus, computer device, and storage medium. Each test case in an acquired test case set is used to sequentially test an application, and the code coverage of each test case when testing the application is calculated. When a test case with a code coverage lower than a preset coverage exists, a first test case with a code coverage lower than the preset coverage is screened out from the test case set. The distribution relationship between each first test case and the called code is determined. The distribution relationships between all first test cases and the code are aggregated to obtain a total distribution relationship. Based on the total distribution relationship, code that was not called during the test of the application is screened out to obtain a target code. The first test case in the test case set is adjusted as a target test case based on the target code. The application is retested using the target test case to obtain a test result. The distribution relationship between the test case and the code is determined by calculating the code coverage, so that the code that was not called during the test of the application is accurately determined based on the total distribution relationship between all test cases and the code. The test case is adjusted to eliminate the influence of personal factors such as personal experience and development test records. This is more objective, and the test scope is more accurate than manual evaluation, avoiding missed tests and improving the accuracy of application testing.

[0160] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, apparatus, article, or method comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, apparatus, article, or method. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, apparatus, article, or method comprising the element.

[0161] The above description is only a preferred embodiment of the present application and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. An application testing method, characterized in that: include: Obtaining a test case set, and testing the application program in sequence using each test case in the test case set; Calculating the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code; When there are test cases with code coverage lower than the preset coverage, filter out the test cases with code coverage lower than the preset coverage from the test case set to obtain a plurality of first test cases; Determining a distribution relationship between each of the first test cases and the called code; Gathering the distribution relationships of all the first test cases and codes to obtain a total distribution relationship; Filter out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code; Adjust the first test case of the test case set according to the target code to obtain a target test case; Retesting the application using the target test case to obtain a test result; The step of adjusting the first test case of the test case set according to the target code to obtain a target test case includes: Determine a first test case in the test case set that is related to the target code, and obtain a second test case; Obtaining the source code of the second test case; Comparing the source code with the target code to obtain code difference information; Adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain a target test case; The code difference information includes incremental information, and adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain the target test case includes: Determine method information where the incremental information is located according to the incremental information of the code difference information; Recursively querying the first method information that calls the method information based on the method information, and using the first method information finally found in the recursive query as the target method information; wherein the target method information is used to represent the impact range of the new content added between the current version and the previous version of the application; A second test case that must be adjusted is determined according to the distribution relationship and the target method information, and a target test case is obtained after adjusting the second test case that must be adjusted.

2. The method according to claim 1, characterized in that After retesting the application using the target test case and obtaining the test result, the method further includes: Obtaining a change code for the application; Determining the incremental coverage of the target test case on the changed code, wherein the incremental coverage represents the coverage of the changed code when the application executes the target test case; Determining whether the incremental coverage ratio is greater than a preset incremental coverage ratio; If so, the target test case is added to the pre-built test case library.

3. The method according to claim 2, characterized in that After adding the target test case to the pre-built test case library, the method further includes: In response to a user's test case recommendation request, obtaining code change information from the recommendation request; wherein the code change information includes a code change file number and a code change line number; Filtering target test cases corresponding to the code change information from the use case library to obtain test cases to be recommended; The test case to be recommended is sent to the user.

4. The method according to claim 3, characterized in that The sending the test case to be recommended to the user includes: When it is detected that there are multiple test cases to be recommended, obtaining the code coverage of each test case to be recommended; Sort all the test cases to be recommended in descending order of code coverage to obtain a sorting result; According to the sorting result, the code coverage rate ranked first is used as the target code coverage rate; The test cases to be recommended corresponding to the target code coverage are recommended to the user.

5. The method according to claim 1, wherein Calculating the code coverage of each test case when testing the application includes: When the application loads the application code according to each test case, determining the class file to be loaded of the application; Performing bytecode modification on the class file to be loaded to obtain a modified class file to be executed of the application program; Obtain the executed code through the class file to be executed; The code coverage of the test case is calculated based on the executed code.

6. An application testing device, characterized in that: include: An acquisition module, configured to acquire a test case set, and test the application program in sequence using each test case in the test case set; A calculation module, configured to calculate the code coverage of each test case when testing the application; wherein the code coverage is the ratio of the code of the application called by the test case when testing the application to the total code; A first screening module is configured to, when there are test cases whose code coverage is lower than a preset coverage, screen out the test cases whose code coverage is lower than the preset coverage from the test case set to obtain a plurality of first test cases; A determination module, configured to determine a distribution relationship between each of the first test cases and the called code; A collection module, configured to collect the distribution relationships of all the first test cases and codes to obtain a total distribution relationship; A second screening module is used to screen out the code of the application program that is not called during the test based on the total distribution relationship to obtain the target code; An adjustment module, configured to adjust the first test case of the test case set according to the target code to obtain a target test case; A retesting module, configured to retest the application using the target test case to obtain a test result; The step of adjusting the first test case of the test case set according to the target code to obtain a target test case includes: Determine a first test case in the test case set that is related to the target code, and obtain a second test case; Obtaining the source code of the second test case; Comparing the source code with the target code to obtain code difference information; Adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain a target test case; The code difference information includes incremental information, and adjusting the source code of the second test case according to the distribution relationship of the second test case and the code difference information to obtain the target test case includes: Determine method information where the incremental information is located according to the incremental information of the code difference information; Recursively querying the first method information that calls the method information based on the method information, and using the first method information finally found in the recursive query as the target method information; wherein the target method information is used to represent the impact range of the new content added between the current version and the previous version of the application; A second test case that must be adjusted is determined according to the distribution relationship and the target method information, and a target test case is obtained after adjusting the second test case that must be adjusted.

7. A computer device, characterized in that: include: processor; Memory; The memory stores a computer program, and the processor implements the application testing method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the application testing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Precise coverage testing method and system based on modularized distributed system

    CN112817865A

  • Interface test method, device and equipment in code iterative update

    CN113626325A