CN113867704A - Code test processing method and device, electronic equipment and storage medium - Google Patents

Code test processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113867704A
CN113867704A CN202111014666.9A CN202111014666A CN113867704A CN 113867704 A CN113867704 A CN 113867704A CN 202111014666 A CN202111014666 A CN 202111014666A CN 113867704 A CN113867704 A CN 113867704A
Authority
CN
China
Prior art keywords
annotation
target
code
module
custom
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
Application number
CN202111014666.9A
Other languages
Chinese (zh)
Inventor
胡芸菘
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuba Co Ltd
Original Assignee
Wuba Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Wuba Co Ltd filed Critical Wuba Co Ltd
Priority to CN202111014666.9A priority Critical patent/CN113867704A/en
Publication of CN113867704A publication Critical patent/CN113867704A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3628Software debugging of optimised code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Abstract

The invention provides a code test processing method and device, electronic equipment and a storage medium. The method comprises the following steps: introducing a custom annotation into a source code of a target module to be tested, and an annotation processor for processing the custom annotation, and adding the custom annotation to a target method to be tested in the target module so as to label the target method through the custom annotation; compiling the project to which the target module belongs, and analyzing the custom annotation by the annotation processor in the compiling process of the target module to obtain a target code to be tested; when the project is started, the target code is automatically executed, and the execution result of the target code is returned to obtain the test result of the target code; the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.

Description

