Code coverage testing method, device and electronic device for application program

By independently testing each subservice function of the application, obtaining its code coverage information, and combining this information to determine the overall code coverage information of the application to be tested, the problem of reliability and comprehensiveness of the code coverage information completion in the prior art is solved, and higher accuracy and reliability are achieved.

CN112685298BActive Publication Date: 2025-04-04BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011568395.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-25
Publication Date
2025-04-04
Estimated Expiration
2040-12-25

AI Technical Summary

Technical Problem

The reliability and comprehensiveness of the completion are relatively low when obtaining code coverage information for application subservice functions in the prior art.

Method used

By listening to test requests, each subservice function of the to-test application is independently tested, the code coverage information of each subservice function is obtained, and the overall code coverage information of the to-test application is determined based on this information.

Benefits of technology

It improves the accuracy and reliability of the code coverage information of each sub-service function, thereby improving the reliability of the code coverage information of the application to be tested and enhancing the utilization rate of code resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112685298B_ABST
    Figure CN112685298B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, electronic device, storage medium and program product for code coverage testing of an application, and relates to information flow in the field of computer technology, and the field of big data. The specific implementation scheme is: monitoring test requests, wherein the test request is used to request testing of at least one sub-service function of the application to be tested, the application to be tested has multiple sub-service functions, each sub-service function indicated by the test request is tested separately, and the code coverage information of each sub-service function is obtained, and the code coverage information of the application to be tested is determined according to the code coverage information of each sub-service function, and by testing each sub-service function, the code coverage information corresponding to each sub-service function is obtained, so that the flexibility and diversity of code testing can be achieved, and the accuracy of the code coverage information of any sub-service function determined can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device, storage medium and program product for code coverage testing of an application program, which can be used in the fields of information flow and big data. Background Art

[0002] With the development of the Internet and computer technology, there have been new breakthroughs in the related technologies of application testing. Code coverage information, such as code coverage, is a metric in application testing.

[0003] In the prior art, code coverage information is usually obtained by instrumenting, compiling and executing the test code based on the golang tool chain. However, the code coverage information obtained based on this method is mixed coverage information. In order to obtain the code coverage information corresponding to different sub-service functions of the application, it is usually completed on the basis of the mixed coverage information.

[0004] However, the above method may cause the problem of low reliability and comprehensiveness of completion. Summary of the invention

[0005] The present application provides a method, device, electronic device, storage medium and program product for improving the code coverage testing of an application program for determining code coverage information of a sub-service function.

[0006] According to one aspect of the present application, a method for code coverage testing of an application is provided, comprising:

[0007] Monitoring a test request, wherein the test request is used to request testing of at least one sub-service function of an application to be tested, and the application to be tested has multiple sub-service functions;

[0008] Testing each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function;

[0009] The code coverage information of the application to be tested is determined according to the code coverage information of each sub-service function.

[0010] According to another aspect of the present application, a code coverage testing device for an application is provided, comprising:

[0011] A monitoring module, used for monitoring a test request, wherein the test request is used for requesting to test at least one sub-service function of the application to be tested, and the application to be tested has multiple sub-service functions;

[0012] A testing module, used to test each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function;

[0013] The first determining module is used to determine the code coverage information of the application to be tested according to the code coverage information of each sub-service function.

[0014] According to another aspect of the present application, there is provided an electronic device, including:

[0015] at least one processor; and

[0016] a memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the above embodiment.

[0018] According to another aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the above embodiment.

[0019] According to another aspect 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 computer program implements the method according to the above embodiment.

