Nothing Special   »   [go: up one dir, main page]

CN110888794B - Interface testing method and device - Google Patents

Interface testing method and device Download PDF

Info

Publication number
CN110888794B
CN110888794B CN201811051627.4A CN201811051627A CN110888794B CN 110888794 B CN110888794 B CN 110888794B CN 201811051627 A CN201811051627 A CN 201811051627A CN 110888794 B CN110888794 B CN 110888794B
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.)
Active
Application number
CN201811051627.4A
Other languages
Chinese (zh)
Other versions
CN110888794A (en
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/CN110888794B/en
Publication of CN110888794A publication Critical patent/CN110888794A/en
Application granted granted Critical
Publication of CN110888794B publication Critical patent/CN110888794B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses an interface testing method and device, and relates to the technical field of computers. One embodiment of the method comprises the following steps: in the source code of the application program, the class to be detected is marked by using the first annotation, and the method to be detected is marked by using the second annotation; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested. According to the method and the device for testing the interfaces, classes and methods of the interfaces to be tested can be filled into a pre-established interface model, and the test interfaces are generated, so that a back-end engineer does not need to consider the implementation of the test interfaces, and the test efficiency is improved.

Description

Interface testing method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for testing an interface.
Background
In the interface test process of an application program, in order to facilitate the test, a back-end engineer often needs to write a front-end test interface for an interface provided by the back-end engineer. Because the back-end engineer is generally not familiar with JavaScript (a scripting language) and cascading style sheets CSS (Cascading Style Sheets) of the front-end test interface, it is difficult to write the front-end test interface, which is easy to affect the test efficiency.
In the prior art, interface test is generally performed by adopting a JUnit test framework, but the JUnit does not provide interface operation and lacks of easy operability.
Disclosure of Invention
In view of this, the embodiments of the present invention provide an interface testing method and apparatus, which can fill classes and methods of an interface to be tested into a pre-established interface model to generate a testing interface, so that a back-end engineer does not need to consider implementation of the testing interface, thereby improving testing efficiency.
To achieve the above object, according to one aspect of the present invention, there is provided an interface test method.
The interface testing method of the embodiment of the invention comprises the following steps: in the source code of the application program, the class to be detected is marked by using the first annotation, and the method to be detected is marked by using the second annotation; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
Optionally, the method further comprises: and when the test interface is used for testing, calling the class to be tested and the method to be tested according to the reflection mechanism so as to realize the testing of the class to be tested and the method to be tested.
Optionally, the application program is developed based on a Spring framework; and when the application program runs, acquiring the class to be tested according to the first annotation, and acquiring the 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 annotated class and the annotated method to 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 obtained class to be tested and the method to be tested to a pre-established interface model specifically includes: loading the acquired class to be tested and the acquired method to be tested into a memory by utilizing a task class which is created in advance in the interface model; and filling the classes to be tested and the methods to be tested in the memory into the interface model.
To achieve the above object, according to another aspect of the present invention, there is provided an interface test apparatus.
The interface test device of the embodiment of the invention can comprise: the marking unit is used for marking the class to be detected by using the first annotation and marking the method to be detected by using the second annotation in the source code of the application program; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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 the class to be tested according to the first annotation and acquiring the method to be tested according to the second annotation when the application program runs; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
Optionally, the apparatus may further include: and the test unit is used for calling the class to be tested and the method to be tested according to the reflection mechanism when the test interface is used for testing so as to realize the testing of the class to be tested and the method to be tested.
Optionally, the application program is developed based on a Spring framework; and, the test interface generation unit may be further configured to: when the application program is started, registering the annotated class and the annotated method to 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 further be configured to: loading the acquired class to be tested and the acquired method to be tested into a memory by utilizing a task class which is created in advance in the interface model; and filling the classes to be tested and the methods to be tested in the memory into the interface model.
To achieve the above object, according to still another aspect of the present invention, there is provided an electronic apparatus.
An electronic apparatus 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 are enabled to 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 class to be tested and a method to be tested for realizing an interface to be tested by using the custom annotation; when an application program runs, the class to be tested and the method to be tested are obtained according to the custom annotation, the obtained class to be tested and the obtained method to be tested are used as components to be filled into a pre-established interface model 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 test of the interface can be realized by only marking the class to be tested and the method to be tested and referring to the interface model program package in the interface test process of the back-end engineer, so that the development test cost is reduced, the test efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the unified easy-to-operate test interface platform is realized through the pre-established interface model, so that the testability of the items and the robustness of the application program are improved.
Further effects of the above-described non-conventional alternatives are 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 of 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 test method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the components of an interface test apparatus according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments in accordance with the present invention may be applied;
fig. 5 is a schematic structural diagram of an electronic device for implementing the interface testing method in the embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered 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 in the embodiments may be combined with each other without collision.
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 specifically be performed according to the following steps:
Step S101: in the source code of the application program, the class to be tested is marked by the first annotation, and the method to be tested is marked by the second annotation.
In the embodiment of the invention, the first annotation and the second annotation are 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 logic is not embodied in the first annotation and the second annotation. In particular, in programming languages such as JAVA, annotation is a special modifier applied to classes, methods, parameters, variables, constructors, or package declarations, and is a tool used to describe metadata. Custom annotations are annotations written by the developer by itself with meta-annotations, except for built-in annotations in the system. In a specific application, the system provides the following four meta-notes:
@ Documented-means for determining whether the defined annotation will be contained in a JAVA document;
the @ Retention-is used to determine when to use a defined annotation;
@ Target-is used to determine where the annotation is to be used;
@ INHERITED-means for determining whether to allow the subclass to inherit the defined annotation.
Note that the above-mentioned notes are completely different from the notes. In general, annotations are used to inform developers of the logic, description, characteristics, etc. of code, and can be written arbitrarily without limitation; at compile time, annotations may be ignored entirely by the compiler. Annotation is the notification of metadata of elements such as class, method, parameters, variables, constructors or packages to JAVA virtual machines by labeling these elements, which generally start with "@" and have strict restrictions on location, grammar, content, and if any error occurs, an exception will be displayed during compilation.
The manner of definition of the first annotation and the second annotation will be presented below in the example in JAVA. In the following example, the first annotation is an outgoing service annotation (ExportService) and the second annotation is an outgoing method annotation (ExportMethod).
ExportService the definition codes are specifically:
wherein the first line of code represents defined annotations that may be used to describe classes, interfaces, or declarations; the second line of codes indicates that the defined notes are not discarded all the time and are reserved in the running process; the third line of code is annotated with public modifier public definition; the fourth line code sets ExportService the name attribute (string type) annotated, which defaults to "unset"; the fifth line code sets ExportService the annotated desc attribute (string type) with default value "no description"; the sixth line of code sets ExportService annotated appGroup attribute (string type) that defaults to "application ungrouped"; the seventh line code sets ExportService the annotated serGroup attribute (string type) that defaults to "no traffic packet".
Wherein the first line of code represents defined annotations that may be used to describe the method; the second line of codes indicates that the defined notes are not discarded all the time and are reserved in the running process; the third line of code is annotated with public modifier public definition; the fourth line code sets ExportMethod the name attribute (string type) annotated, which defaults to "unset"; the fifth line code sets ExportMethod the annotated desc attribute (string type) which defaults to "no description".
By setting the custom notes, the invention can control which classes and which methods are to be filled into the test page subsequently, thereby realizing configurable operation of the test page data. It should be noted that the above codes are only examples, and are not guaranteed to be capable of running, and no limitation is imposed on the specific definition manner of the first annotation and the second annotation.
In step S101, after the definition of the first annotation and the second annotation is completed, 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 the class under test may be as follows:
@ExportService
public class JimCacheServiceImpl implements JimCacheService
Wherein class represents class, jimCacheServiceImpl is class to be tested, implements is implementation keyword, and JimCacheService is interface to be tested.
Labeling the method to be tested can be as follows:
@ExportMethod
public long exportDelCache()
wherein long is a long integer, exportCache is a method to be measured.
After the labeling, the classes to be tested and the methods to be tested can be filled into 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; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
In this step, the annotation marked in step S101 may be used to obtain the class to be tested and the method to be tested during the running (including starting) of the application. For example, if the application is developed in a Spring framework (an open source JAVA platform), when the application is started, the classes and methods marked with annotations can be automatically registered in a Spring container (a space for placing a managed object bean), then the classes to be tested are obtained from the Spring container according to the first annotation, and the methods to be tested are obtained from the Spring container according to the second annotation. In a specific application, the method getAnnotation can be used for obtaining the class to be tested, wherein 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 to generate test interfaces for the class to be tested and the method to be tested. Specifically, the interface model refers to a front-end interface test interface model, which needs to interact with an interface (including implementation class and a method thereof) code to generate a final test interface, and can be implemented by adopting a dynamic page framework such as Bootstrap. In a specific application, the task class created in advance in the interface model can be utilized to load the acquired class to be tested and the method to be tested into the memory, and then the class to be tested and the method to be tested in the memory are filled into the interface model, so that a test interface is generated. It will be appreciated that packages of interface models, such as Java archive JAR (Java Archive) packages, need to be referenced in the application before the class under test and the method under test are exported to the interface model.
It should be noted that, in practical application, the interface model may also utilize a pluggable function of Servlet (an interface or service end program written in JAVA) 3.0 to realize non-intrusive interfacing between the interface model and the application program. When in use, the corresponding deployment description file can be placed under the META-INF directory (a directory storing META-information files) of the interface model JAR package, and the JAR package can be placed under the WEB-INF/lib directory (a directory storing the JAR package). Thus, the application program can directly perform non-invasive interaction with the interface template without declaring the task class of the interface template.
Through the arrangement, a test interface easy to test and operate can be generated for a tester to use. In the test process, the JAVA reflection mechanism can be utilized to call the class to be tested and the method to be tested so as to realize the test of the interface to be tested. As known in the art, JAVA reflection mechanisms refer to: in the running state, for any one class, all the attributes and methods of the class can be obtained; any one of the methods and attributes can be invoked for any one of the objects. That is, through the JAVA reflection mechanism, the JAVA program can load a class whose name is known at runtime, learn its complete structure, and generate its object entity, and then set its attribute or call its method.
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 marked by using the custom annotation and the interface model package is referenced, a plurality of interface modules (including the implementation class of each interface and the method thereof) of the application program can interact with the interface model in a non-invasive manner and generate an imaged test interface to realize the functional test of the interface.
It should be noted that, although the technical solution of the present invention is mainly described above by using JAVA as an example, this does not limit the application range of the interface test method provided by the present invention. In fact, the method of the present invention can be used for interface testing of any suitable software environment and achieve similar technical effects.
In the technical scheme of the embodiment of the invention, a custom annotation is firstly created in an application program source code, and the custom annotation is utilized to mark a class to be tested and a method to be tested for realizing an interface to be tested; when an application program runs, the class to be tested and the method to be tested are obtained according to the custom annotation, the obtained class to be tested and the obtained method to be tested are used as components to be filled into a pre-established interface model 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 test of the interface can be realized by only marking the class to be tested and the method to be tested and referring to the interface model program package in the interface test process of the back-end engineer, so that the development test cost is reduced, the test efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the unified easy-to-operate test interface platform is realized through the pre-established interface model, so that the testability of the items and the robustness of the application program are improved.
It should be noted that, for the convenience of description, the foregoing method embodiments are expressed as a series of combinations of actions, but it should be understood by those skilled in the art that the present invention is not limited by the described order of actions, and some steps may actually be performed in other order or simultaneously. Moreover, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred embodiments, and that the acts and modules referred to are not necessarily required to practice the invention.
In order to facilitate better implementation of the above-described aspects of embodiments of the present invention, the following provides related devices 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: an annotation unit 301 and a test interface generation unit 302.
The labeling unit 301 may be configured to label the class to be tested with a first annotation and label the method to be tested with a second annotation in the source code of the application program; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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 a first annotation and obtain a method to be tested according to a second annotation when the application runs; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
In an embodiment of the present invention, the device 300 may further include a testing unit, configured to call the class to be tested and the method to be tested according to the reflection mechanism when the test interface performs the test, so as to implement the test of the class to be tested and the method to be tested.
In a specific application, the application program is developed based on a Spring framework; and, the test interface generation unit 302 may be further configured to: when the application program is started, registering the annotated class and the annotated method to 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 further be configured to: loading the acquired class to be tested and the acquired method to be tested into a memory by utilizing a task class which is created in advance in the interface model; and filling the classes to be tested and the methods to be tested in the memory into the interface model.
In the technical scheme of the embodiment of the invention, a custom annotation is firstly created in an application program source code, and the custom annotation is utilized to mark a class to be tested and a method to be tested for realizing an interface to be tested; when an application program runs, the class to be tested and the method to be tested are obtained according to the custom annotation, the obtained class to be tested and the obtained method to be tested are used as components to be filled into a pre-established interface model 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 test of the interface can be realized by only marking the class to be tested and the method to be tested and referring to the interface model program package in the interface test process of the back-end engineer, so that the development test cost is reduced, the test efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the unified easy-to-operate test interface platform is realized through the pre-established interface model, so that the testability of the items and the robustness of the application program are improved.
Fig. 4 illustrates an exemplary system architecture 400 to which the interface test method or interface test apparatus of embodiments of the present invention may be applied.
As shown in fig. 4, a 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 contained in a particular architecture may be tailored to the application specific case). The network 404 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403. The background management server may process the received product information query request and the like, and feed back the processing result (e.g., the target push information, the product information—just an example) to the terminal device.
It should be noted that, the interface testing method provided in the embodiment of the present invention is generally executed by the server 405, and accordingly, the interface testing device 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 electronic equipment. The electronic equipment 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 are enabled to realize the interface testing method provided by the invention.
Referring now to FIG. 5, there is illustrated a schematic 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 be construed as limiting the functionality and 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, which 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 required for the operation of the computer system 500 are also stored. The CPU501, ROM 502, and RAM503 are connected to each other through 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 section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; 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 drive 510 is also connected to the I/O interface 505 as needed. 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 needed, so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, the processes described in the main step diagrams above may be implemented as computer software programs according to the disclosed embodiments of the invention. For example, embodiments of the present 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 shown in the main step diagrams. 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 above-described functions defined in the system of the present invention are performed when the computer program is executed by the central processing unit 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this document, 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 comprise a data signal propagated in baseband or as part of a carrier wave, with computer readable program code embodied therein. Such a propagated data signal may take any of a variety of 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 flowcharts 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 involved in the embodiments of the present invention may be implemented in software or in hardware. The described units may also be provided in a processor, for example, described as: a processor includes an annotation unit and a test interface generation unit. The names of these units do not constitute limitations on the unit itself in some cases, and for example, the test interface generating unit may also be described as "a unit that fills the class under test and the method under test as components into the interface model".
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 present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by the device, cause the device to perform steps comprising: in the source code of the application program, the class to be detected is marked by using the first annotation, and the method to be detected is marked by using the second annotation; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
In the technical scheme of the embodiment of the invention, a custom annotation is firstly created in an application program source code, and the custom annotation is utilized to mark a class to be tested and a method to be tested for realizing an interface to be tested; when an application program runs, the class to be tested and the method to be tested are obtained according to the custom annotation, the obtained class to be tested and the obtained method to be tested are used as components to be filled into a pre-established interface model 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 test of the interface can be realized by only marking the class to be tested and the method to be tested and referring to the interface model program package in the interface test process of the back-end engineer, so that the development test cost is reduced, the test efficiency is improved, and the unnecessary workload of the back-end engineer is reduced. Meanwhile, the unified easy-to-operate test interface platform is realized through the pre-established interface model, so that the testability of the items and the robustness of the application program are improved.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (10)