Code test processing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code test processing method and apparatus, an electronic device, and a storage medium.
Background
With the development of computer technology, many development platforms can provide a code testing environment. For example, Android provides a set of Java test environment and Android test environment.
But the test framework can generally only be used normally in the main program/project, but does not support well the code testing of individual modules that are relied upon by the project. For example, if the a module depends on the B, C module, if the code is tested in the B module to run normally in the a module, a test entry needs to be added manually, which affects the efficiency of code testing.
Disclosure of Invention
The embodiment of the invention provides a code test processing method and device, electronic equipment and a storage medium, and aims to solve the problem that the code test efficiency is influenced because a test entry needs to be manually added during each test in the conventional code test mode.
In order to solve the technical problem, the invention is realized as follows:
in a first aspect, an embodiment of the present invention provides a code test processing method, including:
introducing a custom annotation into a source code of a target module to be tested, and an annotation processor for processing the custom annotation, and adding the custom annotation to a target method to be tested in the target module so as to label the target method through the custom annotation;
compiling the project to which the target module belongs, and analyzing the custom annotation by the annotation processor in the compiling process of the target module to obtain a target code to be tested;
when the project is started, the target code is automatically executed, and the execution result of the target code is returned to obtain the test result of the target code;
the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
Optionally, in the compiling process of the target module, the step of obtaining the target code to be tested by parsing the custom annotation through the annotation processor includes:
in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
Optionally, before the steps of compiling the project to which the target module belongs and parsing the custom annotation by the annotation processor in the compiling process of the target module to obtain the target code to be tested, the method further includes:
and acquiring a target source code to be tested, and inputting the target source code in the target method, so that the user-defined annotation is analyzed by the annotation processor in the compiling process of the target module to obtain the target code.
Optionally, before the steps of introducing a custom annotation into a source code of a target module to be tested, and adding the custom annotation to a target method to be tested in the target module, an annotation processor for processing the custom annotation, the method further includes:
the custom annotation is constructed in the project, and an annotation processor for processing the custom annotation.
Optionally, the step of automatically executing the object code and returning an execution result of the object code when the project is started includes:
when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code;
the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
Optionally, the engineering comprises engineering constructed based on a compilable language including at least one of Java, Kotlin.
In a second aspect, an embodiment of the present invention provides a code test processing apparatus, including:
the system comprises a code annotation module, a note processor and a target module, wherein the code annotation module is used for introducing a custom note into a source code of the target module to be tested, the note processor is used for processing the custom note, and the custom note is added to a target method to be tested in the target module so as to annotate the target method through the custom note;
the code compiling module is used for compiling the project to which the target module belongs, and analyzing the custom annotation through the annotation processor in the compiling process of the target module to obtain a target code to be tested;
the code testing module is used for automatically executing the target code when the project is started, and returning the execution result of the target code to obtain the testing result of the target code;
the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
Optionally, the code compiling module is specifically configured to:
in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
Optionally, the apparatus further comprises:
and the test code injection module is used for acquiring a target source code to be tested and inputting the target source code into the target method so as to analyze the custom annotation through the annotation processor in the compiling process of the target module to obtain the target code.
Optionally, the apparatus further comprises:
an annotation tool creation module for constructing the custom annotation in the project and an annotation processor for processing the custom annotation.
Optionally, the code testing module is specifically configured to:
when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code;
the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
Optionally, the engineering comprises engineering constructed based on a compilable language including at least one of Java, Kotlin.
In a third aspect, an embodiment of the present invention additionally provides an electronic device, including: a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the code testing processing method according to the first aspect.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when executed by a processor, the computer program implements the steps of the code test processing method according to the first aspect.
In the embodiment of the invention, the target code to be tested is generated by the compiling annotation and annotation processor, so that the code to be tested is automatically executed after the project is started. The code to be tested can be quickly tested only by adding a line of annotation and writing the test code, and the intrusiveness to the engineering interface is small.
Drawings
FIG. 1 is a flow chart of the steps of a code test processing method in an embodiment of the present invention;
FIG. 2 is a flow chart of steps in another method of code test handling in an embodiment of the invention;
FIG. 3 is a schematic structural diagram of a code test processing apparatus according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a call timing diagram during a code test process according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart illustrating steps of a code test processing method according to an embodiment of the present invention is shown.
Step 110, introducing a custom annotation into a source code of a target module to be tested, and an annotation processor for processing the custom annotation, and adding the custom annotation to a target method to be tested in the target module to label the target method through the custom annotation;
step 120, compiling the project to which the target module belongs, and analyzing the custom annotation by the annotation processor in the compiling process of the target module to obtain a target code to be tested;
step 130, when the project is started, automatically executing the target code, and returning an execution result of the target code to obtain a test result of the target code; the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
Since the whole packaging time, compiling time and the like cannot be shortened, in the embodiment of the present invention, it is considered that a test entry can be automatically added from a test entry, so that a project such as App (Application program) can automatically execute a code to be tested when starting, and an execution result is given after the test is passed, so that the time for manually adding a development entry can be greatly saved.
Specifically, a custom annotation can be introduced into a source code of a target module to be tested, and an annotation processor for processing the custom annotation, and the custom annotation is added to a target method to be tested in the target module; compiling the project to which the target module belongs, and analyzing the custom annotation by the annotation processor in the compiling process of the target module to obtain a target code to be tested; and when the project is started, automatically executing the target code and returning an execution result of the target code.
The user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project. Annotation, also known as Java Annotation, is an Annotation mechanism introduced by JDK 5.0. The annotation processor may then process the customized annotation, for example, may parse the code, generate java code, and so on. A notation is essentially a mark that can be marked on key nodes (classes, methods, variables, parameters, packages) in the program code and then detected at compile time or runtime by the program to perform some special operation. Thus, the basic flow of custom annotation usage can be derived:
first, define annotations — equivalent to definition tags;
secondly, annotation is configured, namely marks are marked in program codes required to be used;
third, the annotation is parsed-the tag is detected during compile time or run time, and special operations are performed.
In the embodiment of the invention, the parsing of the custom annotation in the module can be completed by the annotation processor introduced in the module. In addition, in the embodiment of the present invention, the specific form of the custom annotation may also be set by the user according to the requirement, which is not limited to this embodiment of the present invention. Generally speaking, in order to accurately mark the method to be tested of the test, it is necessary to ensure that the currently used custom annotation is different from other existing annotations.
For example, assuming that an App includes A, B, C three modules, and that the code in module a needs to be tested, module a is the target module. Then custom annotations of pre-custom settings may be introduced in module a, as well as an annotation processor for processing the corresponding custom annotations. The modules may be understood as codes corresponding to functional modules in the project, or code modules, and the division manner and the division granularity of each module may be set by user according to requirements, which is not limited in the embodiment of the present invention.
Furthermore, in the embodiments of the present invention, the custom annotation and the annotation processor may be introduced into the source code of the target module in any available manner, and the embodiments of the present invention are not limited thereto. For example, custom annotations required for testing, annotation handlers, etc. may be introduced in the target module's gradle configuration file.
In the embodiment of the present invention, the custom annotation and the corresponding annotation processor may also be set in any available manner, which is not limited to this embodiment of the present invention. Also, the Annotation (Annotation), if it is to be identified, is not left to the Annotation Processor (Annotation Processor). An Annotation Processor (Annotation Processor) is a tool of java, which scans and processes annotations at compile time, whether by the Processor or by the Processor. The Java has a default annotation processor, and a user can also customize the annotation processor, and the annotation processor is used for processing the annotation after registration, for example, the code can be analyzed, the Java code is generated, and the like, and finally the effect of the annotation itself is achieved. The annotation processor takes the annotated class, variable and the like as input contents, and generates java code to be generated through the processing of the annotation processor. The processor may be understood to be a tool that generates code, simply by annotated rules. The generated code can be regarded as the same general code and is finally compiled.
In addition, in order to generate target code based on the annotation processor, corresponding custom annotations also need to be added to the target methods to be tested in the target module.
For example, assuming that the currently set custom annotation is WuBaTestMethod, the custom annotation can also be understood as a test interface, and by introducing the custom annotation, automatic addition of a test entry can be realized. Then the custom annotation may be added to the target method to be tested in the source code of the target module. An example of source code that adds custom annotations to a target method is shown below:
Figure BDA0003239504270000071
wherein, the test method under "@ WuBaTestMethod" is the target method to be tested in the target module. The method can be marked by inserting the custom note "WuBaTestMethod" above it.
After the custom annotation and annotation processor is introduced and set, the target module can be compiled correspondingly in the process of compiling the project to which the target module belongs, and the custom annotation in the source code can be analyzed through the introduced annotation processor in the compiling process of the target module, so that the target code to be tested is obtained. That is, based on the annotation processor, the object code to be tested can be obtained in an annotation mode during compiling. The annotation at compile time is that a program or project processes the annotation in the program or project during compile time through an annotation processor, for example, a class marked by a custom annotation is obtained.
Accordingly, in the compiling process, the executable code of the object program can be matched, and the object code to be tested is contained in the executable code. After the executable code of the corresponding project is installed on the electronic equipment such as the client and the like, when the project is started, the corresponding target code can be automatically executed, and the execution result of the target code is returned, so that the test result of the target code is obtained. Therefore, only predefined self-defined annotation and an annotation processor are required to be introduced into a module where the method to be tested is located, the self-defined annotation and the annotation processor can be repeatedly quoted for many times, and a development inlet or a test inlet does not need to be manually added during each test, so that the time for manually adding an interface can be greatly saved, and the processing efficiency of code testing is improved.
In addition, the compiling annotation is directly static weaving of the code, and the runtime directly runs the code. This is equivalent to putting all things to be done at runtime into the compile time. The runtime annotation reflects or bytecode modifies, a large number of reflections are not only slow, but also the field cache of various reflections is annotated in runtime occupying memory, thus having an impact on performance. Therefore, in the embodiment of the invention, in order to automatically test the code when the project is started, a compiling annotation mode is preferably adopted, and the compiling annotation can also improve the overall efficiency and performance of the code test to a certain extent.
Optionally, in an embodiment of the present invention, the step 120 further includes: in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
In the embodiment of the present invention, after the setting in step 110 is performed, through the compiling project, the customized annotation processor can parse the customized annotation therein, and complete the generation of the object code.
When the user-defined annotation is analyzed through the annotation processor in each compiling process, in order to avoid that historical use traces of the annotation processor influence the current annotation analysis, the annotation processor can be initialized before being used each time. In embodiments of the invention, the annotation processor may be initialized in any available manner, and embodiments of the invention are not limited in this respect. For example, in general, an init method is provided specifically in an annotation processor, and is used specifically for annotation processor-related initialization operations.
After the initialization is completed, the initialized annotation processor can sequentially execute the steps S2-S4 to obtain all the custom annotations in the target module which need to be processed by the annotation processor, so as to obtain all the methods labeled by each corresponding custom annotation, and then call each method labeled by each corresponding custom annotation through reflection to generate a target code, thereby completing the annotation process for compiling the custom annotations.
Referring to fig. 2, in the embodiment of the present invention, before step 110, the method may further include:
step T10, constructing the custom annotation in the project, and an annotation processor for processing the custom annotation.
As described above, in the embodiment of the present invention, when a custom annotation and an annotation processor for processing the custom annotation are introduced, but an annotation processor provided by a development tool may not necessarily meet the current parsing requirement, the currently required custom annotation and an annotation processor for processing the custom annotation may be constructed in a project according to the requirement.
In embodiments of the present invention, the custom annotations may be created in any available manner, and the annotation processor may be configured to process the corresponding custom annotations, which are not limited in this embodiment of the present invention.
For example, for the above-mentioned custom annotation "WuBaTestMethod" that can act on a class method, that is, can mark the class method, the creation of the custom annotation can be performed in the source code of the project by the following code segment example:
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public@interface WuBaTestMethod{
}
the code content included in the WuBaTestMethod { } may be set according to a requirement, or may be kept empty, which is not limited in this embodiment of the present invention. "RetentionPolicy.CLASS" indicates a compile-time annotation that @ Retention (RetenionPolicy.CLASS) acts on class bytecode with a life cycle that is only valid between compilers. CLASS indicates that annotations remain only to the compilation stage.
Referring to fig. 2, in the embodiment of the present invention, before step 120, the method may further include:
and T20, acquiring a target source code to be tested, and inputting the target source code into the target method, so that the custom annotation is analyzed by the annotation processor in the compiling process of the target module to obtain the target code.
In the embodiment of the invention, the target source code to be tested can be recorded into the target method of the self-defined annotation marking before the engineering compiling, and the target source code can also be directly written in the target method needing automatic testing. Therefore, whether the code to be tested is correct or not can be debugged by compiling the whole project. That is, in the compiling process of the target module, the self-defined annotation in the target module is analyzed by the annotation processor, and the compiled target code corresponding to the target source code is obtained.
For example, for the source code example described above where custom annotations are added to the target method, where the defined function method test, the target source code may be written therein or the target source code to be tested may be entered into the method.
Optionally, in an embodiment of the present invention, the step 130 may further include: when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code; the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
In the embodiment of the invention, in order to automatically test the target code in time while the project is started, a method for automatically executing the target code can be additionally created in the project in advance. Then, when the project is started, calling a target method at the entrance of the project start to automatically execute the target code and return the execution result of the target code; the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
For example, it is assumed that the test is performed by calling the generated target code in a call in the module Application. The specific code may be as follows:
Figure BDA0003239504270000111
bind () is the above-mentioned target method.
Also, a Bind class may be defined in the project as follows to execute the code annotated at compile time by emitting calls. Which contains the specific execution logic of bind ().
Figure BDA0003239504270000112
Figure BDA0003239504270000121
In the embodiment of the present invention, the module containing the Bind class may be understood as an API code injection module, and a call sequence chart between the API code injection module and the custom annotation, the annotation processor, and the module to be tested may be as shown in fig. 3.
Optionally, in an embodiment of the present invention, the engineering includes engineering constructed based on a compilable language, that is, engineering capable of implementing the above-mentioned annotation at compile time, where the compilable language may include, but is not limited to, at least one of Java and Kotlin.
The Kotlin is a static programming language used for modern multi-platform application, can be compiled into Java byte codes and also can be compiled into JavaScript, and is convenient to run on a device without JVM. Java is a door-to-object programming language, which can write desktop applications, Web applications, distributed system and embedded system applications, etc.
The project in the embodiment of the present invention may be a project or a project which is written by any one of the above programming languages having a compiling process to realize annotation during compiling, such as a desktop application program, a Web application program, a distributed system application program, an embedded system application program, and the like.
In the embodiment of the invention, the target code to be tested is generated through the compiling annotation and annotation processor, and the code to be tested is automatically executed after the project such as App and the like is started. Namely, the code segment to be tested can be executed through one line of self-defined annotations, the intrusiveness to an engineering interface is small, and the code to be tested can be quickly tested by only adding one line of annotations to the code to be tested and writing the test code.
Referring to fig. 4, a schematic structural diagram of a code test processing apparatus in an embodiment of the present invention is shown.
The code test processing device of the embodiment of the invention comprises: a code labeling module 210, a code compiling module 220 and a code testing module 230.
The functions of the modules and the interaction relationship between the modules are described in detail below.
A code annotation module 210, configured to introduce a custom annotation into a source code of a target module to be tested, and an annotation processor configured to process the custom annotation, and add the custom annotation to a target method to be tested in the target module, so as to annotate the target method with the custom annotation;
the code compiling module 220 is used for compiling the project to which the target module belongs, and analyzing the custom annotation through the annotation processor in the compiling process of the target module to obtain a target code to be tested;
the code testing module 230 is configured to, when the project is started, automatically execute the target code, and return an execution result of the target code to obtain a testing result of the target code;
the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
Optionally, in an embodiment of the present invention, the code compiling module may be specifically configured to:
in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
Optionally, in an embodiment of the present invention, the apparatus may further include:
and the test code injection module is used for acquiring a target source code to be tested and inputting the target source code into the target method so as to analyze the custom annotation through the annotation processor in the compiling process of the target module to obtain the target code.
Optionally, in an embodiment of the present invention, the apparatus may further include:
an annotation tool creation module for constructing the custom annotation in the project and an annotation processor for processing the custom annotation.
Optionally, in an embodiment of the present invention, the code testing module may be specifically configured to:
when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code;
the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
Optionally, in an embodiment of the present invention, the engineering includes engineering constructed based on a compilable language, and the compilable language includes at least one of Java and Kotlin.
The code test processing apparatus provided in the embodiment of the present invention can implement each process implemented in the method embodiments of fig. 1 to fig. 2, and is not described here again to avoid repetition.
Preferably, an embodiment of the present invention further provides an electronic device, including: the processor, the memory, and the computer program stored in the memory and capable of running on the processor, when executed by the processor, implement the processes of the above-mentioned information processing method embodiments, and can achieve the same technical effects, and in order to avoid repetition, details are not described here again.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program implements each process of the information processing method embodiment, and can achieve the same technical effect, and in order to avoid repetition, the details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (14)