[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.

[0022] Figure 1 is a schematic diagram according to the first embodiment of the present application;

[0023] Figure 2 is a schematic diagram according to a second embodiment of the present application;

[0024] Figure 3 is a schematic diagram according to a third embodiment of the present application;

[0025] Figure 4 is a schematic diagram according to a fourth embodiment of the present application;

[0026] Figure 5 is a schematic diagram according to a fifth embodiment of the present application;

[0027] Figure 6 is a schematic diagram according to a sixth embodiment of the present application;

[0028] Figure 7 is a schematic diagram according to a seventh embodiment of the present application;

[0029] Figure 8 is a schematic diagram according to an eighth embodiment of the present application;

[0030] Fig. 9 It is a schematic diagram according to the ninth embodiment of the present application. DETAILED DESCRIPTION

[0031] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0032] With the development of the Internet and computer technology, the number of applications has increased rapidly, and applications are written based on codes to realize corresponding application services, such as communication services, shopping services, accommodation services, and travel services.

[0033] In order to improve the reliable operation of the application, after the application is completed based on the code writing, the application can be tested, and code coverage information, such as code coverage rate, is a metric in application testing.

[0034] The code coverage rate represents the proportion and degree of the code in the application being tested. For example, if a certain application consists of n lines of code, and m lines of code are run during the testing of the application, then the code coverage rate is m / n.

[0035] Correspondingly, if the code coverage is higher, it means that the utilization rate of the code in the application is higher; if the code coverage is lower, it means that the utilization rate of the code in the application is lower. If the utilization rate is low, it means that the redundancy of the code in the application is large, and the code can be adaptively adjusted to improve the utilization rate of code resources.

[0036] It is worth noting that an application may include multiple sub-service functions, such as a communication application may include: a sub-service function for obtaining address book information and a conversation sub-service function, etc. That is, different sub-service functions of the application are implemented based on the corresponding code.

[0037] In the related art, when performing code coverage testing on an application, all codes of the application are usually tested to obtain mixed coverage information. When code coverage information of a sub-service function is required, it is necessary to complete it based on the mixed coverage information.

[0038] For example, a communication application includes: a sub-service function for obtaining address book information and a conversation sub-service function. When the code coverage test is performed on the communication application, all the codes of the communication application are tested, that is, the tested code includes: the code of the sub-service function for obtaining address book information and the code of the conversation sub-service function. The obtained code coverage information is a mixed coverage information including: the code coverage information of the sub-service function for obtaining address book information and the code coverage information of the conversation sub-service function. If it is necessary to determine the code coverage information of the sub-service function for obtaining address book information, it is necessary to perform corresponding processing on the basis of the mitigated coverage information, such as completion, so as to obtain the code coverage information of the sub-service function for obtaining address book information.

[0039] However, the code coverage information obtained through completion and other methods may cause the accuracy and reliability of the code coverage information to be low.

[0040] The inventor of the present application has obtained the inventive concept of the present application through creative work: monitoring the test request and testing each sub-service function of the application to obtain the code coverage information corresponding to each sub-service function.

[0041] Based on the above-mentioned inventive concept, the present application provides a code coverage testing method, device, electronic device, storage medium and program product for an application, which are applied to the information flow and big data fields in the field of computer technology to achieve the accuracy and reliability of the code coverage information corresponding to each sub-service function.

[0042] Figure 1 is a schematic diagram according to the first embodiment of the present application, such as Figure 1 As shown, the code coverage testing method of the application program of this embodiment includes:

[0043] S101: Listening for a test request, wherein the test request is used to request testing of at least one sub-service function of an application to be tested, and the application to be tested has multiple sub-service functions.

[0044] Exemplarily, the execution subject of this embodiment can be a code coverage test device of an application (hereinafter referred to as the test device), and the test device can be a computer, a server (including a local server and a cloud server), a terminal device, a processor, and a chip, etc., which is not limited in this embodiment.

[0045] Based on the above examples, it can be known that the application to be tested may include multiple sub-service functions, such as a sub-service function for obtaining contact information, a conversation sub-service function, a sub-service function for obtaining data, and a sub-service function for accessing a database, etc. Accordingly, a test request can be used to request a test of a sub-service function of the application to be tested, for example, a test request can be used to test a sub-service function for obtaining contact information; a test request can also be used to request a test of multiple sub-service functions of the application to be tested, for example, a test request can be used to test a sub-service function for obtaining contact information and a conversation sub-service function.