1. An interface testing method, comprising:
in the source code of the application program, the class to be detected is marked by using the first annotation, and the method to be detected is marked by using the second annotation; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
2. The interface testing method of claim 1, further comprising:
and when the test interface is used for testing, calling the class to be tested and the method to be tested according to the reflection mechanism so as to realize the testing of the class to be tested and the method to be tested.
3. The interface testing method of claim 2, wherein the application program is developed based on a Spring framework; and when the application program runs, acquiring the class to be tested according to the first annotation, and acquiring the 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 annotated class and the annotated method to 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 obtained class to be tested and the method to be tested to a pre-established interface model specifically includes:
Loading the acquired class to be tested and the acquired method to be tested into a memory by utilizing a task class which is created in advance in the interface model;
And filling the classes to be tested and the methods to be tested in the memory into the interface model.
5. An interface testing apparatus, comprising:
The marking unit is used for marking the class to be detected by using the first annotation and marking the method to be detected by using the second annotation in the source code of the application program; the first annotation and the second annotation are user-defined annotations, the class to be tested is an implementation 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 the class to be tested according to the first annotation and acquiring the method to be tested according to the second annotation when the application program runs; outputting the acquired class to be tested and the method to be tested to a pre-established interface model, and generating a test interface aiming at the class to be tested and the method to be tested.
6. The apparatus of claim 5, wherein the apparatus further comprises:
And the test unit is used for calling the class to be tested and the method to be tested according to the reflection mechanism when the test interface is used for testing so as to realize the testing of the class to be tested and the method to be tested.
7. The apparatus of claim 6, wherein the application is developed based on a Spring framework; and the test interface generating unit is further configured to:
When the application program is started, registering the annotated class and the annotated method to 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 generation unit is further configured to:
loading the acquired class to be tested and the acquired method to be tested into a memory by utilizing a task class which is created in advance in the interface model; and filling the classes to be tested and the methods to be tested in the memory into the interface model.
9. An electronic device, comprising:
One or more processors;
Storage means for storing one or more programs,
When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the interface testing method of any of claims 1-4.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the interface testing method according to any of claims 1-4.
CN201811051627.4A 2018-09-10 2018-09-10 Interface testing method and device Active CN110888794B (en)