1. A code test processing method, comprising:
introducing a custom annotation into a source code of a target module to be tested, and an annotation processor for processing the custom annotation, and adding the custom annotation to a target method to be tested in the target module so as to label the target method through the custom annotation;
compiling the project to which the target module belongs, and analyzing the custom annotation by the annotation processor in the compiling process of the target module to obtain a target code to be tested;
when the project is started, the target code is automatically executed, and the execution result of the target code is returned to obtain the test result of the target code;
the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
2. The method of claim 1, wherein the step of parsing the custom annotation by the annotation processor to obtain the target code to be tested during the compilation of the target module comprises:
in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
3. The method of claim 1, wherein before the steps of compiling the project to which the target module belongs and parsing the custom annotation by the annotation processor during the compiling process of the target module to obtain the target code to be tested, the method further comprises:
and acquiring a target source code to be tested, and inputting the target source code in the target method, so that the user-defined annotation is analyzed by the annotation processor in the compiling process of the target module to obtain the target code.
4. The method of claim 1, wherein before the steps of introducing a custom annotation into source code of a target module to be tested and an annotation processor for processing the custom annotation and adding the custom annotation to a target method to be tested in the target module, further comprising:
the custom annotation is constructed in the project, and an annotation processor for processing the custom annotation.
5. The method according to any one of claims 1-6, wherein the step of automatically executing the object code and returning the execution result of the object code upon the start of the project comprises:
when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code;
the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
6. The method according to any one of claims 1-4, wherein the engineering comprises engineering constructed based on a compilable language, and the compilable language comprises at least one of Java and Kotlin.
7. A code test processing apparatus, comprising:
the system comprises a code annotation module, a note processor and a target module, wherein the code annotation module is used for introducing a custom note into a source code of the target module to be tested, the note processor is used for processing the custom note, and the custom note is added to a target method to be tested in the target module so as to annotate the target method through the custom note;
the code compiling module is used for compiling the project to which the target module belongs, and analyzing the custom annotation through the annotation processor in the compiling process of the target module to obtain a target code to be tested;
the code testing module is used for automatically executing the target code when the project is started, and returning the execution result of the target code to obtain the testing result of the target code;
the user-defined annotation is an annotation which can act on the class method and is used for marking the class method to be tested, and the target module is any code module in the project.
8. The apparatus of claim 7, wherein the code compiling module is specifically configured to:
in the compiling process of the target module, the annotation processor executes the following steps to analyze the self-defined annotation to obtain a target code to be tested:
s1, initializing the annotation processor;
s2, obtaining all self-defined annotations processed by the annotation processor in the target module;
s3, acquiring all the methods marked by the custom annotation;
s4, calling the method marked by the self-defined annotation through reflection, and generating the target code.
9. The apparatus of claim 8, further comprising:
and the test code injection module is used for acquiring a target source code to be tested and inputting the target source code into the target method so as to analyze the custom annotation through the annotation processor in the compiling process of the target module to obtain the target code.
10. The apparatus of claim 7, further comprising:
an annotation tool creation module for constructing the custom annotation in the project and an annotation processor for processing the custom annotation.
11. The apparatus according to any of claims 7-10, wherein the code testing module is specifically configured to:
when the project is started, calling a target method at an entrance of the project start to automatically execute the target code and return an execution result of the target code;
the target method is used for acquiring the method marked by the self-defined annotation, and the method is executed through reflection, so that the automatic test of the target code is completed.
12. The apparatus of any of claims 7-10, wherein the engineering comprises engineering constructed based on a compilable language comprising at least one of Java, Kotlin.
13. An electronic device, comprising: processor, memory and a computer program stored on the memory and executable on the processor, which computer program, when executed by the processor, carries out the steps of the code test processing method according to any one of claims 1 to 6.
14. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, carries out the steps of the code test processing method according to any one of claims 1 to 6.
CN202111014666.9A 2021-08-31 2021-08-31 Code test processing method and device, electronic equipment and storage medium Pending CN113867704A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111014666.9A CN113867704A (en) 2021-08-31 2021-08-31 Code test processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111014666.9A CN113867704A (en) 2021-08-31 2021-08-31 Code test processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113867704A true CN113867704A (en) 2021-12-31