[0046] S102: Test each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function.

[0047] In one example, if the test request indicates that a sub-service function is to be tested, the test device tests the sub-service function to obtain code coverage information of the sub-service function.

[0048] In another example, if the test request indicates to test multiple sub-service functions, the test device tests each of the multiple sub-service functions respectively to obtain code coverage information corresponding to each of the multiple sub-service functions.

[0049] It is worth noting that, in the present embodiment, after receiving the test request, each sub-service function indicated by the test request is tested separately to obtain the code coverage information of each sub-service function, thereby achieving accurate and reliable determination of the code coverage information of each sub-service function, thereby achieving adaptive adjustment and modification of the code of each service function based on the code coverage information of each sub-service function, thereby achieving the technical effect of improving code utilization and improving the operating efficiency of the application to be tested.

[0050] S103: Determine the code coverage information of the application program to be tested according to the code coverage information of each sub-service function.

[0051] After the testing device determines the code coverage information of each sub-service function, the testing device may determine the code coverage information of the application to be tested based on each code coverage information.

[0052] Based on the above analysis, it can be seen that an embodiment of the present application provides a code coverage testing method for an application, the method comprising: monitoring test requests, wherein the test request is used to request testing of at least one sub-service function of the application to be tested, the application to be tested has multiple sub-service functions, each sub-service function indicated by the test request is tested separately, and code coverage information of each sub-service function is obtained, and code coverage information of the application to be tested is determined according to the code coverage information of each sub-service function, and by testing each sub-service function indicated by the test request separately to obtain the code coverage information corresponding to each sub-service function, the accuracy and reliability of the determined code coverage information of each sub-service function can be improved, and by determining the code coverage information of the application to be tested based on the code coverage information corresponding to each sub-service function, the technical effect of the reliability of the determined code coverage information of the application to be tested can be improved.

[0053] Figure 2 is a schematic diagram according to the second embodiment of the present application, such as Figure 2 As shown, the code coverage testing method of the application program of this embodiment includes:

[0054] S201: Listening for a test request, wherein the test request is used to request testing of at least one sub-service function of an application to be tested, and the application to be tested has multiple sub-service functions.

[0055] For example, the description of S201 may refer to S101, which will not be repeated here.

[0056] In some embodiments, the test request may be monitored by a reverse proxy.

[0057] Now combined Figure 3 The application scenario shown in FIG. 1 is an exemplary description of the reverse proxy method used in this embodiment. Figure 3 In the application scenario shown:

[0058] Client 301 (such as Figure 3 The desktop computer shown in the figure, of course the client can also be other user terminals, such as laptops and mobile terminals, etc.) is connected to the reverse proxy server 303 through the Internet 302, and the user 304 can send a test request to the server 305 on the internal network through the client 302 and the reverse proxy server 303.

[0059] The proxy server 303 may monitor a test request sent by a user 304 to a server 305 on the internal network through the Internet 302 based on the client 302 .

[0060] That is, in some embodiments, the test device may include: a proxy server and a server on an internal network, and the proxy server monitors the test request.

[0061] Accordingly, in combination with the above examples, it can be seen that the execution subject of this embodiment may include multiple servers, such as Figure 3 The proxy server and the server on the internal network are shown in the figure, and the proxy server monitors the test request, and the server on the internal network executes the test of the corresponding sub-service function.

[0062] It is worth noting that the above examples are only used to illustrate application scenarios to which the present embodiment may be applicable, and should not be construed as limiting the application scenarios of the present embodiment.

[0063] S202: Determine a thread corresponding to executing each sub-service function from a plurality of threads used to execute the test request.

