CN110389764A - Dead code method for cleaning, equipment, storage medium and device - Google Patents
Dead code method for cleaning, equipment, storage medium and device Download PDFInfo
- Publication number
- CN110389764A CN110389764A CN201910539940.0A CN201910539940A CN110389764A CN 110389764 A CN110389764 A CN 110389764A CN 201910539940 A CN201910539940 A CN 201910539940A CN 110389764 A CN110389764 A CN 110389764A
- Authority
- CN
- China
- Prior art keywords
- code
- target
- carried out
- dead
- cleaning
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3676—Test management for coverage analysis
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/443—Optimisation
- G06F8/4434—Reducing the memory space required by the program code
- G06F8/4435—Detection or removal of dead or redundant code
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Software Systems (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a kind of dead code method for cleaning, equipment, storage medium and devices, this method comprises: obtaining the source code of destination application, analyze source code, obtain trunk code and plug-in code;Pitching pile function is set in the function entrance of trunk code and the function entrance of plug-in code, obtains pitching pile code;Default automatic test cases are executed, are reported by the coverage rate that pitching pile code obtains source code;Using coverage rate report in target be not carried out duration the target in coverage rate report is not carried out by code is screened, obtain target dead code;The delete target dead code from source code.It is managed based on research and development, code is not carried out by the target in the coverage rate report of source code and corresponding target is not carried out duration, filter out the target dead code in source code, remove dead code, so that checking that code is cheer and bright, development efficiency is improved, the volume of the installation kit of destination application is mitigated, improves operational efficiency.
Description
Technical field
The present invention relates to the technical field of artificial intelligence more particularly to a kind of dead code method for cleaning, equipment, storage Jie
Matter and device.
Background technique
Currently, update of the application program due to version, functional requirement constantly changes and optimizes, user interface (User
Interface writes a Chinese character in simplified form UI) pattern constantly changes and some old patterns are abandoned, cause in application development project
It has been taken less than there are a pile but still existing waste resources, has caused the installation of application program to contract project big problem, apply
The installation of program contract project it is bigger, downloading installation process in, they expend flow can be more, installation the waiting time can also get over
It is long, for product itself, it is meant that downloading conversion ratio can be lower.
Above content is only used to facilitate the understanding of the technical scheme, and is not represented and is recognized that above content is existing skill
Art.
Summary of the invention
The main purpose of the present invention is to provide a kind of dead code method for cleaning, equipment, storage medium and devices, it is intended to
It solves application program in the prior art and the technical problem contracted project and cause operational efficiency low greatly is installed.
To achieve the above object, the present invention provides a kind of dead code method for cleaning, the dead code method for cleaning packet
Include following steps:
The source code for obtaining destination application, analyzes the source code, obtains the trunk generation of the source code
Code and plug-in code;
The function entrance of the trunk code and the function entrance of the plug-in code are obtained, in the letter of the trunk code
Pitching pile function is arranged in the function entrance of number entrance and the plug-in code, obtains pitching pile code;
Default automatic test cases are executed, are reported by the coverage rate that the code of pitching pile obtains the source code;
Extract that target is not carried out code and corresponding target is not carried out duration from coverage rate report;
Duration is not carried out using the target code is not carried out to the target and screened, obtain target dead code;
The target dead code is deleted from the source code.
Preferably, described to execute default automatic test cases, the source code is obtained by the code of pitching pile
Coverage rate report, comprising:
Default automatic test cases are executed, test result is obtained;
According to the test result, reported by the coverage rate that the code of pitching pile obtains the source code.
Preferably, the function entrance of the function entrance for obtaining the trunk code and the plug-in code, described
Pitching pile function is arranged in the function entrance of the function entrance of trunk code and the plug-in code, before obtaining pitching pile code, institute
State dead code method for cleaning further include:
The service line functional sequence for obtaining the destination application is write according to the service line functional sequence and is preset certainly
Dynamicization test case.
Preferably, it is described using the target be not carried out duration code be not carried out to the target screen, obtain mesh
Mark dead code, comprising:
Obtain it is default execute duration rule, be not carried out duration using the target and be not carried out in code from the target and screened
Meet the default code for executing duration rule out as target dead code.
Preferably, it is described using the target be not carried out duration code be not carried out to the target screen, obtain mesh
Mark dead code, comprising:
Code is not carried out using the target and the corresponding target is not carried out duration, by default screening model to institute
It states target and is not carried out code and screened, obtain target dead code.
Preferably, the utilization target is not carried out code and the corresponding target is not carried out duration, by default
Screening model is not carried out code to the target and screens, before obtaining target dead code, the dead code cleaning side
Method further include:
The sample for obtaining the destination application is not carried out code, sample is not carried out duration and corresponding sample useless generation
Code;
Code is not carried out according to the sample, the sample is not carried out duration with the corresponding sample dead code to volume
Product neural network model is trained, and obtains default screening model.
Preferably, described before deleting the target dead code in the source code, the dead code cleaning side
Method further include:
The source code and the current code version are carried out backup and deposited by the current code version for obtaining the source code
Storage.
In addition, to achieve the above object, the present invention also proposes a kind of dead code cleaning equipment, the dead code cleaning
Equipment includes the dead code cleaning that memory, processor and being stored in can be run on the memory and on the processor
The step of program, the dead code liquidation procedures is arranged for carrying out dead code method for cleaning as described above.
In addition, to achieve the above object, the present invention also proposes a kind of storage medium, it is stored on the storage medium useless
Code liquidation procedures, the dead code liquidation procedures realize dead code cleaning side as described above when being executed by processor
The step of method.
In addition, to achieve the above object, the present invention also proposes a kind of dead code cleaning plant, the dead code cleaning
Device includes:
It obtains module to analyze the source code for obtaining the source code of destination application, obtains the source
The trunk code and plug-in code of code;
Pitching pile module, for obtaining the function entrance of the trunk code and the function entrance of the plug-in code, in institute
The function entrance of trunk code and the function entrance setting pitching pile function of the plug-in code are stated, pitching pile code is obtained;
Execution module obtains the source code by the code of pitching pile for executing default automatic test cases
Coverage rate report;
Extraction module, for extracting from coverage rate report, target is not carried out code and corresponding target is not carried out
Duration;
Screening module is not carried out code to the target for being not carried out duration using the target and screens, and obtains
Target dead code;
Removing module, for deleting the target dead code from the source code.
In the present invention, by obtaining the source code of destination application, the source code is analyzed, the source is obtained
The trunk code and plug-in code of code obtain the function entrance of the trunk code and the function entrance of the plug-in code,
Pitching pile function is set in the function entrance of the trunk code and the function entrance of the plug-in code, obtains pitching pile code,
Default automatic test cases are executed, is reported by the coverage rate that the code of pitching pile obtains the source code, is covered from described
It extracts that target is not carried out code and corresponding target is not carried out duration in the report of lid rate, is not carried out duration pair using the target
The target is not carried out code and is screened, and obtains target dead code, the target useless generation is deleted from the source code
Code removes dead code based on research and development management, so that checking that code is cheer and bright, improves development efficiency, mitigates target application journey
The volume of the installation kit of sequence improves operational efficiency.
Detailed description of the invention
Fig. 1 is the structural representation of the dead code cleaning equipment for the hardware running environment that the embodiment of the present invention is related to
Figure;
Fig. 2 is the flow diagram of dead code method for cleaning first embodiment of the present invention;
Fig. 3 is the flow diagram of dead code method for cleaning second embodiment of the present invention;
Fig. 4 is the structural block diagram of dead code cleaning plant first embodiment of the present invention.
The embodiments will be further described with reference to the accompanying drawings for the realization, the function and the advantages of the object of the present invention.
Specific embodiment
It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, it is not intended to limit the present invention.
Referring to Fig.1, Fig. 1 is the dead code cleaning equipment structure for the hardware running environment that the embodiment of the present invention is related to
Schematic diagram.
As shown in Figure 1, the dead code cleaning equipment may include: processor 1001, such as central processing unit
(Central Processing Unit, CPU), communication bus 1002, user interface 1003, network interface 1004, memory
1005.Wherein, communication bus 1002 is for realizing the connection communication between these components.User interface 1003 may include display
Shield (Display), optional user interface 1003 can also include standard wireline interface and wireless interface, for user interface
1003 wireline interface can be USB interface in the present invention.Network interface 1004 optionally may include standard wireline interface,
Wireless interface (such as Wireless Fidelity (WIreless-FIdelity, WI-FI) interface).Memory 1005 can be the random of high speed
Memory (Random Access Memory, RAM) memory is accessed, stable memory (Non-volatile is also possible to
Memory, NVM), such as magnetic disk storage.Memory 1005 optionally can also be the storage independently of aforementioned processor 1001
Device.
It will be understood by those skilled in the art that structure shown in Fig. 1 does not constitute the limit to dead code cleaning equipment
It is fixed, it may include perhaps combining certain components or different component layouts than illustrating more or fewer components.
As shown in Figure 1, as may include that operating system, network are logical in a kind of memory 1005 of computer storage medium
Believe module, Subscriber Interface Module SIM and dead code liquidation procedures.
In dead code cleaning equipment shown in Fig. 1, network interface 1004 is mainly used for connecting background server, with institute
It states background server and carries out data communication;User interface 1003 is mainly used for connecting user equipment;The dead code cleaning is set
It is standby that the dead code liquidation procedures stored in memory 1005 is called by processor 1001, and offer of the embodiment of the present invention is provided
Dead code method for cleaning.
Based on above-mentioned hardware configuration, the embodiment of dead code method for cleaning of the present invention is proposed.
It is the flow diagram of dead code method for cleaning first embodiment of the present invention referring to Fig. 2, Fig. 2, proposes the present invention
Dead code method for cleaning first embodiment.
In the first embodiment, the dead code method for cleaning the following steps are included:
Step S10: obtaining the source code of destination application, analyzes the source code, obtains the source code
Trunk code and plug-in code.
It should be understood that the executing subject of the present embodiment is the dead code cleaning equipment, wherein the dead code
Cleaning equipment can be the electronic equipments such as PC or server.The source code for obtaining the destination application, in Jenkins
It pulls up a branch and does dead code detection, by generating coverage rate report and then H5 source code pitching pile is to collect coverage rate information
It accuses.Jenkins is an open source software project, is a kind of continuous integrating tool based on Java exploitation, continues weight for monitoring
Multiple work, it is desirable to provide an easy-to-use software platform of opening makes the continuous integrating of software become possible.It can be by described
Source code carries out syntactic analysis, realizes that the code of major function is the trunk code of the source code, realizes the generation of miscellaneous function
Code is the plug-in code of the source code.
Step S20: the function entrance of the trunk code and the function entrance of the plug-in code are obtained, in the trunk
Pitching pile function is arranged in the function entrance of the function entrance of code and the plug-in code, obtains pitching pile code.
It should be understood that generally requiring to know certain information, such as: the source code during realizing coverage test
Middle executable statement is performed the case where (i.e. capped), the path that the source code executes, reference or definition of variable etc..It wants
Want to obtain this category information, needs to track the implementation procedure of the source code, or the process executed by computer in source code
In automatically record.The code that relevant work can be completed by being inserted into the source code, copies pitching pile function file to institute
State in trunk code and the plug-in code, by the pitching pile function file to the trunk code and the plug-in code into
Row traversal, obtains all function files in all function files and the plug-in code in the trunk code, to described
All function files in all function files and the plug-in code in trunk code carry out syntactic analysis, obtain the master
The function entrance of each function file in dry code and the plug-in code, function entrance and the plug-in unit in the trunk code
Pitching pile function is arranged in the function entrance of code, obtains pitching pile code.Can by modify AndroidManifest.xml file,
Increase a coverage rate and generates service;Build_common.xml file is modified, realizes the modification of trunk code pitching pile;Modification
Build_plugins.xml file, realizes the pitching pile modification of plug-in code, so that the source code is transformed into the pitching pile
Code.
Step S30: default automatic test cases are executed, the covering of the source code is obtained by the code of pitching pile
Rate report.
It will be appreciated that in order to test the source code, to obtain covering for the source code according to test result analysis
The report of lid rate, can write multiple UI automatic test cases previously according to the function of the destination application, i.e., described default
Automatic test cases, by the way that in the UI automatic test cases that execution Java language is write in a browser, UI automates foot
Originally the survey of public module (such as homepage account page), each service line (service lines such as oxygen is borrowed or i is borrowed) functional sequence is specifically included
Case script on probation, can automatic imitation manually operated on APP, click button or input etc., after enabling JSCover service, execute
The default automatic test cases obtain the report of H5 code coverage, i.e., the coverage rate report of the described source code.The present embodiment
In, before the step S20, further includes: the service line functional sequence for obtaining the destination application, according to the service line
Functional sequence writes default automatic test cases.
In the present embodiment, the step S30, comprising:
Default automatic test cases are executed, test result is obtained;
According to the test result, reported by the coverage rate that the code of pitching pile obtains the source code.
It should be noted that can be generated by writing the build mode of report report as a result, generate report, by with
Lower step operation, for example, being respectively there are three the ec files of the test result of the execution default automatic test cases
Yyb1.ec, yyb2.ec and yyb3.ec.The classes.zip that coverage rate is packaged in result is dropped into template root and is solved
Pressure;The address svn and version number when according to packing, remove source code and are put into src catalogue, svn is the abbreviation of Subversion, is
The version control system of one open source code;Ec file (yyb1.ec, yyb2.ec and yyb3.ec) is all dropped into template root
In catalogue;Build_property file is modified, title is write as into value (removing ec suffix);Build file, such as nothing
Path change, it is basic not have to modify, the build_group that build file takes, respectively<group name=" YYB ">,<
Group name=" plugin_power_save " >;Ant is executed, report catalogue will generate;After report catalogue generates,
The coverage rate report can be obtained by entering to execute index.
In the concrete realization, js code coverage can be obtained by establishing JSCover service, JSCover service is realized
Principle is exactly to realize to H5 code pitching pile, is ordered as follows: java-jar target/dist/JSCover-all.jar-ws--
Document-root=doc/example--report-dir=target;After enabling JSCover service, executes automation and survey
Training sheet obtains the report of H5 code coverage.
Step S40: extract that target is not carried out code and corresponding target is not carried out duration from coverage rate report.
It will be appreciated that the coverage rate report includes performing which code, the time that code executes and code to execute
The information such as a result can then extract from coverage rate report and be not carried out code.For row coverage rate, from the coverage rate report
Announcement finds out that a total of first quantity row has covered the second quantity row.The coverage rate report is analyzed by executing java script
And corresponding source code, show which code is not carried out in the source code, and generate how many days how many row are not used
It arrives, i.e., the described target is not carried out duration, generates dead code analysis report.Java is a kind of programming language, can write Java
Script is reported coverage rate and source code carries out processing analysis, specifically includes in the file to coverage rate report and source code
Hold the processing of character string and create the processing logic of object, is realized especially by bottom code, the purpose of the java script
It is the analysis coverage rate report and the source code, to export which code is not carried out.It is described in the present embodiment
Step S40, comprising: coverage rate report and the source code are analyzed by default script, from the coverage rate report
Extract that target is not carried out code and corresponding target is not carried out duration in announcement.
It should be understood that being directed to extra cascading style sheets (Cascading Style Sheets, write a Chinese character in simplified form CSS) pattern generation
Code can also analyze never call after which id style definitions by java script, not used layout pattern or picture resource etc., from
And it can also obtain CSS dead code analysis report.For example, CSS be defined pattern daohang, caidan, leibiao and
Biaoti, but only used in the page in implementation of test cases: caidan and biaoti, that is to say, that also
The two model codes of daohang and leibiao are not carried out, then this extra two model code is that the target is not held
Line code.
Step S50: being not carried out duration using the target and be not carried out code to the target and screen, obtain target without
Use code.
It should be noted that default execution duration rule can be set in conjunction with type of code according to previous experiences, it is described pre-
If executing duration rule includes that the corresponding code of each H5 code executes duration threshold value, extracted from the default execution duration rule
The target is not carried out the corresponding object code of code and executes duration threshold value out, and the target is not carried out duration and the target
Code executes duration threshold value and is compared, if the target, which is not carried out duration, executes duration threshold value more than the object code,
Assert that the target is not carried out duration and the default execution duration rule match success, the target of successful match is not carried out duration
Corresponding target is not carried out code, that is, is more than that the object code executes the target of duration threshold value to be not carried out duration corresponding
Target is not carried out code, screens as the target dead code.For example, in above-mentioned example, daohang and leibiao the two
Model code is that the target is not carried out code, if the target of the two model codes of daohang and leibiao is not carried out duration
The default execution duration rule can be matched, then the two model codes of daohang and leibiao can be screened as the mesh
Mark dead code.In the present embodiment, the step S50, comprising: obtain default execution duration rule, do not held using the target
Row duration be not carried out from the target filtered out in code meet it is described it is default execute duration rule code it is useless as target
Code.
Step S60: the target dead code is deleted from the source code.
It should be understood that can be by the target dead code from the application program of current version (Application, abbreviation
APP it is deleted in installation kit (AndroidPackage writes a Chinese character in simplified form APK)), to reduce dead code, mitigates the APK of APP
Backpack body product, improves user experience.Such as in above-mentioned example, daohang and the two model codes of leibiao be the target without
With code, by daohang and leibiao, the two model codes are deleted from the APK of the destination application, APK
Volume reduces, and in downloading installation process, the flow of consuming is also accordingly reduced, and the installation waiting time can also reduce, for product
Itself, it is meant that downloading conversion ratio improves, to improve user experience.
In the present embodiment, by obtaining the source code of destination application, the source code is analyzed, described in acquisition
The function of the trunk code and plug-in code of source code, the function entrance and the plug-in code that obtain the trunk code enters
Mouthful, pitching pile function is set in the function entrance of the trunk code and the function entrance of the plug-in code, obtains pitching pile generation
Code executes default automatic test cases, is reported by the coverage rate that the code of pitching pile obtains the source code, from described
It extracts that target is not carried out code and corresponding target is not carried out duration in coverage rate report, is not carried out duration using the target
Code is not carried out to the target to screen, and obtains target dead code, it is useless that the target is deleted from the source code
Code removes dead code based on research and development management, so that checking that code is cheer and bright, improves development efficiency, mitigates target application
The volume of the installation kit of program improves operational efficiency.
It is the flow diagram of dead code method for cleaning second embodiment of the present invention referring to Fig. 3, Fig. 3, is based on above-mentioned Fig. 2
Shown in first embodiment, propose the second embodiment of dead code method for cleaning of the present invention.
In a second embodiment, the step S50, comprising:
Step S501: being not carried out code using the target and the corresponding target be not carried out duration, passes through default sieve
Modeling type is not carried out code to the target and screens, and obtains target dead code.
It should be understood that it is based on machine learning in order to improve the screening efficiency and accuracy rate of the target dead code, it can
It obtains a large amount of history test case and executes data, extract sample from history test case execution data and be not carried out generation
Code, sample be not carried out duration and corresponding sample dead code, code is not carried out according to the sample, sample be not carried out duration and
Corresponding sample dead code is trained convolutional neural networks model, obtains default screening model, the default screening mould
Type have passed through a large amount of sample training, so as to accurately filter out dead code.It can be by the way that the target be not carried out generation
Code and the corresponding target are not carried out duration and input the default screening model, export the target dead code.This implementation
In example, before the step S501, comprising: when the sample for obtaining the destination application is not carried out code, sample is not carried out
It grows and corresponding sample dead code;Be not carried out code according to the sample, the sample be not carried out duration with it is corresponding described
Sample dead code is trained convolutional neural networks model, obtains default screening model.
In the present embodiment, before the step S60, further includes:
The source code and the current code version are carried out backup and deposited by the current code version for obtaining the source code
Storage.
It should be noted that before not removing the target dead code, can application program APK to current version it is pre-
It first backups, i.e., makes a backup store the current code version of the source code and the source code, it is subsequent if desired to use
The deleted target dead code can directly extract enforcement of going forward side by side from the source code of the current code version of backup
With.
In the present embodiment, code is not carried out using the target and the corresponding target is not carried out duration, by pre-
If screening model is not carried out code to the target and screens, target dead code is obtained, machine learning is based on, by a large amount of
The default screening model of sample training can be improved the screening accuracy rate and efficiency of the target dead code.
In addition, the embodiment of the present invention also proposes a kind of storage medium, dead code cleaning is stored on the storage medium
Program, the dead code liquidation procedures realize the step of dead code method for cleaning as described above when being executed by processor
Suddenly.
In addition, the embodiment of the present invention also proposes a kind of dead code cleaning plant, the dead code cleaning referring to Fig. 4
Device includes:
Module 10 is obtained to analyze the source code, described in acquisition for obtaining the source code of destination application
The trunk code and plug-in code of source code.
It should be understood that obtaining the source code of the destination application, a branch is pulled up in Jenkins and does useless generation
Code detection, by generating coverage rate report and then H5 source code pitching pile is to collect coverage rate information.Jenkins is an open source
Software project is a kind of continuous integrating tool based on Java exploitation, for monitoring persistently duplicate work, it is desirable to provide one
Open easy-to-use software platform, makes the continuous integrating of software become possible.It can be real by carrying out syntactic analysis to the source code
The code of existing major function is the trunk code of the source code, realizes that the code of miscellaneous function is the plug-in unit generation of the source code
Code.
Pitching pile module 20, for obtaining the function entrance of the trunk code and the function entrance of the plug-in code, In
Pitching pile function is arranged in the function entrance of the trunk code and the function entrance of the plug-in code, obtains pitching pile code.
It should be understood that generally requiring to know certain information, such as: the source code during realizing coverage test
Middle executable statement is performed the case where (i.e. capped), the path that the source code executes, reference or definition of variable etc..It wants
Want to obtain this category information, needs to track the implementation procedure of the source code, or the process executed by computer in source code
In automatically record.The code that relevant work can be completed by being inserted into the source code, copies pitching pile function file to institute
State in trunk code and the plug-in code, by the pitching pile function file to the trunk code and the plug-in code into
Row traversal, obtains all function files in all function files and the plug-in code in the trunk code, to described
All function files in all function files and the plug-in code in trunk code carry out syntactic analysis, obtain the master
The function entrance of each function file in dry code and the plug-in code, function entrance and the plug-in unit in the trunk code
Pitching pile function is arranged in the function entrance of code, obtains pitching pile code.Can by modify AndroidManifest.xml file,
Increase a coverage rate and generates service;Build_common.xml file is modified, realizes the modification of trunk code pitching pile;Modification
Build_plugins.xml file, realizes the pitching pile modification of plug-in code, so that the source code is transformed into the pitching pile
Code.
Execution module 30 obtains the source generation by the code of pitching pile for executing default automatic test cases
The coverage rate report of code.
It will be appreciated that in order to test the source code, to obtain covering for the source code according to test result analysis
The report of lid rate, can write multiple UI automatic test cases previously according to the function of the destination application, i.e., described default
Automatic test cases, by the way that in the UI automatic test cases that execution Java language is write in a browser, UI automates foot
Originally the survey of public module (such as homepage account page), each service line (service lines such as oxygen is borrowed or i is borrowed) functional sequence is specifically included
Case script on probation, can automatic imitation manually operated on APP, click button or input etc., after enabling JSCover service, execute
The default automatic test cases obtain the report of H5 code coverage, i.e., the coverage rate report of the described source code.The present embodiment
In, further includes: module is write, for obtaining the service line functional sequence of the destination application, according to the service line function
Energy process writes default automatic test cases.
In the present embodiment, the execution module 30 adds for executing default automatic test cases, obtains test result;
According to the test result, reported by the coverage rate that the code of pitching pile obtains the source code.
It should be noted that can be generated by writing the build mode of report report as a result, generate report, by with
Lower step operation, for example, being respectively there are three the ec files of the test result of the execution default automatic test cases
Yyb1.ec, yyb2.ec and yyb3.ec.The classes.zip that coverage rate is packaged in result is dropped into template root and is solved
Pressure;The address svn and version number when according to packing, remove source code and are put into src catalogue, svn is the abbreviation of Subversion, is
The version control system of one open source code;Ec file (yyb1.ec, yyb2.ec and yyb3.ec) is all dropped into template root
In catalogue;Build_property file is modified, title is write as into value (removing ec suffix);Build file, such as nothing
Path change, it is basic not have to modify, the build_group that build file takes, respectively<group name=" YYB ">,<
Group name=" plugin_power_save " >;Ant is executed, report catalogue will generate;After report catalogue generates,
The coverage rate report can be obtained by entering to execute index.
In the concrete realization, js code coverage can be obtained by establishing JSCover service, JSCover service is realized
Principle is exactly to realize to H5 code pitching pile, is ordered as follows: java-jar target/dist/JSCover-all.jar-ws--
Document-root=doc/example--report-dir=target;After enabling JSCover service, executes automation and survey
Training sheet obtains the report of H5 code coverage.
Extraction module 40, for extracting from coverage rate report, target is not carried out code and corresponding target is not held
Row duration.
It will be appreciated that the coverage rate report includes performing which code, the time that code executes and code to execute
The information such as a result can then extract from coverage rate report and be not carried out code.For row coverage rate, from the coverage rate report
Announcement finds out that a total of first quantity row has covered the second quantity row.The coverage rate report is analyzed by executing java script
And corresponding source code, show which code is not carried out in the source code, and generate how many days how many row are not used
It arrives, i.e., the described target is not carried out duration, generates dead code analysis report.Java is a kind of programming language, can write Java
Script is reported coverage rate and source code carries out processing analysis, specifically includes in the file to coverage rate report and source code
Hold the processing of character string and create the processing logic of object, is realized especially by bottom code, the purpose of the java script
It is the analysis coverage rate report and the source code, to export which code is not carried out.It is described in the present embodiment
Extraction module 40 is also used to analyze coverage rate report and the source code by default script, from the covering
Extract that target is not carried out code and corresponding target is not carried out duration in rate report.
It should be understood that being directed to extra cascading style sheets (Cascading Style Sheets, write a Chinese character in simplified form CSS) pattern generation
Code can also analyze never call after which id style definitions by java script, not used layout pattern or picture resource etc., from
And it can also obtain CSS dead code analysis report.For example, CSS be defined pattern daohang, caidan, leibiao and
Biaoti, but only used in the page in implementation of test cases: caidan and biaoti, that is to say, that also
The two model codes of daohang and leibiao are not carried out, then this extra two model code is that the target is not held
Line code.
Screening module 50 is not carried out code to the target for being not carried out duration using the target and screens, obtains
Obtain target dead code.
It should be noted that default execution duration rule can be set in conjunction with type of code according to previous experiences, it is described pre-
If executing duration rule includes that the corresponding code of each H5 code executes duration threshold value, extracted from the default execution duration rule
The target is not carried out the corresponding object code of code and executes duration threshold value out, and the target is not carried out duration and the target
Code executes duration threshold value and is compared, if the target, which is not carried out duration, executes duration threshold value more than the object code,
Assert that the target is not carried out duration and the default execution duration rule match success, the target of successful match is not carried out duration
Corresponding target is not carried out code, that is, is more than that the object code executes the target of duration threshold value to be not carried out duration corresponding
Target is not carried out code, screens as the target dead code.For example, in above-mentioned example, daohang and leibiao the two
Model code is that the target is not carried out code, if the target of the two model codes of daohang and leibiao is not carried out duration
The default execution duration rule can be matched, then the two model codes of daohang and leibiao can be screened as the mesh
Mark dead code.In the present embodiment, the screening module 50 is also used to obtain default execution duration rule, utilizes the target
It is not carried out duration and is not carried out to filter out in code from the target and meet the default code for executing duration rule as target
Dead code.
Removing module 60, for deleting the target dead code from the source code.
It should be understood that can be by the target dead code from the application program of current version (Application, abbreviation
APP it is deleted in installation kit (AndroidPackage writes a Chinese character in simplified form APK)), to reduce dead code, mitigates the APK of APP
Backpack body product, improves user experience.Such as in above-mentioned example, daohang and the two model codes of leibiao be the target without
With code, by daohang and leibiao, the two model codes are deleted from the APK of the destination application, APK
Volume reduces, and in downloading installation process, the flow of consuming is also accordingly reduced, and the installation waiting time can also reduce, for product
Itself, it is meant that downloading conversion ratio improves, to improve user experience.
In the present embodiment, by obtaining the source code of destination application, the source code is analyzed, described in acquisition
The function of the trunk code and plug-in code of source code, the function entrance and the plug-in code that obtain the trunk code enters
Mouthful, pitching pile function is set in the function entrance of the trunk code and the function entrance of the plug-in code, obtains pitching pile generation
Code executes default automatic test cases, is reported by the coverage rate that the code of pitching pile obtains the source code, from described
It extracts that target is not carried out code and corresponding target is not carried out duration in coverage rate report, is not carried out duration using the target
Code is not carried out to the target to screen, and obtains target dead code, it is useless that the target is deleted from the source code
Code removes dead code based on research and development management, so that checking that code is cheer and bright, improves development efficiency, mitigates target application
The volume of the installation kit of program improves operational efficiency.
In one embodiment, the screening module 50 is also used to be not carried out code and corresponding described using the target
Target is not carried out duration, is not carried out code to the target by default screening model and screens, obtains target dead code.
In one embodiment, the dead code cleaning plant further include:
Obtain module, the sample for obtaining the destination application is not carried out code, sample be not carried out duration with it is right
The sample dead code answered;
Training module, for being not carried out code according to the sample, the sample is not carried out duration and the corresponding sample
This dead code is trained convolutional neural networks model, obtains default screening model.
In one embodiment, the dead code cleaning plant further include:
Backup memory module, for obtaining the current code version of the source code, by the source code and described current
Code release makes a backup store.
The other embodiments or specific implementation of dead code cleaning plant of the present invention can refer to above-mentioned each method
Embodiment, details are not described herein again.
It should be noted that, in this document, the terms "include", "comprise" or its any other variant are intended to non-row
His property includes, so that the process, method, article or the system that include a series of elements not only include those elements, and
And further include other elements that are not explicitly listed, or further include for this process, method, article or system institute it is intrinsic
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including being somebody's turn to do
There is also other identical elements in the process, method of element, article or system.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.If listing equipment for drying
Unit claim in, several in these devices, which can be, to be embodied by the same item of hardware.Word first,
Second and the use of third etc. do not indicate any sequence, can be mark by these word explanations.
Through the above description of the embodiments, those skilled in the art can be understood that above-described embodiment side
Method can be realized by means of software and necessary general hardware platform, naturally it is also possible to by hardware, but in many cases
The former is more preferably embodiment.Based on this understanding, technical solution of the present invention substantially in other words does the prior art
The part contributed out can be embodied in the form of software products, which is stored in a storage medium
(such as read-only memory mirror image (Read Only Memory image, ROM)/random access memory (Random Access
Memory, RAM), magnetic disk, CD) in, including some instructions are used so that terminal device (can be mobile phone, computer,
Server, air conditioner or network equipment etc.) execute method described in each embodiment of the present invention.
The above is only a preferred embodiment of the present invention, is not intended to limit the scope of the invention, all to utilize this hair
Equivalent structure or equivalent flow shift made by bright specification and accompanying drawing content is applied directly or indirectly in other relevant skills
Art field, is included within the scope of the present invention.
Claims (10)
1. a kind of dead code method for cleaning, which is characterized in that the dead code method for cleaning the following steps are included:
Obtain destination application source code, the source code is analyzed, obtain the source code trunk code and
Plug-in code;
The function entrance of the trunk code and the function entrance of the plug-in code are obtained, is entered in the function of the trunk code
Pitching pile function is arranged in the function entrance of mouth and the plug-in code, obtains pitching pile code;
Default automatic test cases are executed, are reported by the coverage rate that the code of pitching pile obtains the source code;
Extract that target is not carried out code and corresponding target is not carried out duration from coverage rate report;
Duration is not carried out using the target code is not carried out to the target and screened, obtain target dead code;
The target dead code is deleted from the source code.
2. dead code method for cleaning as described in claim 1, which is characterized in that described to execute default automatic test use
Example is reported by the coverage rate that the code of pitching pile obtains the source code, comprising:
Default automatic test cases are executed, test result is obtained;
According to the test result, reported by the coverage rate that the code of pitching pile obtains the source code.
3. dead code method for cleaning as claimed in claim 2, which is characterized in that the function for obtaining the trunk code
The function entrance of entrance and the plug-in code, in the function entrance of the trunk code and the function entrance of the plug-in code
Pitching pile function is set, before obtaining pitching pile code, the dead code method for cleaning further include:
The service line functional sequence for obtaining the destination application writes default automation according to the service line functional sequence
Test case.
4. dead code method for cleaning as described in claim 1, which is characterized in that described to be not carried out duration using the target
Code is not carried out to the target to screen, and obtains target dead code, comprising:
Obtain it is default execute duration rule, be not carried out duration using the target and be not carried out in code from the target and filter out symbol
The default code for executing duration rule is closed as target dead code.
5. dead code method for cleaning as described in claim 1, which is characterized in that described to be not carried out duration using the target
Code is not carried out to the target to screen, and obtains target dead code, comprising:
Code is not carried out using the target and the corresponding target is not carried out duration, by default screening model to the mesh
Mark is not carried out code and is screened, and obtains target dead code.
6. dead code method for cleaning as claimed in claim 5, which is characterized in that described to be not carried out code using the target
And the corresponding target is not carried out duration, is not carried out code to the target by default screening model and screens, obtains
Before target dead code, the dead code method for cleaning further include:
The sample for obtaining the destination application is not carried out code, sample is not carried out duration and corresponding sample dead code;
Code is not carried out according to the sample, the sample is not carried out duration with the corresponding sample dead code to convolution mind
It is trained through network model, obtains default screening model.
7. such as dead code method for cleaning of any of claims 1-6, which is characterized in that described from the source code
Before the middle deletion target dead code, the dead code method for cleaning further include:
The current code version for obtaining the source code makes a backup store the source code and the current code version.
8. a kind of dead code cleaning equipment, which is characterized in that the dead code cleaning equipment includes: memory, processor
And it is stored in the dead code liquidation procedures that can be run on the memory and on the processor, the dead code cleaning
The step of dead code method for cleaning as described in any one of claims 1 to 7 is realized when program is executed by the processor.
9. a kind of storage medium, which is characterized in that be stored with dead code liquidation procedures, the useless generation on the storage medium
Code liquidation procedures realizes the step of the dead code method for cleaning as described in any one of claims 1 to 7 when being executed by processor
Suddenly.
10. a kind of dead code cleaning plant, which is characterized in that the dead code cleaning plant includes:
It obtains module to analyze the source code for obtaining the source code of destination application, obtains the source code
Trunk code and plug-in code;
Pitching pile module, for obtaining the function entrance of the trunk code and the function entrance of the plug-in code, in the master
Pitching pile function is arranged in the function entrance of the function entrance of dry code and the plug-in code, obtains pitching pile code;
Execution module obtains covering for the source code by the code of pitching pile for executing default automatic test cases
The report of lid rate;
Extraction module is not carried out code and when corresponding target is not carried out for extracting target from coverage rate report
It is long;
Screening module is not carried out code to the target for being not carried out duration using the target and screens, and obtains target
Dead code;
Removing module, for deleting the target dead code from the source code.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910539940.0A CN110389764A (en) | 2019-06-19 | 2019-06-19 | Dead code method for cleaning, equipment, storage medium and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910539940.0A CN110389764A (en) | 2019-06-19 | 2019-06-19 | Dead code method for cleaning, equipment, storage medium and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110389764A true CN110389764A (en) | 2019-10-29 |
Family
ID=68285594
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910539940.0A Pending CN110389764A (en) | 2019-06-19 | 2019-06-19 | Dead code method for cleaning, equipment, storage medium and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110389764A (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111580824A (en) * | 2020-03-30 | 2020-08-25 | 北京达佳互联信息技术有限公司 | Program optimization method, device and storage medium |
CN111831573A (en) * | 2020-07-27 | 2020-10-27 | 中国工商银行股份有限公司 | Method, device, computer system and medium for determining code branch coverage condition |
CN111913878A (en) * | 2020-07-13 | 2020-11-10 | 苏州洞察云信息技术有限公司 | Program analysis result-based bytecode instrumentation method, device and storage medium |
CN112395203A (en) * | 2020-11-30 | 2021-02-23 | 京东数字科技控股股份有限公司 | Program testing method, device and storage medium |
CN113835686A (en) * | 2020-06-08 | 2021-12-24 | 华为技术有限公司 | Code processing method and device |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050166194A1 (en) * | 2004-01-28 | 2005-07-28 | Ati Technologies, Inc. | Method and apparatus for static single assignment form dead code elimination |
US20130159839A1 (en) * | 2011-12-14 | 2013-06-20 | Microsoft Corporation | Semantic compression of cascading style sheets |
CN104881274A (en) * | 2014-02-28 | 2015-09-02 | 上海斐讯数据通信技术有限公司 | Method for identifying useless codes |
CN105205080A (en) * | 2014-06-26 | 2015-12-30 | 阿里巴巴集团控股有限公司 | Redundant file clearing method, device and system |
US20160011889A1 (en) * | 2014-07-10 | 2016-01-14 | Fujitsu Limited | Simulation method and storage medium |
US20160321036A1 (en) * | 2015-04-28 | 2016-11-03 | Box, Inc. | Dynamically monitoring code execution activity to identify and manage inactive code |
CN108415821A (en) * | 2017-02-09 | 2018-08-17 | 腾讯科技(深圳)有限公司 | The generation method and device of test report |
CN108897569A (en) * | 2018-05-30 | 2018-11-27 | 福建天晴在线互动科技有限公司 | The method for cleaning and computer readable storage medium of iOS engineering discarded record |
CN109460234A (en) * | 2018-09-04 | 2019-03-12 | 中国平安人寿保险股份有限公司 | Application program method for reducing body weight, device, terminal and storage medium |
CN110688118A (en) * | 2019-10-28 | 2020-01-14 | 郑州阿帕斯科技有限公司 | Webpage optimization method and device |
-
2019
- 2019-06-19 CN CN201910539940.0A patent/CN110389764A/en active Pending
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050166194A1 (en) * | 2004-01-28 | 2005-07-28 | Ati Technologies, Inc. | Method and apparatus for static single assignment form dead code elimination |
US20130159839A1 (en) * | 2011-12-14 | 2013-06-20 | Microsoft Corporation | Semantic compression of cascading style sheets |
CN104881274A (en) * | 2014-02-28 | 2015-09-02 | 上海斐讯数据通信技术有限公司 | Method for identifying useless codes |
CN105205080A (en) * | 2014-06-26 | 2015-12-30 | 阿里巴巴集团控股有限公司 | Redundant file clearing method, device and system |
US20160011889A1 (en) * | 2014-07-10 | 2016-01-14 | Fujitsu Limited | Simulation method and storage medium |
US20160321036A1 (en) * | 2015-04-28 | 2016-11-03 | Box, Inc. | Dynamically monitoring code execution activity to identify and manage inactive code |
CN108415821A (en) * | 2017-02-09 | 2018-08-17 | 腾讯科技(深圳)有限公司 | The generation method and device of test report |
CN108897569A (en) * | 2018-05-30 | 2018-11-27 | 福建天晴在线互动科技有限公司 | The method for cleaning and computer readable storage medium of iOS engineering discarded record |
CN109460234A (en) * | 2018-09-04 | 2019-03-12 | 中国平安人寿保险股份有限公司 | Application program method for reducing body weight, device, terminal and storage medium |
CN110688118A (en) * | 2019-10-28 | 2020-01-14 | 郑州阿帕斯科技有限公司 | Webpage optimization method and device |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111580824A (en) * | 2020-03-30 | 2020-08-25 | 北京达佳互联信息技术有限公司 | Program optimization method, device and storage medium |
CN111580824B (en) * | 2020-03-30 | 2024-05-07 | 北京达佳互联信息技术有限公司 | Program optimization method, device and storage medium |
CN113835686A (en) * | 2020-06-08 | 2021-12-24 | 华为技术有限公司 | Code processing method and device |
CN111913878A (en) * | 2020-07-13 | 2020-11-10 | 苏州洞察云信息技术有限公司 | Program analysis result-based bytecode instrumentation method, device and storage medium |
CN111913878B (en) * | 2020-07-13 | 2023-09-15 | 苏州洞察云信息技术有限公司 | Byte code instrumentation method, device and storage medium based on program analysis result |
CN111831573A (en) * | 2020-07-27 | 2020-10-27 | 中国工商银行股份有限公司 | Method, device, computer system and medium for determining code branch coverage condition |
CN111831573B (en) * | 2020-07-27 | 2024-03-08 | 中国工商银行股份有限公司 | Method, device, computer system and medium for determining code branch coverage condition |
CN112395203A (en) * | 2020-11-30 | 2021-02-23 | 京东数字科技控股股份有限公司 | Program testing method, device and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110389764A (en) | Dead code method for cleaning, equipment, storage medium and device | |
US11797298B2 (en) | Automating identification of code snippets for library suggestion models | |
US12032475B2 (en) | Automating identification of test cases for library suggestion models | |
US12056487B2 (en) | Automating generation of library suggestion engine models | |
KR101105177B1 (en) | Data container for user interface content data | |
CN107608874A (en) | Method of testing and device | |
CN109086215B (en) | Embedded software unit test case generation method and system | |
CN110941467A (en) | Data processing method, device and system | |
CN105786506A (en) | User interface automatic-generation system and method | |
CN110209387B (en) | Method and device for generating top-level HDL file and computer readable storage medium | |
CN100507871C (en) | Method and system for testing embedded file system | |
CN107894889A (en) | Bury point methods, equipment and computer-readable recording medium | |
CN109189384A (en) | A kind of multiplexing method and device of code | |
CN107451060A (en) | A kind of across mobile terminal automated test frame system | |
CN113553035A (en) | Design and construction method of universal front-end UI component library | |
CN108763042A (en) | A kind of Cloud Server performance data acquisition method and device based on python | |
CN109889587A (en) | Internet of things system automated construction method, device, equipment and storage medium | |
CN101937335B (en) | Method for generating Widget icon, method for generating Widget summary document and Widget engine | |
CN113268243A (en) | Memory prediction method and device, storage medium and electronic equipment | |
CN109491884A (en) | Code method for testing performance, device, computer equipment and medium | |
CN108762765A (en) | Development board program based on contiki systems compiles method for down loading | |
CN109086040A (en) | A kind of method and system quickly generating html code | |
Cockton et al. | Literate development: weaving human context into design specifications | |
CN112241373A (en) | Automatic test method, test device, processor and test system | |
CN109543122B (en) | Content synchronization method, device, storage medium and electronic device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |