Summary of the invention
The technical problem to be solved by the present invention is in order to overcome in the prior art be directed to cell phone system code coverage numberAccording to the problem for calculating inaccuracy, a kind of code coverage calculation and analysis methods, device, equipment and storage medium are proposed, is passed throughCalculating is merged to the coverage rate file below all commit id under some version, certain version is obtained and accurately coversRate file.
The present invention is to solve above-mentioned technical problem by following technical proposals:
A kind of code coverage calculation and analysis methods, include the following steps:
S1, the code for obtaining current version from code library by git order and the corresponding commit id of the code;
S2, the code is packaged to generate corresponding test bag, while after compiling the code to generate compilingFile, then test bag is saved with the file after compiling to the file of the code corresponding commit id nameIn;
S3, the covering that the commit id with code generated after the test bag that test man uploads is tested is named is receivedRate file, and the coverage rate file is saved into the file named with the commit id;
S4, the file in the commit id file is calculated to generate and work as former generation by code coverage toolThe test coverage report of code;
S5, the test coverage report of current version code and the test of a preceding edition code are covered by merging algorithmThe report of lid rate merges, and generates the coverage rate report of full dose;
S6, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode takes out code coverage corresponding with the change code of part from full dose coverage rate report, generates incrementCoverage rate report.
Preferably, this method is further comprising the steps of:
S7, the coverage rate report of the increment and the coverage rate report of full dose are sent to and are surveyed to current version codeThe test man of examination.
Preferably, the code includes applied to the installation procedure on the end IOS and applied to the installation procedure on Android end.
Preferably, when the code is applied to installation procedure on the end IOS, the file after the compiling is gcno textPart, the coverage rate file are gcda file.
Preferably, when the code is applied to installation procedure on Android end, the file after the compiling includes classFile and source file, the coverage rate file are ec file.
Preferably, the generating process of the coverage rate report of the full dose is as follows:
S51, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode, to calculate the offset of code;
S52, the offset according to code close the code coverage in the test coverage report of a preceding edition codeAnd into the report of the test coverage of current version code.
Preferably, the coverage rate file is installed after test bag is tested on mobile phone terminal by test man and is given birth to automaticallyAt.
A kind of electronic device is stored with code coverage on the electronic device and calculates analysis system, the code coverageRate calculates analysis system:
Code obtaining module, the code for obtaining current version from code library by git order are corresponding with the codeCommit id;
Be packaged collector, the code is packaged to generate corresponding test bag, at the same compile the code withThen file after generating compiling saves the file after test bag and compiling to the code corresponding commit id nameFile in;
Coverage rate file reception module, the test bag for receiving test man's upload generate after testing with codeThe coverage rate file of commit id name, and the coverage rate file is saved to the file named with the commit idIn;
Current report generation module, for by code coverage tool to the file in the commit id file intoRow is calculated to generate the report of the test coverage of current code;
Full dose report generation module, for by merge algorithm by the report of the test coverage of current version code with it is previousThe test coverage report of secondary edition code merges, and generates the coverage rate report of full dose;
Increment report generation module, for obtaining current version code and a preceding edition code by git diff orderCompared to the code of change part, code corresponding with the change code of part is taken out from full dose coverage rate reportCoverage rate generates the coverage rate report of increment.
A kind of computer equipment, including memory and processor are stored with and can be held by the processor on the memoryCapable code coverage calculates analysis system, realizes as described in any one of aforementioned when the system is executed by the processorThe step of code coverage calculation and analysis methods.
A kind of computer readable storage medium is stored with code coverage in the computer readable storage medium and calculates pointAnalysis system, the code coverage calculates analysis system can be performed by least one processor, so that described at least oneManage the step of device executes the code coverage calculation and analysis methods as described in any one of aforementioned.
The positive effect of the present invention is that:In the case where operational trials unaware, coverage rate situation is collected;It supportsAfter code frequently changes, the merging of coverage rate situation between different code, so as to obtain the accurate coverage rate text of certain versionPart;The unlapped test point of test phase is automatically analyzed according to current coverage rate report, tester is notified automatically, guarantees to surveyThe coverage rate of examination.
Specific embodiment
The present invention is further illustrated below by the mode of embodiment, but does not therefore limit the present invention to the realityIt applies among a range.
Firstly, the present invention proposes a kind of code coverage calculation and analysis methods.
In example 1, as shown in Figure 1, for the installation procedure being applied on the end IOS, the code coverage meterAnalysis method is calculated to include the following steps:
S1, the code for obtaining current version from code library by git order and the corresponding commit id of the code.
After usual programmer has write a program, which can all be uploaded to a specific code library (such as sandBox) in, it include corresponding commit id in the program of upload.
Id in the commit id refers to that cryptographic Hash, the cryptographic Hash are passed through according to the data of the content of fileThe numerical value that logical operation obtains, the cryptographic Hash that different file (even identical filename) obtains also are different, soCryptographic Hash can be used as the identity card for identifying each file.
When needing to test code, newest code (i.e. current version is just pulled by git order from code libraryThis code) because the installation procedure of same version can all may give birth to by repeatedly modification, each modification in the process of developmentAt a new code, current version described here does not refer to the version number of code, but refers to the cryptographic Hash of code, in the applicationWhat alleged current version and previous version were distinguished by cryptographic Hash.
Specifically, Jenkins tool can be used by code being obtained from code library.The Jenkins be one open source,Continuous integrating (CI) tool at friendliness interface is provided, originates from Hudson (Hudson is commercial), is mainly used for holdingContinuous, automatic building/test software project, the operation for monitoring external tasks.The concrete operations of Jenkins tool refer to its explanationBook.
S2, the code is packaged to generate corresponding test bag, while after compiling the code to generate compilingGcno file, then test bag is saved with the gcno file after compiling to the code corresponding commit id nameIn file.
For the installation procedure being applied on the end IOS, being packaged for test bag can be used by the way of Apple recommendationThe archive function of xcode (xcode is the Integrated Development Tool operated on operating system Mac OS X) is packaged (suitableFor personal development), by the way of secondly being dragged in using iTunes (iTunes be professional apple equipment management tool),The compiling that a full-automatic compilation script realizes code can also be write.
Wherein first two has used existing tool xcode and iTunes, and specific packing process is shown in its specification.Below forLower explanation is done by writing full-automatic compilation script progress code compilation:
The first step:New folder is named as " distribute ", distribute.sh script file is created, with reference to such asLower content (wherein the appName is the title of code, such as some title for the app on IOS):
rm-rf appName
mkdir appName
mkdir appName/Payload
cp-r appName.app appName/Payload/appName.app
cp Icon.png appName/iTunesArtwork
cd appName
zip-r appName.ipa Payload iTunesArtworkexit 0
Above-mentioned code completes following steps:
Delete file appName;
Create a file appName;
A sub-folder payload is created at file appName;
File appName.app is copied in the sub-folder payload under file appName;
Icon Icon.png is copied in the sub-folder iTunesArtwork under file appName;
It is switched to file appName;
Two sub-folders payload and iTunesArtwork under file appName are compressed into a file,And the suffix of compressed file is changed to .ipa;
Normally exit.
Second step:The .app file that will be converted is put under distribute/ file, with reference to as follows:
distribute/distribute.sh
distribute/appName.app
Third step:Run distribute.sh script.Terminal is opened, under cd to distribute file,Distribute.sh drawing is executed into terminal.If prompting permission denied, " chmod is usedAfter 777distribute.sh " order assigns permission, then execute a distribute.sh.
4th step:After running several seconds, appName/ file can be generated under distribute/ file, the insideAppName.ipa is exactly the test bag that we want.
Gcno file after the compiling is by obtaining after carrying out pitching pile to original code, this process is known as program and insertsStake, described program pitching pile are the methods by by the insertion operation into tested program, to realize test purpose, i.e., in guarantee quiltSome probes (also known as " survey meter ") is inserted on the basis of the original logic integrality of ranging sequence in a program.These probes essenceOn be exactly the code segment for carrying out information collection, can be assignment statement or acquire coverage information function call.Pass through probeExecute the operation characteristic data of simultaneously output program.Based on the analysis to these characteristics, internal act and the spy of program are disclosedSign.
S3, the covering that the commit id with code generated after the test bag that test man uploads is tested is named is receivedRate gcda file, and the coverage rate gcda file is saved into the file named with the commit id.
The gcda file refers to that suffix is the file of gcda, is obtained by gcov command tools, the gcov order isThe tool of the code coverage of a test program.After the code is tested by the tool, a suffix is finally obtainedFor the coverage rate file of gcda, and the title of this document is named with the commit id of tested code.
After coverage rate gcda file generated, test man also needs to be uploaded in aforementioned specific code library, and savesInto with the file of commit id name.
The coverage rate gcda file is below for generating the basis of coverage rate report.
S4, the file in the commit id file is calculated to generate and work as former generation by code coverage toolThe test coverage report of code;
The code coverage tool still can use gcov command tools, will by executing order gcov * .cppThe coverage rate of test is printed on the screen, and generates file " * cpp.gcov " simultaneously, which then can see with vi openingRow is capped, that is, sees which code tester arrives, which, which is not tested, arrives.
S5, the test coverage report of current version code and the test of a preceding edition code are covered by merging algorithmThe report of lid rate merges, and generates the coverage rate report of full dose.
The step S5 specifically may include following steps:
S51, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode, to calculate the offset of code;
S52, the offset according to code close the code coverage in the test coverage report of a preceding edition codeAnd into the report of the test coverage of current version code.
Using above-mentioned merging method, can be by the way that test coverage report be gradually merged two-by-two after, ultimately generateThe coverage rate of full dose is reported.
S6, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode takes out code coverage corresponding with the change code of part from full dose coverage rate report, generates incrementCoverage rate report.
The report of test coverage described in the present embodiment is exactly that the coverage rate file being previously obtained is presented with report formOut.Including but not limited to the following contents:Coverage rate, method coverage rate, sentence covering rate, statement block coverage rate and the branch of classCoverage rate.
In the present embodiment, the test man obtains test bag and can be obtained by way of barcode scanning, as long as completing to testAfter the packing of packet, increasing the step of automatically generating two dimensional code or bar code etc be can be realized.
In example 2, as shown in Fig. 2, for the installation procedure being applied on the end IOS, the code coverage meterAnalysis method is calculated to include the following steps:
S1, the code commit id corresponding with the code for obtaining current version from code library by git order.
Step S1 is as in the first embodiment, details are not described herein again.
S2, the code is packaged to generate corresponding test bag, while after compiling the code to generate compilingClass file and source file, then by test bag and compiling after class file and source file save to thisIn the file of the corresponding commit id name of code.
The test bag of code applied to Android system refers specifically to be inserted into the peace after the code for generating coverage dataProgram is filled, after test man installs program operation, automatically generating corresponding code tester rate ec file, (suffix is the text of .ecPart).
The packing of test bag usually completed by writing the included strapping tool of the tool of code, such as Eclipse includedStrapping tool Ant, also some, which are write in the tool of code, has specific be packaged to order, and input is specific to be packaged order, and meeting is certainlyIt is dynamic to generate test bag.
The complete entitled Java class file of the class file, the source file write with java language (code) warpCrossing compiling will become corresponding * .class file.Compiling described here is general all to carry out reality by the compilation facility that developing instrument carriesMyEclipse that is existing, such as developing for Java, Java EE and mobile application saves file by the code that it is developedAfter can be compiled into class file automatically.
Different from the code of IOS system is applied to, the code applied to Android system can also generate one after compilingSource file, this file is for saving source code.
S3, the covering that the commit id with code generated after the test bag that test man uploads is tested is named is receivedRate ec file, and the coverage rate ec file is saved into the file named with the commit id;
The ec file refers to that suffix is the file of ec, and this document can be automatically generated by the operation of test bag, this documentTitle is still with the commit id name of tested code.
The coverage rate ec file is below for generating the basis of coverage rate report.
S4, the file in the commit id file is calculated to generate and work as former generation by code coverage toolThe test coverage report of code;
The code coverage tool can use Jacoco (abbreviation of Java Code Coverage) tool, the toolApplication method referring to its specification.
S5, the test coverage report of current version code and the test of a preceding edition code are covered by merging algorithmThe report of lid rate merges, and generates the coverage rate report of full dose.
The step S5 specifically may include following steps:
S51, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode, to calculate the offset of code;
S52, the offset according to code close the code coverage in the test coverage report of a preceding edition codeAnd into the report of the test coverage of current version code.
Using above-mentioned merging method, can be by the way that test coverage report be gradually merged two-by-two after, ultimately generateThe coverage rate of full dose is reported.
S6, show that current version code changes the generation of part compared with a preceding edition code by git diff orderCode takes out code coverage corresponding with the change code of part from full dose coverage rate report, generates incrementCoverage rate report.
The report of test coverage described in the present embodiment is exactly that the coverage rate file being previously obtained is presented with report formOut.Including but not limited to the following contents:Coverage rate, method coverage rate, sentence covering rate, statement block coverage rate and the branch of classCoverage rate.
The difference of the present embodiment two and embodiment one is only in S2-S4, remaining step is the same as embodiment one.
In the third embodiment, based on the basis of embodiment one or two, the code coverage calculation and analysis methods are alsoInclude the following steps:
S7, the coverage rate report of the increment and the coverage rate report of full dose are sent to and are surveyed to current version codeThe test man of examination.
Here it can specifically send report in the mailbox of test man, so that it reads in detail.
If it is desired, this report can also be automatically transmitted to all relevant personnel, as long as presetting relevant people in systemsThe mailbox of member.
It is sent and is reported by mailbox, test man can be allowed to learn test result in time, removed its active from and initiate to obtain reportOperation.
Secondly, being stored with code coverage on the electronic device the invention proposes a kind of electronic device and calculating analysisSystem 20, the system 20 can be divided into one or more program module.
For example, Fig. 3 shows the program module schematic diagram that the code coverage calculates 20 first embodiment of analysis system,In the embodiment, the system 20 can be divided into Code obtaining module 201, packing collector 202, coverage rate file and connectReceive module 203, current report generation module 204, full dose report generation module 205 and increment report generation module 206.Wherein,The so-called program module of the present invention is the series of computation machine program instruction for referring to complete specific function.Being described below will be specificIntroduce the concrete function of the program module 201-206.
The Code obtaining module 201 is used to obtain code and generation of current version from code library by git orderThe corresponding commit id of code.
Id in the commit id refers to that cryptographic Hash, the cryptographic Hash are passed through according to the data of the content of fileThe numerical value that logical operation obtains, the cryptographic Hash that different file (even identical filename) obtains also are different, soCryptographic Hash can be used as the identity card for identifying each file.
When needing to test code, it is (i.e. current that newest code is just pulled by git order from code libraryThe code of version) because the installation procedure of same version can may be modified every time and all can by repeatedly modification in the process of developmentA new code is generated, current version described here does not refer to the version number of code, but refers to the cryptographic Hash of code, the applicationIn alleged current version and previous version distinguished by cryptographic Hash.
Specifically, Jenkins tool can be used by code being obtained from code library.The Jenkins be one open source,Continuous integrating (CI) tool at friendliness interface is provided, originates from Hudson (Hudson is commercial), is mainly used for holdingContinuous, automatic building/test software project, the operation for monitoring external tasks.The concrete operations of Jenkins tool refer to its explanationBook.
The packing collector 202 is packaged the code to generate corresponding test bag, while described in compilingCode is to generate the file after compiling, and then the file by test bag and after compiling is saved to the corresponding commit of the codeIn the file of id name.
For the installation procedure for being applied to the end IOS, what is generated after code compilation is gcno file.
Being packaged for test bag can be by the way of Apple recommendation, i.e., with xcode, (xcode is to operate in operating systemIntegrated Development Tool on Mac OS X) archive function be packaged (be suitable for personal development), secondly can useThe mode that iTunes (the apple equipment management tool that iTunes is profession) is dragged in can also write a full-automatic compiling footThe compiling of this realization code (with reference to described in embodiment of the method one).
Gcno file after the compiling is by obtaining after carrying out pitching pile to original code, this process is known as program and insertsStake, described program pitching pile are the methods by by the insertion operation into tested program, to realize test purpose, i.e., in guarantee quiltSome probes (also known as " survey meter ") is inserted on the basis of the original logic integrality of ranging sequence in a program.These probes essenceOn be exactly the code segment for carrying out information collection, can be assignment statement or acquire coverage information function call.Pass through probeExecute the operation characteristic data of simultaneously output program.Based on the analysis to these characteristics, internal act and the spy of program are disclosedSign.
For the installation procedure for being applied to Android system, the class file and source file that are generated after code compilation.
The test bag of code refers specifically to be inserted into the installation procedure after the code for generating coverage data, test man's installationAfter program operation, corresponding code tester rate ec file (file that suffix is .ec) can be automatically generated.
The packing of test bag usually completed by writing the included strapping tool of the tool of code, such as Eclipse includedStrapping tool Ant, also some, which are write in the tool of code, has specific be packaged to order, and input is specific to be packaged order, and meeting is certainlyIt is dynamic to generate test bag.
The complete entitled Java class file of the class file, the source file write with java language (code) warpCrossing compiling will become corresponding * .class file.Compiling described here is general all to carry out reality by the compilation facility that developing instrument carriesMyEclipse that is existing, such as developing for Java, Java EE and mobile application saves file by the code that it is developedAfter can be compiled into class file automatically.
Different from the code of IOS system is applied to, the code applied to Android system can also generate one after compilingSource file, this file is for saving source code.
The coverage rate file reception module 203 be used for receive test man upload test bag test after generate withThe coverage rate file of the commit id name of code, and the coverage rate file is saved to being named with the commit idIn file.
For the installation procedure for being applied to the end IOS, the coverage rate file of generation is gcda file, passes through gcov order workWhat tool obtained, the gcov order is the tool of the code coverage of a test program.The code is carried out by the toolIt is final to obtain the coverage rate file that a suffix is gcda after test, and the title of this document is with tested codeCommit id name.
For the installation procedure for being applied to Android system, the coverage rate file of generation is ec file, and this document passes through testThe operation of packet can automatically generate, and the title of this document is still with the commit id name of tested code.
The coverage rate file is below for generating the basis of coverage rate report.
The current report generation module 204 is used for through code coverage tool in the commit id fileFile is calculated to generate the report of the test coverage of current code.
The generating process of report is as follows:Firstly, obtaining current version code and a preceding version by git diff orderCode is compared to the code for changing part, to calculate the offset of code;Then according to the offset of code, by preceding primary versionCode coverage in the test coverage report of this code is merged into the test coverage report of current version code.
After gradually being merged test coverage report two-by-two, the coverage rate report of full dose is ultimately generated.
The full dose report generation module 205 is used to report the test coverage of current version code by merging algorithmTest coverage report with a preceding edition code merges, and generates the coverage rate report of full dose;
Increment report generation module, for obtaining current version code and a preceding edition code by git diff orderCompared to the code of change part, code corresponding with the change code of part is taken out from full dose coverage rate reportCoverage rate generates the coverage rate report of increment.
The report of test coverage described in the present embodiment is exactly that the coverage rate file being previously obtained is presented with report formOut.Including but not limited to the following contents:Coverage rate, method coverage rate, sentence covering rate, statement block coverage rate and the branch of classCoverage rate.
Again, the present invention also puts forward a kind of computer equipment.
As shown in fig.4, being the hardware structure schematic diagram of one embodiment of computer equipment of the present invention.In the present embodiment, instituteStating computer equipment 2 is that one kind can be automatic to carry out at numerical value calculating and/or information according to the instruction for being previously set or storingThe equipment of reason.For example, it may be smart phone, tablet computer, laptop, desktop computer, rack-mount server, bladeFormula server, (including the service composed by independent server or multiple servers of tower server or Cabinet-type serverDevice cluster) etc..As shown, the computer equipment 2 includes at least, but it is not limited to, company can be in communication with each other by system busIt connects memory 21, processor 22, network interface 23 and code coverage and calculates analysis system 20.Wherein:
The memory 21 includes at least a type of computer readable storage medium, and the readable storage medium storing program for executing includesFlash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory etc.), random access storage device (RAM), it is static withMachine accesses memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmableRead memory (PROM), magnetic storage, disk, CD etc..In some embodiments, the memory 21 can be describedThe internal storage unit of computer equipment 2, such as the hard disk or memory of the computer equipment 2.In further embodiments, describedMemory 21 is also possible to the plug-in type being equipped on the External memory equipment of the computer equipment 2, such as the computer equipment 2Hard disk, intelligent memory card (Smart Media Card, SMC), secure digital (Secure Digital, SD) card, flash card(Flash Card) etc..Certainly, the memory 21 can also both include the internal storage unit of the computer equipment 2 or wrapInclude its External memory equipment.In the present embodiment, the memory 21 is installed on the behaviour of the computer equipment 2 commonly used in storageMake system and types of applications software, such as the code coverage calculates the program code etc. of analysis system 20.In addition, described depositReservoir 21 can be also used for temporarily storing the Various types of data that has exported or will export.
The processor 22 can be in some embodiments central processing unit (Central Processing Unit,CPU), controller, microcontroller, microprocessor or other data processing chips.The processor 22 is commonly used in the control meterCalculate machine equipment 2 overall operation, such as execute with the computer equipment 2 carry out data interaction or communication it is relevant control andProcessing etc..In the present embodiment, the processor 22 is for running the program code stored in the memory 21 or processing numberAccording to, such as run the code coverage and calculate analysis system 20 etc..
The network interface 23 may include radio network interface or wired network interface, which is commonly used inCommunication connection is established between the computer equipment 2 and other computer equipments.For example, the network interface 23 is for passing throughThe computer equipment 2 is connected by network with exterior terminal, establishes data between the computer equipment 2 and exterior terminalTransmission channel and communication connection etc..The network can be intranet (Intranet), internet (Internet), the whole worldMobile communcations system (Global System of Mobile communication, GSM), wideband code division multiple access(Wideband Code Division Multiple Access, WCDMA), 4G network, 5G network, bluetooth (Bluetooth),The wirelessly or non-wirelessly network such as Wi-Fi.
It should be pointed out that Fig. 4 illustrates only the computer equipment 2 with component 21-23, it should be understood that simultaneouslyAll components shown realistic are not applied, the implementation that can be substituted is more or less component.
In the present embodiment, the code coverage being stored in memory 21 calculates analysis system 20 can be by oneA or multiple processors (the present embodiment is processor 22) are performed, to complete the behaviour of above-mentioned code coverage calculation and analysis methodsMake.
In addition, a kind of computer readable storage medium of the present invention, code is stored in the computer readable storage medium and is coveredLid rate calculates analysis system 20 and realizes when code coverage calculating analysis system 20 can be executed by one or more processorsThe operation of above-mentioned code coverage calculation and analysis methods or electronic device.
Although specific embodiments of the present invention have been described above, it will be appreciated by those of skill in the art that this is onlyFor example, protection scope of the present invention is to be defined by the appended claims.Those skilled in the art without departing substantially fromUnder the premise of the principle and substance of the present invention, many changes and modifications may be made, but these change andModification each falls within protection scope of the present invention.