[0064] For example, in combination with the above example, if the application to be tested includes: a sub-service function for obtaining address book information and a conversation sub-service function, the testing device determines from multiple threads a thread for executing the sub-service function for obtaining address book information, and determines from multiple threads a thread for executing the conversation sub-service function, and the thread for executing the sub-service function for obtaining address book information and the thread for executing the conversation sub-service function are two different threads.

[0065] It is worth noting that, in the present embodiment, there are multiple threads for executing test requests, and each thread has an independent memory space. The threads with independent memory space are isolated from each other, and the threads do not interfere with each other when executing their corresponding sub-service functions, thereby achieving the technical effect of accuracy and reliability of the code coverage information of each sub-service function when each sub-service function is executed based on the thread corresponding to each sub-service function.

[0066] In some embodiments, S202 may include: based on a preset scheduling period, selecting a thread corresponding to executing each sub-service function from various threads.

[0067] Exemplarily, the scheduling period can be understood as the scheduling frequency of each thread, which can be a frequency in time or a frequency in number. For example, the frequency in time can be understood as: scheduling each thread based on time, such as calling a thread once every preset time interval, etc.; for another example, the frequency in number can be understood as: calling the current thread after calling each thread once, etc.

[0068] Specifically, the testing device may pre-sort the scheduling order of each thread, and select a thread corresponding to each sub-service function from each thread in turn based on the sorting.

[0069] In some embodiments, the testing device may test the running performance of each thread in advance, and determine the scheduling period based on the running performance of each thread, that is, determine the order of scheduling each thread.

[0070] For example, for threads with better performance, the testing device preferentially selects them; conversely, for threads with worse performance, the testing device selects the threads with worse performance after selecting the threads with better performance.

[0071] That is, each thread can be sorted based on its running performance. If it is sorted in ascending order based on the running performance, the test device will select threads from the end of the sorting when selecting threads; if it is sorted in descending order based on the running performance, the test device will select threads from the beginning of the sorting when selecting threads.

[0072] In this embodiment, by selecting a thread corresponding to each sub-service function from various threads based on a scheduling cycle, a technical effect of quickly and conveniently calling the thread can be achieved.

[0073] In some embodiments, when no test request is detected, the state of each thread is in a sleep state, and based on a preset scheduling cycle, a thread corresponding to each sub-service function is selected from each thread to execute, including: based on the scheduling cycle, waking up the thread that executes each sub-service function from each thread, and executing each sub-service function based on the awakened thread.

[0074] Exemplarily, the test device may be provided with a scheduler and multiple threads, and the scheduler may be used to implement the calling of the multiple threads. For example, the scheduler may be understood as a parent thread, and the multiple threads may be understood as multiple child threads, and the calling of the multiple child threads is completed based on the parent thread.

[0075] In some embodiments, thread calling can be implemented based on Unix sockets, such as multi-thread pooling can be transformed into a thread pool, which is similar to the concept of a buffer in an operating system, and the test device wakes up and calls the corresponding thread from the thread pool based on a scheduling cycle.

[0076] In this embodiment, the state of each thread may include two types, one is a sleeping state and the other is a wake-up state. The initial state of each thread may be a sleeping state. For example, each thread is in a sleeping state before being called, that is, before the test device detects a test request and there is no application to be tested, each thread is in a sleeping state. When the test device detects a test request, the test device can, based on a scheduling cycle, wake up the thread that executes each sub-service function from each thread in each sleeping state, thereby executing each sub-service function based on the awakened thread.

[0077] For example, in combination with the above example, if the number of threads is n, where n is a positive integer greater than 1, then before the test device detects the application to be tested, the n threads are in a sleep state. If the test device detects the application to be tested, and the application to be tested includes: a sub-service function for obtaining address book information and a conversation sub-service function, then the test device, based on the scheduling cycle, wakes up the thread for executing the sub-service function for obtaining address book information from the n threads, and executes the sub-service function for obtaining address book information based on the awakened thread, and wakes up the thread for executing the conversation sub-service function from the (n-1) sleeping threads (excluding the thread for executing the sub-service function for obtaining address book information), and executes the conversation sub-service function based on the awakened thread.

