Disclosure of Invention
The invention aims to provide a collection method capable of automatically realizing the storage of test coverage, the automatic transmission of a test coverage file and the failure retransmission in the test process aiming at the problems encountered when a target application is tested, in particular to the problems encountered when the application in an Android system is tested. The working mode of manually copying and storing the coverage rate execution files from a plurality of devices is changed, and the working efficiency is improved.
Specifically, an embodiment of the present invention provides a code coverage acquisition method for a target application manual test, where the method includes:
loading a pre-constructed software development kit in a system where the target application is located;
associating the software development kit with the target application;
running the software development kit to automatically perform the steps of:
calling a code coverage rate testing tool to perform code coverage rate testing on the target application, and generating and storing a code coverage rate file;
starting a transmission program, and transmitting the generated code coverage rate file of the target application to a server;
judging whether the code coverage rate file is successfully transmitted or not, and if the code coverage rate file is successfully transmitted, deleting the generated code coverage rate file; otherwise, monitoring the network state and repeating the transmitting operation until the code coverage rate file is transmitted to the server successfully.
Preferably, the method further comprises the following steps: resetting the code coverage tested by the code coverage testing tool.
Preferably, the step of monitoring the network status and repeatedly performing the transmission operation until the code coverage file is successfully transmitted to the server comprises: and registering broadcast messages of network changes and program starting, and after receiving the broadcast messages, transmitting the code coverage rate file cached in the local to the server again.
Preferably, the software development kit is integrated with a code coverage test tool and further includes local memory.
Preferably, the software development kit comprises a reset interface for interacting with a user, and the reset interface is used for executing the reset of the code coverage rate state.
Preferably, the step of associating the software development kit with the target application comprises: and adding an integration code to the target Application, wherein the integration code is used for outputting an Application object of the target Application to the software development toolkit.
Preferably, the step of transmitting the generated code coverage file of the target application to a server further comprises: the code coverage file is transmitted to the server along with the relevant state information of the target application.
Preferably, the step of loading a pre-constructed software development kit in the system where the target application is located includes: installing and starting a pre-constructed software development kit in a system where the target application is located; or directly starting a pre-constructed software development kit installed in a third-party storage device coupled with the system where the target application is located in the system where the target application is located.
In addition, the software development kit can be associated with the target application in the process of loading a pre-constructed software development kit in the system where the target application is located.
The embodiment of the present invention further provides a storage device storing a software development kit, wherein when the storage device is coupled to a system where a target application is located and the software development kit is loaded in the system, the software development kit is associated with the target application, and the software development kit is run to perform the following steps:
calling a code coverage rate testing tool to perform code coverage rate testing on the target application, and generating and storing a code coverage rate file;
starting a transmission program, and transmitting the generated code coverage rate file of the target application to a server;
judging whether the code coverage rate file is successfully transmitted or not, and if the code coverage rate file is successfully transmitted, deleting the generated code coverage rate file; otherwise, monitoring the network state and repeating the transmitting operation until the code coverage rate file is transmitted to the server successfully.
Preferably, when the software development kit is run, the following steps are further executed: resetting the code coverage tested by the code coverage testing tool.
Preferably, the code coverage testing tool is Jacoco Agent.
Preferably, the step of performing the monitoring of the network status and repeating the transmitting operation until the code coverage file is successfully transmitted to the server comprises: and registering broadcast messages of network changes and program starting, and after receiving the broadcast messages, transmitting the code coverage rate file cached in the local to the server again.
Preferably, the software development kit is integrated with a code coverage test tool.
Preferably, the software development kit comprises a reset interface for interacting with a user, and the reset interface is used for executing the reset of the code coverage rate state.
Preferably, the step of associating the software development kit with the target application comprises: and adding integration codes to the target Application, wherein the integration codes are used for outputting the Application object of the target Application to the software development kit.
Preferably, the step of transmitting the generated code coverage file of the target application to a server further comprises: the code coverage file is transmitted to the server along with the relevant state information of the target application.
Preferably, the step of coupling the storage device with a system in which the target application is located and loading the software development kit in the system comprises: installing and starting the software development kit in a system where the target application is located; or directly starting the software development kit in the system where the target application is located.
Preferably, the software development kit is associated with the target application during loading of the software development kit in the system in which the target application is located.
It should be noted that the term "register" in the present invention refers to registering or registering a recipient of an event in an Android or other operating system, where the event may include a network change, a program start, and the like.
Technical effects
In the existing Android application test mode, the generated coverage rate file is stored in a memory card (for example, an SD card) of the smart terminal, and then the smart terminal needs to be connected, exported, and summarized, and then a report is generated. Using the method of the present invention, after constructing the software development tool SDK, associating the software development tool package with the target application; the software development kit is run to automatically test the code coverage of the target application and send a coverage file to the server until the transfer is successful, completing the totalization of the coverage file. The scheme provided by the invention changes the working mode of manually copying and storing the coverage rate execution file from a plurality of devices, and can also provide a reset function on the running page, so that a tester can reset the coverage rate state at any time, the coverage condition of the code at the required test stage can be accurately recorded, and the working efficiency is greatly improved.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the embodiments of the present invention and the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components or steps of an embodiment of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings and the specific embodiments of the present invention.
In this embodiment, the description of the code coverage acquisition method related to the present invention is described by taking an Android system as an example, and at this time, the target application is an application program running under the Android system. Fig. 1 is a schematic flow chart of a code coverage acquisition method of a first embodiment of the present invention. As shown in fig. 1, in the present embodiment, the code coverage rate collecting method for the target application manual test includes the following steps:
s1: and loading a pre-constructed software development kit in a system where the target application is located.
In order to collect the code coverage rate of the target application, a pre-constructed software development kit needs to be loaded in a system where the target application is located. The loading mode comprises the following steps: installing and starting the pre-constructed software development kit in the system where the target application is located; or, directly starting a pre-built software development kit installed in a third-party storage device coupled to the system where the target application is located in the system where the target application is located, for example, coupling a removable storage device (e.g., an optical disc, a U-disc, an SD card, a TF card, etc.) loaded with the pre-built software development kit with a smart terminal (e.g., a smart mobile terminal of an android system, etc.) installed with the target application, so that the pre-built software development kit can be directly started in the system where the target application is located; or directly starting a software development kit of a pre-constructed network version on a shared server or a shared space under the internet or the local area network to load the pre-constructed software development kit in a system where the target application is located in the internet or the local area network. The coupling described herein may include, but is not limited to: the method comprises the steps of placing an optical disk loaded with a pre-constructed software development kit in an optical drive driver of the intelligent terminal, inserting a U disk or an SD card or a TF card or the like loaded with the pre-constructed software development kit into a corresponding interface of the intelligent terminal provided with the target application, and communicating a shared server or a shared space storing the pre-constructed network version software development kit with the intelligent terminal provided with the target application through the Internet or a local area network.
Preferably, a software development kit (Android SDK) of an Android system is constructed in advance, and the software development kit of the Android system has the following functions: calling a code coverage rate testing tool and generating and storing a code coverage rate testing file; starting an Android Service to automatically transmit the generated code test coverage rate file or the generated code test coverage rate file and related parameters of the target application to a remote or back-end server; then judging whether the transmission is successful, if so, deleting the generated code coverage rate file stored locally; otherwise, the generated code coverage file is cached and retransmitted, which avoids the occurrence of missing code test coverage files when the network is unavailable or unstable.
In addition, the software development kit has an interface for interacting with a user, such as a floating button providing a reset function, and the like, and the user can reset the code coverage tested by the code coverage testing tool through the interactive interface (reset button) at any time. The floating button may be referred to as a virtual floating button or a physical button. In this embodiment, a virtual floating button is employed.
S2: the constructed software development kit is associated with the target application.
The associated meanings mentioned here mean: the software development kit, e.g. the Android system, loaded into the system where the target application is located is made to interact with the target application in any way, both data and programmatically.
In a preferred mode, the step of associating the built software development kit, such as the Android system, with the target application comprises the following steps: and adding integration codes to the target Application, wherein the integration codes are used for outputting the Application object of the target Application to the software development kit. Adding the integration code in the target application can be realized in a manual mode, for example, a tester manually adds the integration code in the target application; of course, the method can also be implemented in an automatic manner, that is, the software development kit is associated with the target application in the process of loading the pre-constructed software development kit in the system where the target application is located. For example, in the process of installing and starting the pre-constructed software development kit in the system where the target application is located, or in the process of directly starting and loading the pre-constructed software development kit in the system where the target application is located, the required integrated code is automatically added to the target application by the software development kit. Taking an Android system as an example, the target Application transmits an Android Application instance to a software development kit SDK, and the software development kit SDK can acquire relevant states of the target Application through the object, such as registering a lifecycle callback function.
S3: running the software development kit to automatically perform the steps of:
s3-1) calling a code coverage testing tool to carry out code coverage testing on the target application, and generating and saving a code coverage file. Specifically, since the association between the software development kit of the Android system and the target application is established, for example, the software development kit of the Android system may start the target application, and may also invoke a code coverage testing tool, which may be a Jacoco Agent, to perform a code coverage test on the target application.
And the Android system software development kit outputs the measured current code coverage rate of the target application to a target file and performs local storage, wherein the local storage can be stored in an physically independent local storage or a drawn virtual storage space.
The code coverage testing tool may be integrated into or otherwise in communication with and capable of being invoked by a software development kit.
S3-2) starting a transmission program, and transmitting the generated code coverage rate file of the target application to a server;
s3-3) judging whether the code coverage rate file is successfully transmitted, if so, deleting the generated code coverage rate file; otherwise, monitoring the network state and repeating the transmitting operation until the code coverage rate file is transmitted to the server successfully.
The steps of monitoring a network status and repeatedly performing a transfer operation until the code coverage file is successfully transferred to the server include: and registering broadcast messages of network changes and program starting, and after receiving the broadcast messages, transmitting the code coverage rate file cached in the local to the server again.
Preferably, if the network communication fails, the software development kit for example of the Android system constructed in the present invention may cache a plurality of code coverage files generated by a plurality of tests during the network failure, and send all the cached coverage files to the server once the network recovery is monitored, and preferably, send all the cached coverage files to the server together with the corresponding state information of the target application. In this preferred embodiment, the software development kit is integrated with the code coverage testing tool.
In addition, the software development kit may further include a local memory, i.e., a memory card, such as an SD card, a TF card, etc., and may also be a usb disk.
The above-described two steps S3-2 and S3-3 are actually a loop of repeated judgment processes.
The server can be a local server or a remote server, and the server communicates with the device where the application to be tested is located through a wired or wireless communication mode, so that the code coverage rate file can be transmitted.
In fact, more preferably, in addition to transmitting the code coverage file, the transmission of the relevant state file of the target application may also be performed, that is, the step S3-2 further includes: the code coverage file is transmitted to the server along with the relevant state information of the target application. The relevant state information of the target application comprises: version information of the program: such as version identification in a code versioning system, ID of the current application installation package, and these version information are used to associate code coverage information with a particular version of source code.
In addition, the code coverage rate acquisition method of the embodiment further includes: resetting the code coverage tested by the code coverage testing tool. The resetting of the code coverage status is not necessary for a single test, but is necessary for the case where multiple tests are required for the same or different applications, by which the accuracy of subsequent coverage tests is guaranteed.
The resetting of code coverage may be performed manually by a user, and may be performed automatically by a software development kit.
The resetting step performed automatically may be performed at multiple time points, for example, the resetting step may be set when the software development kit is started, or the resetting step may be set after the software development kit calls the code coverage testing tool to perform the code coverage test and outputs the code coverage file.
The manual reset mode is to make the reset operation more free, and an interface interacting with the user may be added to a software development kit of, for example, an Android system, for example, the software development kit generates a floating button for resetting on the target application, so that the user can reset the code coverage status of the test only by clicking the floating button, that is, the reset of the code coverage status is performed through the reset interface, and is not required to modify the target application.
In the conventional method for realizing reset, the application needs to be modified, and the code for realizing reset is inserted in some life cycles of the application; such as when the program exits, a reset is implemented. In this way, the code for resetting the coverage rate is introduced into the original business logic of the program, so that the program is not convenient to carry, and the risk of damaging the production code is also introduced.
Preferably, the software development kit of the present invention is a "pluggable" software development kit, where reference to "pluggable" refers to: the built software development kit is added without modifying the service logic of the program, so that the integration is convenient, and the integration or the removal can be convenient. When the code coverage rate test of the target application is needed, combining the constructed software development kit such as an Android system with the target application on the target device, running the software development kit to call a coverage rate test tool for testing and automatically transmitting the generated code coverage rate file to the server.
Although in the above-described first embodiment and the corresponding preferred embodiment, the loading of the pre-constructed software development kit in the system in which the target application is located and the association of the software development kit with the target application are respectively described as being divided into two steps S1 and S2; however, an example is also described above in which the software development kit can be associated with the target application in the process of loading the pre-constructed software development kit in the system in which the target application is located, and thus, those skilled in the art will know that: the loading of the pre-constructed software development kit in the system where the target application is located and the association of the software development kit with the target application, which are described separately in two steps S1 and S2, can be implemented as one step, that is, in the second embodiment: the code coverage rate acquisition method for the target application manual test comprises the following steps:
loading a pre-constructed software development kit in a system where a target application is located and associating the software development kit with the target application in a loading process;
running the software development kit to automatically perform the steps of:
calling a code coverage rate testing tool to perform code coverage rate testing on the target application, and generating and storing a code coverage rate file;
starting a transmission program, and transmitting the generated code coverage rate file of the target application to a server;
judging whether the code coverage rate file is successfully transmitted or not, and if the code coverage rate file is successfully transmitted, deleting the generated code coverage rate file; otherwise, monitoring the network state and repeating the transmitting operation until the code coverage rate file is transmitted to the server successfully.
At this time, the contents of the first embodiment and the preferred embodiment described above with reference to fig. 1 can be applied to the second embodiment without conflict, which will be obvious to those skilled in the art and will not be described repeatedly herein.
According to the code coverage rate acquisition method for the target application manual test, a pre-constructed software development kit is associated with the target application; the software development kit is run to automatically test the code coverage of the target application and automatically send a coverage file to the server until the transfer is successful, completing the totalization of the coverage files. The scheme provided by the invention changes the working mode of manually copying and storing the coverage rate execution file from a plurality of devices, and can also provide a reset function on the running page, so that a tester can reset the coverage rate state at any time, the coverage condition of the code at the required test stage can be accurately recorded, and the working efficiency is greatly improved.
Fig. 2 is an exemplary screenshot of a coverage test performed using the coverage acquisition method of the present invention. The floating button of the insect graph in the upper right corner of fig. 2 is a code coverage generation entry provided by a software development kit of the Android system after the software development kit is loaded.
The example shown in fig. 2 is a code coverage acquisition test performed on a reading-like App-Android version flag reading App.
In order to collect the code coverage rate of the reading class App, a pre-constructed Android system software development kit, in particular a pluggable Android system software development kit, is loaded in a system where the reading class App is located. The software development kit of the Android system is integrated with a code coverage test tool of, for example, Jacoco Agent. In order to combine the software development kit of the Android system with the reading type App, only the Application type needs to be realized in the reading type App, and the following line of codes is added in the realized onCreate method of the Application type:
new ReportBug.Builder(this,"xxxx").build()
where "xxxx" is an identification code assigned to the target application.
In a preferred example, after the above steps are performed, a floating reset button is arranged on the display page of the reading class App for resetting the code coverage status.
Then, clicking a floating button of the insect graph displayed on the page to run the software development kit, and automatically executing the following series of actions:
firstly, the software development toolkit calls a code coverage rate testing tool Jacoco Agent to perform code coverage rate testing on reading class App-Android version flag reading by using an onCreate function of an Application object, and the coverage rate information of a testing step on a code is recorded in the testing process. A code coverage file is generated that contains coverage information for the program source code for the test execution step, such as whether certain instructions, lines, or branches of a certain method are covered for a certain class. For the example in fig. 2, the measured code coverage is the coverage of the source code read by the Android version flag in the step related to the operation of the book reading page by the tester, and the measured coverage automatically generates a code test coverage file and stores the code test coverage file on the memory card.
The reset of the coverage status can then be done manually or automatically in a preferred application with a reset function.
And then, starting a code coverage rate file transmission program by the software development kit through Android Service, monitoring a coverage rate transmission state by monitoring received HTTP Response, monitoring the transmission condition of the code coverage rate file in real time, deleting the generated code coverage rate test file by issuing a deletion command if the transmission is successful, or else, monitoring the network state by registering an application network condition monitor and retrying to transmit the code coverage rate file again when the network is recovered until the transmission is successful.
When manual reset is realized, the software development kit generates a floating button on a target application, and a user clicks the floating button to directly execute the reset; of course, the floating button may also correspond to a menu, that is, a menu appears after the user clicks the floating button, and the menu displays, for example: a reset option; send and reset options, etc. The transfer code coverage file is executed when the user selects the send and reset options, while a reset of the coverage status is executed.
The transmitted file may include, in addition to the generated code coverage file: the identifier of the current target application (above "xxxx") and the version information of the target application, which together identify the version of one target application. And the code coverage rate file and the related state file of the target application are directly transmitted to a background server through a post method and are stored by the background server.
In addition, the present invention also provides a storage device storing a software development kit, the storage device being coupled to a system in which a target application is located and the software development kit being associated with the target application when the storage device is coupled to the system and the software development kit is loaded in the system, the software development kit being executed to perform the steps of:
calling a code coverage rate testing tool to perform code coverage rate testing on the target application, and generating and storing a code coverage rate file;
starting a transmission program, and transmitting the generated code coverage rate file of the target application to a server;
judging whether the code coverage rate file is successfully transmitted or not, and if the code coverage rate file is successfully transmitted, deleting the generated code coverage rate file; otherwise, monitoring the network state and repeating the transmitting operation until the code coverage rate file is transmitted to the server successfully.
The implementation steps and procedures described in the first and second embodiments and their alternative embodiments above are also applicable here. Wherein the step of coupling the storage device with a system in which the target application resides and loading the software development kit in the system comprises: installing and starting the software development kit in a system where the target application is located; or directly starting the software development kit in the system where the target application is positioned. The coupling described herein may include, but is not limited to: and placing the optical disc stored with the software development kit in an optical drive driver of the intelligent terminal, inserting the U disc, the SD card, the TF card or the like stored with the software development kit into a corresponding interface of the intelligent terminal provided with the target application, and communicating a shared service terminal or a shared space stored with the software development kit of a pre-constructed network version with the intelligent terminal provided with the target application through the Internet or a local area network.
Associating the software development kit with a target application is: the software development kit loaded into the system in which the target application resides is caused to interact data and program with the target application in any manner. Preferably, the method for associating the software development kit with the target application comprises: and adding an integration code to the target Application, wherein the integration code is used for outputting an Application object of the target Application to the software development toolkit. Adding the integration code in the target application can be realized in a manual mode, for example, a tester manually adds the integration code in the target application; of course, the software development kit may also be automatically associated with the target application in the process of loading the software development kit in the system where the target application is located. For example, in the process of installing and starting the software development kit in the system where the target application is located, or in the process of directly starting and loading the software development kit in the system where the target application is located, the software development kit automatically adds the required integration code to the target application.
Preferably, when the software development kit is run, the following steps can be further executed: resetting the code coverage tested by the code coverage testing tool. The resetting of code coverage may be performed manually by a user, and may be performed automatically by a software development kit. The resetting step performed automatically may be performed at multiple time points, for example, the resetting step may be set when the software development kit is started, or the resetting step may be set after the software development kit calls the code coverage testing tool to perform the code coverage test and outputs the code coverage file. In a preferred embodiment of manual reset, the software development kit includes a reset interface for user interaction, through which reset of the code coverage status is performed. The reset interface is, for example, a floating button that the software development kit generates for resetting on the target application.
Preferably, the code coverage testing tool is Jacoco Agent.
Wherein the step of performing the monitoring of the network status and repeating the transfer operation until the code coverage file is successfully transferred to the server comprises: and registering broadcast messages of network changes and program starting, and after receiving the broadcast messages, transmitting the code coverage rate file cached in the local to the server again.
Preferably, the software development kit is integrated with a code coverage test tool.
Preferably, the step of executing the step of transmitting the generated code coverage file of the target application to a server further comprises: the code coverage file is transmitted to the server along with the relevant state information of the target application. The relevant state information of the target application comprises: version information of the program: such as version identification in a code versioning system, ID of the current application installation package, and these version information are used to associate code coverage information with a particular version of source code.
In addition, the software development kit can be associated with the target application in the process of loading the software development kit in the system where the target application is located.
Parts not described in detail herein may refer to the description of the first and second embodiments and their respective preferred embodiments, and will not be repeated here.
According to the storage device stored with the software development kit, when a tester uses the storage device to manually test the code coverage rate of the target application, the software development kit stored in the storage device is associated with the target application; and running the software development kit to automatically test the code coverage rate of the target application, and automatically sending the coverage rate file to the server until the transmission is successful, and finishing the totalization of the coverage rate file. The storage device with the software development kit stored in the invention changes the working mode of manually copying and storing the coverage rate execution file from a plurality of devices, and can also provide a reset function on the running page, so that a tester can reset the coverage rate state at any time, the coverage condition of a code at a required test stage can be accurately recorded, and the working efficiency is greatly improved.
It should be noted that, although the foregoing embodiment of the present invention describes the code coverage acquisition method according to the present invention by taking an Android system as an example, it should be understood by those skilled in the art that when testing target applications under other operating systems, including but not limited to target applications under ios and windows systems, on the basis of reading and understanding the spirit of the present invention, those skilled in the art can extend the code coverage acquisition method for manually testing target applications according to the present invention to code coverage acquisition for manually testing target applications under other operating systems.
The software development kit described in the present invention can be stored in a computer or intelligent device readable storage medium when it is implemented in the form of software functional units and sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention, or a part thereof, which substantially contributes to the prior art, may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing an intelligent mobile device to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.