Priority Applications (1)

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

Applications Claiming Priority (1)

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

Publications (2)

Publication Number Publication Date
CN110888794A CN110888794A (en) 2020-03-17
CN110888794B true CN110888794B (en) 2024-09-20

Family

ID=69745008

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN110888794B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112286802B (en) * 2020-10-23 2023-04-25 上海淇玥信息技术有限公司 Method and device for testing program performance and electronic equipment
CN112948264B (en) * 2021-03-30 2024-07-02 完美世界(重庆)互动科技有限公司 Method and device for executing test task, system, storage medium and electronic device
CN113342736A (en) * 2021-06-03 2021-09-03 网易传媒科技(北京)有限公司 Storage path management method, device, medium and computing equipment
CN113505083B (en) * 2021-09-09 2021-12-14 连连宝(杭州)信息技术有限公司 Interface pressure performance testing method, device, equipment and medium

Citations (2)

* 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
CN108415834A (en) * 2018-02-12 2018-08-17 平安科技(深圳)有限公司 Explain rear end method of calibration, device, computer equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10261890B2 (en) * 2015-09-14 2019-04-16 Salesforce.Com, Inc. Methods and systems for executing tests using grouped/filtered test classes during testing of an application
CN106547689B (en) * 2016-10-20 2019-03-01 金航数码科技有限责任公司 A kind of automatic test cases development system and method based on web