[0078] It is worth noting that in this embodiment, when the testing device does not detect a test request, each thread is in a sleep state. When a test request is detected, at least some of the threads in the sleep state are awakened, so that at least some of the threads in the sleep state are in an awake state, thereby completing the feedback of the test request and achieving the technical effect of saving resources.

[0079] In some embodiments, after executing each sub-service function based on the awakened thread, the testing device may adjust the state of the awakened thread to a sleep state.

[0080] For example, in combination with the above example, after the test device executes the sub-service function of obtaining the address book information based on the awakened thread, the state of the thread is adjusted from the awakened state to the sleeping state.

[0081] It is worth noting that, in this embodiment, by switching the state of the awakened thread from the awakened state to the sleep state after the awakened thread executes the corresponding sub-service function, it is possible to achieve the technical effect of reducing resource consumption and achieving resource utilization.

[0082] In some embodiments, if all threads are in the awake state, the method may further include: determining the load of each thread, selecting a thread with the smallest load from among the threads, and determining it as the thread for executing each sub-service function.

[0083] For example, in combination with the above example, if the number of threads is n, and all n threads are in an awake state, that is, all n threads are executing corresponding sub-service functions, then the testing device can determine the load of each of the n threads, obtain n loads, and select the minimum load from the n loads, and determine the thread corresponding to the minimum load, and determine the thread corresponding to the minimum load as the thread that executes each sub-service function.

[0084] In some embodiments, if there are multiple minimum loads, that is, multiple threads have the same load, the testing device can randomly select a thread corresponding to a minimum load, and determine the randomly selected thread corresponding to the minimum load as the thread that executes each sub-service function; or, the testing device can select the thread with the best running performance from the threads corresponding to each minimum load based on the historical running performance of the threads corresponding to each minimum load, and execute each sub-service function based on the thread with the best running performance.

[0085] It is worth noting that, in this embodiment, by selecting the thread with the smallest load from each thread and determining it as the thread for executing each sub-service function, resource utilization can be improved, so that the operating performance of each thread can be optimized.

[0086] S203: Based on the thread corresponding to each sub-service function, test each sub-service function to obtain code coverage information corresponding to each sub-service function.

[0087] For example, in combination with the above example, based on the thread corresponding to the sub-service function of obtaining contact information, the sub-service function of obtaining contact information is tested to obtain code coverage information corresponding to the sub-service function of obtaining contact information.

[0088] Exemplarily, the code coverage information corresponding to each sub-service function can be obtained by inserting code sequence stubs. For example, some probes (also called "probes", which are essentially code segments for information collection, which can be assignment statements or function calls for collecting coverage information) are inserted into the code corresponding to the sub-service function for obtaining address book information. The probes are executed and feature data of code operation is thrown out. By analyzing these data, the control flow and data flow information of the code can be obtained, and then the code coverage information, such as code coverage rate, can be obtained.

[0089] S204: Determine the code coverage information of the application program to be tested according to the code coverage information of each sub-service function.

[0090] For example, the description of S204 may refer to S103, which will not be repeated here.

[0091] Figure 4 is a schematic diagram according to the fourth embodiment of the present application, such as Figure 4 As shown, the code coverage testing method of the application program of this embodiment includes:

[0092] S401: Listening for a test request, wherein the test request is used to request testing of at least one sub-service function of an application to be tested, and the application to be tested has multiple sub-service functions.

[0093] For example, the description of S401 may refer to S101, which will not be repeated here.

[0094] S402: Determine, from among the threads for executing the test request, a thread corresponding to each sub-service function, and determine an association relationship between each sub-service function and the corresponding thread.

[0095] In one example, the testing device can split the test request into multiple sub-test requests based on the sub-service functions. For different sub-test requests, the testing device can put a characteristic value in each sub-test request. The characteristic value can be understood as a unique identifier for each test request, which is used to distinguish different sub-test requests.

