CN110888794A - Interface test method and device - Google Patents

Interface test method and device Download PDF

Info

Publication number
CN110888794A
CN110888794A CN201811051627.4A CN201811051627A CN110888794A CN 110888794 A CN110888794 A CN 110888794A CN 201811051627 A CN201811051627 A CN 201811051627A CN 110888794 A CN110888794 A CN 110888794A
Authority
CN
China
Prior art keywords
tested
class
annotation
interface
application program
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
CN201811051627.4A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811051627.4A priority Critical patent/CN110888794A/en
Publication of CN110888794A publication Critical patent/CN110888794A/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/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The invention discloses an interface testing method and device, and relates to the technical field of computers. One embodiment of the method comprises: in the source code of the application program, a class to be tested is marked by a first annotation, and a method to be tested is marked by a second annotation; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested; when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method. According to the method and the system for testing the interface, the class and the method of the interface to be tested can be filled into the pre-established interface model to generate the testing interface, so that a back-end engineer does not need to consider the realization of the testing interface, and the testing efficiency is improved.

Description

Interface test method and device
Technical Field
The invention relates to the technical field of computers, in particular to an interface testing method and device.
Background
In the process of testing the interface of the application program, in order to facilitate testing, a back-end engineer often needs to write a front-end test interface for the interface provided by the back-end engineer. Since the back-end engineer is generally not familiar with technologies such as JavaScript (scripting language) and cascading Style sheet css (cascading Style sheets) of the front-end test interface, it is difficult to write the front-end test interface, and the test efficiency is easily affected.
In the prior art, a JUnit unit test framework is generally adopted for interface test, but JUnit does not provide interface operation and lacks operability.
Disclosure of Invention
In view of this, embodiments of the present invention provide an interface testing method and apparatus, which can fill the type and method of the interface to be tested into a pre-established interface model to generate a test interface, so that a back-end engineer does not need to consider the implementation of the test interface, thereby improving the testing efficiency.
To achieve the above object, according to one aspect of the present invention, an interface testing method is provided.
The interface test method of the embodiment of the invention comprises the following steps: in the source code of the application program, a class to be tested is marked by a first annotation, and a method to be tested is marked by a second annotation; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested; when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
Optionally, the method further comprises: and calling the to-be-tested class and the to-be-tested method according to the reflection mechanism when the test interface is used for testing so as to realize the test of the to-be-tested class and the to-be-tested method.
Optionally, the application is developed based on a Spring framework; and when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation, wherein the method specifically comprises the following steps: when the application program is started, registering the classes and the methods marked with the annotations into a Spring container; and obtaining the class to be tested from the Spring container according to the first annotation, and obtaining the method to be tested from the Spring container according to the second annotation.
Optionally, the outputting the acquired class to be tested and the method to be tested to a pre-established interface model specifically includes: loading the acquired to-be-tested class and the acquired to-be-tested method to a memory by using the pre-established task class in the interface model; and filling the interface model with the class to be tested and the method to be tested in the memory.
To achieve the above object, according to another aspect of the present invention, an interface test apparatus is provided.
The interface testing device of the embodiment of the invention can comprise: the annotation unit is used for annotating the class to be tested by using the first annotation and annotating the method to be tested by using the second annotation in the source code of the application program; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested; the test interface generating unit is used for acquiring a class to be tested according to the first annotation and acquiring a method to be tested according to the second annotation when the application program runs; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
Optionally, the apparatus may further comprise: and the test unit is used for calling the to-be-tested class and the to-be-tested method according to the reflection mechanism when the test interface is tested so as to realize the test of the to-be-tested class and the to-be-tested method.
Optionally, the application is developed based on a Spring framework; and the test interface generating unit may be further configured to: when the application program is started, registering the classes and the methods marked with the annotations into a Spring container; and obtaining the class to be tested from the Spring container according to the first annotation, and obtaining the method to be tested from the Spring container according to the second annotation.
Optionally, the test interface generating unit may be further configured to: loading the acquired to-be-tested class and the acquired to-be-tested method to a memory by using the pre-established task class in the interface model; and filling the interface model with the class to be tested and the method to be tested in the memory.
To achieve the above object, according to still another aspect of the present invention, there is provided an electronic apparatus.
An electronic device of the present invention includes: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the interface testing method provided by the invention.
To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of the present invention has stored thereon a computer program which, when executed by a processor, implements the interface testing method provided by the present invention.
According to the technical scheme of the invention, one embodiment of the invention has the following advantages or beneficial effects:
firstly, creating a custom annotation in an application program source code, and marking a to-be-tested class and a to-be-tested method for realizing a to-be-tested interface by using the custom annotation; when the application program runs, the class to be tested and the method to be tested are obtained according to the user-defined annotation, the obtained class to be tested and the method to be tested are filled into a pre-established interface model as components to generate a test interface, and the class to be tested and the method to be tested are called by using a reflection mechanism during testing. Therefore, the interface testing of the interface can be realized by the back-end engineer only needing to label the class to be tested and the method to be tested and introducing the interface model program package in the interface testing process, so that the development testing cost is reduced, the testing efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the invention also realizes a uniform easy-to-operate test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application program.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram illustrating the main steps of an interface testing method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an implementation architecture of an interface testing method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the components of an interface testing apparatus according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic structural diagram of an electronic device for implementing the interface testing method in the embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that the embodiments of the present invention and the technical features of the embodiments may be combined with each other without conflict.
Fig. 1 is a schematic diagram illustrating main steps of an interface testing method according to an embodiment of the present invention.
As shown in fig. 1, the interface testing method according to the embodiment of the present invention may be specifically executed according to the following steps:
step S101: in the source code of the application program, the class to be tested is marked by using a first annotation, and the method to be tested is marked by using a second annotation.
In an embodiment of the invention, the first annotation and the second annotation are both custom annotations. The first annotation is used for marking the class to be tested, the second annotation is used for marking the method to be tested in the class to be tested, and other business logics are not reflected by the first annotation and the second annotation. In particular, in the programming language such as JAVA, annotation (annotation) is a special modifier applied to classes, methods, parameters, variables, constructors or package declarations, which is a tool used to describe metadata. Custom annotations are annotations other than system built-in annotations that are written by developers themselves with meta-annotations. In a specific application, the system provides the following four meta-annotations:
@ Documented-for determining whether a defined annotation is to be contained in a JAVA document;
@ Retention-an annotation used to determine when to use a definition;
@ Target-is used to determine where the annotation is used;
@ Inherited-an annotation used to determine whether a subclass is allowed to inherit a definition.
Note that the above annotation is completely different from the annotation. Generally, annotations are used to inform developers of the logic, description, characteristics, etc. of the code, and can be written at will without limitation; at compile time, the annotations are completely ignored by the compiler. Annotation is the metadata that informs the JAVA virtual machine of the elements by marking the elements such as class, method, parameter, variable, constructor or package, which is generally started with "@", and has strict limitations on position, syntax and content, and if there is any error, an exception is displayed in the compiling process.
The way in which the first and second annotations are defined will be presented below in an example in JAVA. In the following example, the first annotation is an export service annotation (export service) and the second annotation is an export method annotation (export method).
The definition code of exportervice specifically includes:
Figure BDA0001794702430000061
wherein the annotation of the first line of code representation definition can be used to describe a class, interface or declaration; the annotation of the second line code representation definition is not discarded all the time and is also kept in the runtime; the third line of code is annotated with public modifier public definitions; the fourth line code sets the name attribute (string type) of Exportservice annotation, and the default value of the attribute is 'unset'; the fifth line of code sets the desc attribute (string type) of the Exportservice annotation, which is "no description" as a default value; the sixth line of code sets the appProup attribute (string type) of ExportService annotations, which is "application ungrouped" by default; the seventh line of code sets the servgroup attribute (string type) annotated by ExportService, which is "service not grouped" by default.
Figure BDA0001794702430000062
Wherein the first line of code represents that the defined annotation is available to describe the method; the annotation of the second line code representation definition is not discarded all the time and is also kept in the runtime; the third line of code is annotated with public modifier public definitions; the fourth line code sets the name attribute (string type) of the ExportMethod annotation, which is "unset" by default; the fifth line of code sets the desc attribute (string type) of the Exportmethod annotation, which defaults to "no description".
By setting the self-defined annotation, the invention can control which classes and methods are filled into the test page subsequently, thereby realizing the configurable operation of the test page data. It should be noted that the above codes are only examples, and do not guarantee to be able to run, and do not set any limit on the specific definition manner of the first annotation and the second annotation.
In step S101, after the first annotation and the second annotation are defined, the class to be tested may be marked with the first annotation and the method to be tested may be marked with the second annotation in the application source code. In practical application, the class to be tested is an implementation class of an interface to be tested of an application program, and the method to be tested is a method of the class to be tested.
Labeling classes to be tested can be shown as the following code:
@ExportService
public class JimCacheServiceImpl implements JimCacheService
wherein class represents class, jimcacherviceimpl is class to be tested, instances is implementation keywords, and jimcachervice is interface to be tested.
The method to be tested for labeling can be shown as the following codes:
@ExportMethod
public long exportDelCache()
wherein long is the integer, and export cache is the method to be measured.
After the above labeling, the class under test and the method under test can be filled in the interface template as components, which will be described in detail below.
Step S102: when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
In this step, the to-be-tested class and the to-be-tested method may be obtained by using the annotation marked in step S101 during the running (including starting) of the application program. For example, if the application is developed in a Spring framework (an open source JAVA platform), when the application is started, the class and the method marked with the annotation may be automatically registered in a Spring container (a space for placing the managed object bean), and then the class to be tested is obtained from the Spring container according to the first annotation, and the method to be tested is obtained from the Spring container according to the second annotation. In specific application, the getAnntotation method can be used for obtaining the class to be tested, the input parameter of the method is the first annotation, and the output parameter of the method is the class to be tested marked with the first annotation.
In one embodiment, after the class to be tested and the method to be tested are obtained, the class to be tested and the method to be tested can be output to a pre-established interface model as components, and a test interface for the class to be tested and the method to be tested is generated. Specifically, the interface model refers to an interface test interface model of a front end, which needs to interact with interface (including implementation classes and methods thereof) code to generate a final test interface, which can be implemented by using a dynamic page frame such as boottrap. In specific application, the acquired class to be tested and the method to be tested can be loaded to the memory by using the task class pre-established in the interface model, and then the class to be tested and the method to be tested in the memory are filled into the interface model, so that the test interface is generated. It is understood that before exporting the class to be tested and the method to be tested to the interface model, a package referencing the interface model in the application, such as a Java archive file jar (Java archive) package, is required.
It should be noted that, in practical applications, the interface model may also use a pluggable function of Servlet (an interface or server program written in JAVA) 3.0 to implement the non-intrusive interfacing between the interface model and the application program. When the method is used, the corresponding deployment description file can be placed under the META-INF directory (a directory for storing the META-information file) of the interface model JAR package, and the JAR package is placed under the WEB-INF/lib directory (a directory for storing the JAR package). Therefore, the application program can directly carry out non-invasive interaction with the interface template without declaring the task class of the interface template.
Through the arrangement, a test interface which is easy to test and operate can be generated for a tester to use. In the test process, the class to be tested and the method to be tested can be called by using a JAVA reflection mechanism so as to test the interface to be tested. As known in the art, the JAVA reflection mechanism refers to: in the running state, for any one class, all the attributes and methods of the class can be obtained; any method and property can be called for any object. That is, through the JAVA reflection mechanism, the JAVA program can load a class whose name is known at runtime, learn its complete structure, generate its object entity, and then set its attributes or invoke its methods.
Fig. 2 is a schematic diagram of an implementation architecture of an interface testing method according to an embodiment of the present invention. As shown in fig. 2, after the source code of the application program is labeled with the custom annotation and refers to the interface model package, a plurality of interface modules (including the implementation classes of each interface and the methods thereof) of the application program can interact with the interface model in a non-invasive manner and generate the functional test of the imaging test interface implementation interface.
It should be noted that, although the above mainly uses JAVA as an example to illustrate the technical solution of the present invention, this does not set any limit to the application range of the interface testing method provided by the present invention. In fact, the method of the present invention can be used for interface testing in any applicable software environment, and achieves similar technical effects.
In the technical scheme of the embodiment of the invention, firstly, custom notes are created in the source codes of the application program, and the to-be-tested class and the to-be-tested method of the to-be-tested interface are marked by the custom notes; when the application program runs, the class to be tested and the method to be tested are obtained according to the user-defined annotation, the obtained class to be tested and the method to be tested are filled into a pre-established interface model as components to generate a test interface, and the class to be tested and the method to be tested are called by using a reflection mechanism during testing. Therefore, the interface testing of the interface can be realized by the back-end engineer only needing to label the class to be tested and the method to be tested and introducing the interface model program package in the interface testing process, so that the development testing cost is reduced, the testing efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the invention also realizes a uniform easy-to-operate test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application program.
It should be noted that, for the convenience of description, the foregoing method embodiments are described as a series of acts, but those skilled in the art will appreciate that the present invention is not limited by the order of acts described, and that some steps may in fact be performed in other orders or concurrently. Moreover, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required to implement the invention.
To facilitate a better implementation of the above-described aspects of embodiments of the present invention, the following also provides relevant means for implementing the above-described aspects.
Referring to fig. 3, an interface testing apparatus 300 according to an embodiment of the present invention may include: a labeling unit 301 and a test interface generating unit 302.
The labeling unit 301 may be configured to label, in the application source code, the class to be tested with the first annotation and label the method to be tested with the second annotation; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested.
The test interface generating unit 302 may be configured to obtain a class to be tested according to the first annotation and obtain a method to be tested according to the second annotation when the application program runs; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
In an embodiment of the present invention, the apparatus 300 may further include a test unit, configured to call the class to be tested and the method to be tested according to a reflection mechanism when the test interface performs a test, so as to implement a test of the class to be tested and the method to be tested.
In specific application, the application program is developed based on a Spring framework; and, the test interface generating unit 302 may be further configured to: when the application program is started, registering the classes and the methods marked with the annotations into a Spring container; and obtaining the class to be tested from the Spring container according to the first annotation, and obtaining the method to be tested from the Spring container according to the second annotation.
Furthermore, in an embodiment of the present invention, the test interface generating unit 302 may be further configured to: loading the acquired to-be-tested class and the acquired to-be-tested method to a memory by using the pre-established task class in the interface model; and filling the interface model with the class to be tested and the method to be tested in the memory.
In the technical scheme of the embodiment of the invention, firstly, custom notes are created in the source codes of the application program, and the to-be-tested class and the to-be-tested method of the to-be-tested interface are marked by the custom notes; when the application program runs, the class to be tested and the method to be tested are obtained according to the user-defined annotation, the obtained class to be tested and the method to be tested are filled into a pre-established interface model as components to generate a test interface, and the class to be tested and the method to be tested are called by using a reflection mechanism during testing. Therefore, the interface testing of the interface can be realized by the back-end engineer only needing to label the class to be tested and the method to be tested and introducing the interface model program package in the interface testing process, so that the development testing cost is reduced, the testing efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the invention also realizes a uniform easy-to-operate test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application program.
Fig. 4 shows an exemplary system architecture 400 to which the interface test method or the interface test apparatus of the embodiments of the present invention can be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405 (this architecture is merely an example, and the components included in a particular architecture may be adapted according to application specific circumstances). The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may process the received product information query request and the like, and feed back a processing result (e.g., target push information, product information — just an example) to the terminal device.
It should be noted that the interface testing method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the interface testing apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides the electronic equipment. The electronic device of the embodiment of the invention comprises: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the interface testing method provided by the invention.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use in implementing an electronic device of an embodiment of the present invention. The electronic device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM503, various programs and data necessary for the operation of the computer system 500 are also stored. The CPU501, ROM 502, and RAM503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, the processes described in the main step diagrams above may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the invention include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the main step diagram. In the above-described embodiment, the computer program can be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the central processing unit 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present invention may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a labeling unit and a test interface generating unit. Where the names of these units do not in some cases constitute a definition of the unit itself, for example, the test interface generation unit may also be described as a "unit that populates the interface model with the class to be tested and the method to be tested as components".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by the apparatus, cause the apparatus to perform steps comprising: in the source code of the application program, a class to be tested is marked by a first annotation, and a method to be tested is marked by a second annotation; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested; when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
In the technical scheme of the embodiment of the invention, firstly, custom notes are created in the source codes of the application program, and the to-be-tested class and the to-be-tested method of the to-be-tested interface are marked by the custom notes; when the application program runs, the class to be tested and the method to be tested are obtained according to the user-defined annotation, the obtained class to be tested and the method to be tested are filled into a pre-established interface model as components to generate a test interface, and the class to be tested and the method to be tested are called by using a reflection mechanism during testing. Therefore, the interface testing of the interface can be realized by the back-end engineer only needing to label the class to be tested and the method to be tested and introducing the interface model program package in the interface testing process, so that the development testing cost is reduced, the testing efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the invention also realizes a uniform easy-to-operate test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application program.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. An interface testing method, comprising:
in the source code of the application program, a class to be tested is marked by a first annotation, and a method to be tested is marked by a second annotation; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested;
when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
2. The interface testing method of claim 1, wherein the method further comprises:
and calling the to-be-tested class and the to-be-tested method according to the reflection mechanism when the test interface is used for testing so as to realize the test of the to-be-tested class and the to-be-tested method.
3. The interface testing method according to claim 2, wherein the application program is developed based on a Spring framework; and when the application program runs, acquiring a class to be tested according to the first annotation, and acquiring a method to be tested according to the second annotation, wherein the method specifically comprises the following steps:
when the application program is started, registering the classes and the methods marked with the annotations into a Spring container;
and obtaining the class to be tested from the Spring container according to the first annotation, and obtaining the method to be tested from the Spring container according to the second annotation.
4. The interface testing method according to any one of claims 1 to 3, wherein the outputting the acquired class to be tested and the method to be tested to a pre-established interface model specifically includes:
loading the acquired to-be-tested class and the acquired to-be-tested method to a memory by using the pre-established task class in the interface model;
and filling the interface model with the class to be tested and the method to be tested in the memory.
5. An interface testing apparatus, comprising:
the annotation unit is used for annotating the class to be tested by using the first annotation and annotating the method to be tested by using the second annotation in the source code of the application program; the first annotation and the second annotation are both user-defined annotations, the class to be tested is a realization class of the interface to be tested of the application program, and the method to be tested is a method of the class to be tested;
the test interface generating unit is used for acquiring a class to be tested according to the first annotation and acquiring a method to be tested according to the second annotation when the application program runs; and outputting the acquired to-be-tested class and the acquired to-be-tested method to a pre-established interface model to generate a test interface aiming at the to-be-tested class and the to-be-tested method.
6. The apparatus of claim 5, further comprising:
and the test unit is used for calling the to-be-tested class and the to-be-tested method according to the reflection mechanism when the test interface is tested so as to realize the test of the to-be-tested class and the to-be-tested method.
7. The apparatus of claim 6, wherein the application is developed based on a Spring framework; and the test interface generating unit is further used for:
when the application program is started, registering the classes and the methods marked with the annotations into a Spring container; and obtaining the class to be tested from the Spring container according to the first annotation, and obtaining the method to be tested from the Spring container according to the second annotation.
8. The apparatus of any of claims 5-7, wherein the test interface generating unit is further configured to:
loading the acquired to-be-tested class and the acquired to-be-tested method to a memory by using the pre-established task class in the interface model; and filling the interface model with the class to be tested and the method to be tested in the memory.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the interface testing method of any one of claims 1-4.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the interface testing method according to any one of claims 1 to 4.
CN201811051627.4A 2018-09-10 2018-09-10 Interface test method and device Pending CN110888794A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811051627.4A CN110888794A (en) 2018-09-10 2018-09-10 Interface test method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811051627.4A CN110888794A (en) 2018-09-10 2018-09-10 Interface test method and device