Family

ID=78989069

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111014666.9A Pending CN113867704A (en) 2021-08-31 2021-08-31 Code test processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113867704A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115617353A (en) * 2022-12-15 2023-01-17 杭州比智科技有限公司 Method for generating description file based on ksp and rapid instrumentation gradle compiling system
WO2024045379A1 (en) * 2022-08-31 2024-03-07 蚂蚁区块链科技(上海)有限公司 Compiling method, compiler, and wasm virtual machine

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024045379A1 (en) * 2022-08-31 2024-03-07 蚂蚁区块链科技(上海)有限公司 Compiling method, compiler, and wasm virtual machine
CN115617353A (en) * 2022-12-15 2023-01-17 杭州比智科技有限公司 Method for generating description file based on ksp and rapid instrumentation gradle compiling system

Similar Documents

Publication Publication Date Title
CN110908640B (en) Method for realizing service function and script engine
US10261889B2 (en) Techniques for edit-and-continue and enhanced optimized debugging on optimized code
US10540262B2 (en) Using edit and continue to dynamically set and unset optimizations in source code while debugging
CN110704063B (en) Method and device for compiling and executing intelligent contract
CN110688122B (en) Method and device for compiling and executing intelligent contract
US8060869B1 (en) Method and system for detecting memory problems in user programs
US20110047532A1 (en) Methods and apparatuses for selective code coverage
CN110704064B (en) Method and device for compiling and executing intelligent contract
US7823144B2 (en) Computer program code comparison using lexemes
CN111459495B (en) Unit test code file generation method, electronic device and storage medium
CN113867704A (en) Code test processing method and device, electronic equipment and storage medium
CN110673837B (en) Code repairing method and device, electronic equipment and computer readable storage medium
US11126527B2 (en) Software engineering method including tracing and visualizing
CN107203535B (en) Information query method and device
JP6845429B2 (en) Compiler program, information processing device and compilation method
JP2008052688A (en) Patch data generation device for program
Hill et al. Pin++: an object-oriented framework for writing pintools
CN115794054A (en) Code generation method and device, storage medium and computer equipment
CN114895914A (en) Log output code generation method and device, electronic equipment and storage medium
CN111796832A (en) Hot patch file generation method, device, equipment and storage medium
CN114489653A (en) Compiler-based data processing method, compiler-based data processing device and readable storage medium
Azadmanesh et al. Language-independent information flow tracking engine for program comprehension tools
CN112148581A (en) Code specification checking method, device, system and storage medium
CN113946347B (en) Function call detection method and device, electronic equipment and readable medium
Aldausari et al. Combining Design by Contract and Inference Rules of Programming Logic towards Software Reliability.

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