[0096] Exemplarily, the test request is a test request for an application to be tested, and the application to be tested includes multiple sub-service functions. The testing device can split the application to be tested based on each sub-service function, obtain sub-test requests corresponding to each sub-service function, and put a characteristic value in each sub-test request to distinguish it from other sub-test requests.

[0097] It is worth noting that the characteristic value of the sub-test request may be related to the sub-service function of the sub-test request, or may be a randomly assigned characteristic value, which is not limited in this embodiment.

[0098] Accordingly, the testing device may determine a corresponding thread for each sub-test request, so as to execute each test request based on the determined corresponding thread, that is, execute each sub-service function.

[0099] In another example, the testing device may split the test request into multiple sub-test requests based on the sub-service function, and for different sub-test requests, the association relationship between the sub-test request and the thread may be recorded.

[0100] Exemplarily, the test device allocates a thread to each sub-test request and determines the association between the sub-test request and the thread. For example, this can be achieved by means of identification, such as assigning the same identification to the sub-test request and the thread, so that when the thread feeds back code coverage information, the sub-test request with the same identification can be determined based on the identification of the thread, thereby determining the code coverage information as the code coverage information of the sub-test request with the same identification, thereby determining the code coverage information corresponding to the sub-service function.

[0101] Of course, the same identifier may also be assigned to each sub-service function and the thread corresponding thereto, so that the code coverage information corresponding to each sub-service function is determined based on the same identifier.

[0102] It is worth noting that, in combination with the above examples, the test request monitored by the test device can also be a test request corresponding to a sub-service function. Accordingly, the test device can monitor the test requests corresponding to multiple sub-service functions, that is, the test device monitors multiple test requests, and each of the multiple test requests is a code coverage test of a sub-service function. The test device can also determine the code coverage information corresponding to each test request based on the method in the above example, that is, determine the code coverage information of each sub-service function.

[0103] In other embodiments, the test request monitored by the testing device may be a test of multiple sub-service functions. For example, the application to be tested includes: a sub-service function for obtaining address book information, a conversation sub-service function, and a sub-service function for reading a database, and the test request may be a test indicating a sub-service function for obtaining address book information and a conversation sub-service function. The testing device may use the above-mentioned embodiment to select a thread for the test request and determine the code coverage information of the test request, that is, determine the code coverage information of the sub-service function for obtaining address book information and the conversation sub-service function.

[0104] S403: Based on the thread corresponding to each sub-service function, test each sub-service function to obtain code coverage information corresponding to each sub-service function.

[0105] In combination with the above example, this step can be understood as: the testing device executes each sub-test request based on the thread corresponding to each sub-test request, thereby completing the test of each sub-service function and obtaining the code coverage information corresponding to each sub-service function.

[0106] S404: Determine a mapping relationship according to the code coverage information of each sub-service function, where the mapping relationship represents a mapping relationship between different sub-service functions and different code coverage information.

[0107] For example, in combination with the above example, there is an association relationship between each sub-service function and the corresponding thread. When the testing device receives the code coverage information fed back by the thread, it can determine the sub-service function corresponding to the received code coverage information based on the association relationship, and establish a mapping relationship between the sub-service function and the code coverage information.

[0108] For example, when a thread executes a corresponding sub-test request and obtains the corresponding code coverage information, the corresponding feature value can be placed in the code coverage information. The testing device can determine the corresponding sub-test request based on the feature value in the code coverage information, and determine the corresponding sub-service function, thereby establishing a mapping relationship between the sub-service function and the code coverage information.

[0109] In some embodiments, the code of the application program to be tested may be adjusted based on the mapping relationship.

[0110] It is worth noting that, in this embodiment, by determining the mapping relationship between each sub-service function and its corresponding code coverage information, the code corresponding to at least part of the sub-service functions can be adjusted based on the mapping relationship, thereby achieving the technical effect of deleting redundant code, reducing the running time of the application to be tested, and improving the reliability of the application to be tested.