Publications (1)

Publication Number Publication Date
CN110888794A true CN110888794A (en) 2020-03-17

Family

ID=69745008

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811051627.4A Pending CN110888794A (en) 2018-09-10 2018-09-10 Interface test method and device

Country Status (1)

Country Link
CN (1) CN110888794A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112286802A (en) * 2020-10-23 2021-01-29 上海淇玥信息技术有限公司 Method and device for testing program performance and electronic equipment
CN112948264A (en) * 2021-03-30 2021-06-11 完美世界(重庆)互动科技有限公司 Test task execution method, device, system, storage medium and electronic device
CN113505083A (en) * 2021-09-09 2021-10-15 连连宝(杭州)信息技术有限公司 Interface pressure performance testing method, device, equipment and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106383789A (en) * 2016-12-05 2017-02-08 广州唯品会信息科技有限公司 Software interface test method and software interface test system
CN106547689A (en) * 2016-10-20 2017-03-29 金航数码科技有限责任公司 A kind of automatic test cases development system and method based on web
CN108415834A (en) * 2018-02-12 2018-08-17 平安科技(深圳)有限公司 Explain rear end method of calibration, device, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106547689A (en) * 2016-10-20 2017-03-29 金航数码科技有限责任公司 A kind of automatic test cases development system and method based on web
CN106383789A (en) * 2016-12-05 2017-02-08 广州唯品会信息科技有限公司 Software interface test method and software interface test system
CN108415834A (en) * 2018-02-12 2018-08-17 平安科技(深圳)有限公司 Explain rear end method of calibration, device, computer equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112286802A (en) * 2020-10-23 2021-01-29 上海淇玥信息技术有限公司 Method and device for testing program performance and electronic equipment
CN112286802B (en) * 2020-10-23 2023-04-25 上海淇玥信息技术有限公司 Method and device for testing program performance and electronic equipment
CN112948264A (en) * 2021-03-30 2021-06-11 完美世界(重庆)互动科技有限公司 Test task execution method, device, system, storage medium and electronic device
CN113505083A (en) * 2021-09-09 2021-10-15 连连宝(杭州)信息技术有限公司 Interface pressure performance testing method, device, equipment and medium
CN113505083B (en) * 2021-09-09 2021-12-14 连连宝(杭州)信息技术有限公司 Interface pressure performance testing method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN108415832B (en) Interface automation test method, device, equipment and storage medium
CN107832045B (en) Method and apparatus for cross programming language interface conversion
US10353702B2 (en) Source code element signatures
CN109062563B (en) Method and device for generating page
CN110865889B (en) Method and device for transmitting event between components
CN110543297B (en) Method and apparatus for generating source code
CN110780874B (en) Method and device for generating information
CN110888794A (en) Interface test method and device
CN112769706B (en) Componentized routing method and system
CN111125064A (en) Method and device for generating database mode definition statement
CN110928571A (en) Business program development method and device
CN115599386A (en) Code generation method, device, equipment and storage medium
CN107391118B (en) Web application user experience platform system
CN109582317A (en) Method and apparatus for debugging boarding application
CN116881166A (en) Method, device and system for generating test script
US9135001B2 (en) Dynamically configuring an integrated development environment
CN112416333A (en) Software model training method, device, system, equipment and storage medium
US20100125827A1 (en) Developing software code using parameterized annotations
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN115640279A (en) Method and device for constructing data blood relationship
CN111666201A (en) Regression testing method, device, medium and electronic equipment
CN113535565B (en) Interface use case generation method, device, equipment and medium
CN112256252B (en) Interface generation method and device, storage medium and electronic equipment
CN114115855A (en) Code multiplexing method and device, computer readable storage medium and electronic equipment

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