Patent Citations (2)

* 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
CN108415834A (en) * 2018-02-12 2018-08-17 平安科技(深圳)有限公司 Explain rear end method of calibration, device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN110888794A (en) 2020-03-17

Similar Documents

Publication Publication Date Title
US11188310B2 (en) Automatically generating an interface description in an interface description language
CN110888794B (en) Interface testing method and device
CN109062563B (en) Method and device for generating page
CN108964968B (en) Service access management method and system in container cloud environment
US10353702B2 (en) Source code element signatures
CN110543297B (en) Method and apparatus for generating source code
CN113778848A (en) Test code generation method, device, computer system and medium
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN110780874B (en) Method and device for generating information
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN113485927B (en) Test data generation method, device, equipment and storage medium
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
US11288170B1 (en) Log analysis debugging without running on real production environment
CN110928571A (en) Business program development method and device
CN112395098A (en) Application program interface calling method and device, storage medium and electronic equipment
CN115599386A (en) Code generation method, device, equipment and storage medium
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN113495730A (en) Resource package generation and analysis method and device
CN111158661A (en) System interface docking method, device, medium and electronic equipment
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN113535565B (en) Interface use case generation method, device, equipment and medium
CN114691527A (en) Unit test case generation method, apparatus, device, medium, and program product
CN111539200B (en) Method, device, medium and electronic equipment for generating rich text
CN113760292A (en) Method and device for developing application program, electronic equipment and storage medium
CN109697141B (en) Method and device for visual testing

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
GR01 Patent grant
GR01 Patent grant