[0111] S405: Determine the code coverage information of the application program to be tested according to the code coverage information of each sub-service function.

[0112] For example, the description of S405 may refer to S103, which will not be described again here.

[0113] Figure 5 is a schematic diagram according to the fifth embodiment of the present application, such as Figure 5 As shown, the code coverage testing device 500 for an application program of this embodiment includes:

[0114] The monitoring module 501 is used to monitor a test request, wherein the test request is used to request to test at least one sub-service function of the application to be tested, and the application to be tested has multiple sub-service functions.

[0115] The testing module 502 is used to test each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function.

[0116] The first determining module 503 is used to determine the code coverage information of the application program to be tested according to the code coverage information of each sub-service function.

[0117] Figure 6 is a schematic diagram according to the sixth embodiment of the present application, such as Figure 6 As shown, based on the fifth embodiment, the number of threads for executing the test request is multiple, and the test module 502 includes:

[0118] The thread determination submodule 5021 is used to determine the thread corresponding to executing each sub-service function.

[0119] The testing submodule 5022 is used to test each sub-service function based on the thread corresponding to each sub-service function, and obtain code coverage information corresponding to each sub-service function.

[0120] In some embodiments, the thread determination submodule is used to select a thread corresponding to each sub-service function from various threads based on a preset scheduling period.

[0121] In some embodiments, when no test request is detected, the state of each thread is in a sleep state; the thread determination submodule 5021 is used to wake up the thread that executes each sub-service function from each thread based on the scheduling cycle, and execute each sub-service function based on the awakened thread.

[0122] Figure 7 is a schematic diagram according to the seventh embodiment of the present application, such as Figure 7 As shown, based on the sixth embodiment, the test module further includes:

[0123] The adjustment module 5023 is used to adjust the state of the awakened thread to the sleep state after the awakened thread executes each sub-service function.

[0124] In some embodiments, all threads are in the awake state, and the thread determination submodule 5021 is used to determine the load of each thread, select the thread with the smallest load from each thread, and determine it as the thread that executes each sub-service function.

[0125] Figure 8 is a schematic diagram according to the eighth embodiment of the present application, such as Figure 8 As shown, based on the seventh embodiment, the code coverage testing device 500 further includes:

[0126] The second determining module 504 is used to determine a mapping relationship according to the code coverage information of each sub-service function, where the mapping relationship represents a mapping relationship between different sub-service functions and different code coverage information.

[0127] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.

[0128] Fig. 9 A schematic block diagram of an example electronic device 900 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0129] like Fig. 9As shown, the electronic device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the device 900 can also be stored. The computing unit 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0130] A number of components in the device 900 are connected to the I / O interface 905, including: an input unit 906, such as a keyboard, a mouse, etc.; an output unit 907, such as various types of displays, speakers, etc.; a storage unit 908, such as a disk, an optical disk, etc.; and a communication unit 909, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 909 allows the device 900 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0131] The computing unit 901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 901 performs the various methods and processes described above, such as a code coverage test method for an application. For example, in some embodiments, the code coverage test method for an application may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 908. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 900 via the ROM 902 and / or the communication unit 909. When the computer program is loaded into the RAM 903 and executed by the computing unit 901, one or more steps of the code coverage test method for the application described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to execute the code coverage test method for the application by any other appropriate means (e.g., by means of firmware).

[0132] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0133] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0134] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0135] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0136] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.

[0137] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.

[0138] According to another aspect of the embodiments of the present application, the embodiments of the present application further provide a computer program product, including a computer program, wherein when the computer program is executed by a processor, the method according to any of the above embodiments is implemented, such as when executed, Figure 1 , Figure 2 as well as Figure 4 The method shown in any one of the embodiments.

[0139] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.

[0140] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

Claims

1. A code coverage testing method for an application, comprising: Monitoring a test request, wherein the test request is used to request testing of at least one sub-service function of an application to be tested, and the application to be tested has multiple sub-service functions; Testing each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function; Determine the code coverage information of the application to be tested according to the code coverage information of each sub-service function; The number of threads used to execute the test request is multiple; each sub-service function indicated by the test request is tested respectively to obtain code coverage information of each sub-service function, including: Testing the running performance of each thread, and determining the scheduling period of each thread based on the running performance of each thread, wherein the scheduling period is the frequency of the number of scheduling times determined based on the running performance of each thread; Sorting the scheduling periods of the threads, and selecting a thread corresponding to executing each sub-service function from the threads in sequence based on the sorting; Based on the thread corresponding to each sub-service function, each sub-service function is tested to obtain code coverage information corresponding to each sub-service function; wherein the state of each thread includes a sleep state and a wake-up state, and when no test request is detected, the state of each thread is a sleep state; and selecting a thread corresponding to each sub-service function to execute from each thread includes: Based on the order of the scheduling cycles of the threads, wake up the thread that executes each sub-service function from the threads, and execute each sub-service function based on the woken thread; After testing each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function, the method further includes: Determine a mapping relationship according to the code coverage information of each sub-service function, wherein the mapping relationship represents a mapping relationship between different sub-service functions and different code coverage information; Based on the mapping relationship, the codes corresponding to at least some of the sub-service functions are adjusted.

2. The method according to claim 1, after executing each of the sub-service functions based on the awakened thread, the method further comprises: After the awakened thread executes each of the sub-service functions, the state of the awakened thread is adjusted to a sleep state.

3. The method according to claim 1, if all threads are in awake state, the method further comprises: The load of each thread is determined, and a thread with the smallest load is selected from each thread to be determined as the thread for executing each sub-service function.

4. A code coverage test device for an application, comprising: A monitoring module, used for monitoring a test request, wherein the test request is used for requesting to test at least one sub-service function of the application to be tested, and the application to be tested has multiple sub-service functions; A testing module, used to test each sub-service function indicated by the test request respectively to obtain code coverage information of each sub-service function; A first determining module, configured to determine the code coverage information of the application to be tested according to the code coverage information of each sub-service function; Among them, the number of threads used to execute the test request is multiple; the test module includes: A thread determination submodule, used to test the running performance of each thread, and determine the scheduling period of each thread based on the running performance of each thread, wherein the scheduling period is the frequency of the number of scheduling times determined based on the running performance of each thread; Sorting the scheduling periods of the threads, and selecting a thread corresponding to executing each sub-service function from the threads in sequence based on the sorting; A testing submodule, configured to test each subservice function based on a thread corresponding to each subservice function, and obtain code coverage information corresponding to each subservice function; The state of each thread includes a sleeping state and a wake-up state. When no test request is detected, the state of each thread is a sleeping state. The thread determination submodule is used to wake up the thread that executes each sub-service function from each thread based on the order of the scheduling cycles of the threads, and execute each sub-service function based on the woken thread. The device also includes: The second determination module is used to determine a mapping relationship based on the code coverage information of each sub-service function, wherein the mapping relationship represents the mapping relationship between different sub-service functions and different code coverage information; based on the mapping relationship, the code corresponding to at least part of the sub-service functions is adjusted.

5. The device according to claim 4, wherein: The test module also includes: The adjustment module is used to adjust the state of the awakened thread to a sleep state after the awakened thread executes each of the sub-service functions.

6. The device according to claim 4, wherein: If all threads are in the awake state, the thread determination submodule is used to determine the load of each thread, select a thread with the smallest load from each thread, and determine it as the thread that executes each sub-service function.

7. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 3.

8. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 3.

9. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Coverage rate test processing method and device and coverage rate test server and system

    CN103095518A

  • Terminal code coverage rate monitoring method and system, medium and electronic device

    CN110245073A