Interface testing method and device

By using custom annotations in the application source code to annotate the classes and methods to be tested, and using the reflection mechanism to generate the test interface, it solves the problem of difficulty for back-end engineers in writing front-end test interfaces, and achieves efficient interface testing and unified and easy-to-operate Test interface platform.

CN110888794BActive Publication Date: 2024-09-20BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201811051627.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-09-10
Publication Date
2024-09-20
Estimated Expiration
2038-09-10

AI Technical Summary

Technical Problem

During the interface testing process, back-end engineers are not familiar with front-end technology and have difficulty writing front-end test interfaces, resulting in low testing efficiency. The existing JUnit unit testing framework lacks interface operability.

Method used

By using custom annotations in the application source code to annotate the classes and methods to be tested, and using the reflection mechanism to obtain and output to the pre-established interface model at runtime, the test interface is generated and the development workload of the back-end engineer is reduced.

Benefits of technology

Implemented interface testing, reduced development and testing costs, improved testing efficiency, improved project testability and application robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110888794B
    Figure CN110888794B
Patent Text Reader

Abstract

The present invention discloses an interface testing method and device, and relates to the field of computer technology. A specific implementation of the method includes: in the source code of an application, a class to be tested is annotated with a first annotation, and a method to be tested is annotated with a second annotation; wherein the first annotation and the second annotation are both custom annotations, the class to be tested is an implementation class of the interface to be tested of the application, and the method to be tested is a method of the class to be tested; when the application is running, the class to be tested is obtained according to the first annotation, and the method to be tested is obtained according to the second annotation; the obtained class to be tested and the method to be tested are output to a pre-established interface model, and a test interface for the class to be tested and the method to be tested is generated. This implementation can fill the class and method of the interface to be tested into the pre-established interface model, and generate a test interface, so that the back-end engineer does not have to consider the implementation of the test interface, thereby improving the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to an interface testing method and apparatus. Background Technology

[0002] During application interface testing, backend engineers often need to write frontend test interfaces for the interfaces they provide to facilitate testing. Since backend engineers are generally not familiar with frontend test interface technologies such as JavaScript (a scripting language) and Cascading Style Sheets (CSS), writing frontend test interfaces is quite difficult and can easily impact testing efficiency.

[0003] In existing technologies, the JUnit unit testing framework is generally used for interface testing. However, JUnit does not provide a graphical interface and lacks ease of use. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide an interface testing method and apparatus that can populate the classes and methods of the interface to be tested into a pre-established interface model to generate a test interface, thereby eliminating the need for backend engineers to consider the implementation of the test interface and thus improving testing efficiency.

[0005] To achieve the above objectives, according to one aspect of the present invention, an interface testing method is provided.

[0006] The interface testing method of this invention includes: in the application source code, annotating the class to be tested with a first annotation and annotating the method to be tested with a second annotation; wherein, the first annotation and the second annotation are both custom annotations, the class to be tested is the implementation class of the interface to be tested in the application, and the method to be tested is the method of the class to be tested; when the application runs, obtaining the class to be tested according to the first annotation and obtaining the method to be tested according to the second annotation; outputting the obtained class to be tested and method to be tested to a pre-established interface model to generate a test interface for the class to be tested and method to be tested.

[0007] Optionally, the method further includes: when testing on the test interface, calling the class to be tested and the method to be tested according to the reflection mechanism to realize the testing of the class to be tested and the method to be tested.

[0008] Optionally, the application is developed based on the Spring framework; and, when the application is running, obtaining the class to be tested based on the first annotation and obtaining the method to be tested based on the second annotation specifically includes: registering the annotated classes and methods to the Spring container when the application starts; obtaining the class to be tested from the Spring container based on the first annotation and obtaining the method to be tested from the Spring container based on the second annotation.

[0009] Optionally, the step of outputting the obtained test class and test method to a pre-established interface model specifically includes: using a pre-created task class in the interface model to load the obtained test class and test method into memory; and filling the test class and test method in memory into the interface model.

[0010] To achieve the above objectives, according to another aspect of the present invention, an interface testing apparatus is provided.

[0011] The interface testing apparatus of this invention may include: an annotation unit, used to annotate the class to be tested using a first annotation and the method to be tested using a second annotation in the application source code; wherein the first annotation and the second annotation are both custom annotations, the class to be tested is the implementation class of the interface to be tested in the application, and the method to be tested is the method of the class to be tested; and a test interface generation unit, used to obtain the class to be tested based on the first annotation and the method to be tested based on the second annotation when the application is running; and to output the obtained class to be tested and method to be tested to a pre-established interface model to generate a test interface for the class to be tested and method to be tested.

[0012] Optionally, the device may further include: a testing unit, used to invoke the class to be tested and the method to be tested according to the reflection mechanism when testing is performed on the testing interface, so as to realize the testing of the class to be tested and the method to be tested.

[0013] Optionally, the application is developed based on the Spring framework; and the test interface generation unit can be further used to: register annotated classes and methods to the Spring container when the application starts; obtain the class to be tested from the Spring container according to the first annotation, and obtain the method to be tested from the Spring container according to the second annotation.

[0014] Optionally, the test interface generation unit can be further used to: load the obtained test class and test method into memory using the pre-created task class in the interface model; and fill the test class and test method in memory into the interface model.

[0015] To achieve the above objectives, according to another aspect of the present invention, an electronic device is provided.

[0016] An electronic device according to the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the interface testing method provided by the present invention.

[0017] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is provided.

[0018] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the interface testing method provided by the present invention.

[0019] According to the technical solution of the present invention, one embodiment of the above invention has the following advantages or beneficial effects:

[0020] First, custom annotations are created in the application source code to mark the test classes and methods that implement the interface under test. During application runtime, the test classes and methods are retrieved based on the custom annotations and populated as components into a pre-built interface model to generate the test interface. During testing, reflection is used to call the test classes and methods. This allows backend engineers to perform UI testing by simply annotating the test classes and methods and referencing the UI model package, thereby reducing development and testing costs, improving testing efficiency, and alleviating unnecessary workload for backend engineers. Furthermore, this invention provides a unified and easy-to-use test interface platform through the pre-built interface model, enhancing the project's testability and application robustness.

[0021] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0022] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0023] Figure 1 This is a schematic diagram of the main steps of the interface testing method according to an embodiment of the present invention;

[0024] Figure 2 This is a schematic diagram of the implementation architecture of the interface testing method according to an embodiment of the present invention;

[0025] Figure 3 This is a schematic diagram of the components of the interface testing device according to an embodiment of the present invention;

[0026] Figure 4 This is an exemplary system architecture diagram that can be applied thereto according to embodiments of the present invention;

[0027] Figure 5 This is a schematic diagram of the structure of an electronic device used to implement the interface testing method in the embodiments of the present invention. Detailed Implementation

[0028] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0029] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.

[0030] Figure 1 This is a schematic diagram of the main steps of the interface testing method according to an embodiment of the present invention.

[0031] like Figure 1 As shown, the interface testing method of this invention can be executed according to the following steps:

[0032] Step S101: In the application source code, annotate the class to be tested with the first annotation and annotate the method to be tested with the second annotation.

[0033] In this embodiment of the invention, both the first annotation and the second annotation are custom annotations. The first annotation is used to annotate the class to be tested, and the second annotation is used to annotate the method to be tested within the class to be tested; neither reflects any other business logic. Specifically, in programming languages ​​such as Java, an annotation is a special modifier applied to class, method, parameter, variable, constructor, or package declaration; it is a tool used to describe metadata. Custom annotations are annotations written by developers using meta-annotations, in addition to the system's built-in annotations. In specific applications, the system provides the following four types of meta-annotations:

[0034] @Documented – Used to determine whether a defined annotation will be included in the Java documentation;

[0035] @Retention – Used to determine when a defined annotation is used;

[0036] @Target – Used to determine where the annotation is used;

[0037] @Inherited – An annotation used to determine whether subclasses are allowed to inherit the definition.

[0038] It's important to note that the above annotations are completely different from comments. Generally, comments are used to inform developers of the logic, explanations, and characteristics of code, and can be written freely without restrictions; during compilation, comments are completely ignored by the compiler. Annotations, on the other hand, inform the Java Virtual Machine of the metadata of elements such as classes, methods, parameters, variables, constructors, or packages by marking them. They generally begin with "@" and have strict restrictions on their position, syntax, and content. If any errors occur, an exception will be displayed during compilation.

[0039] The following Java example demonstrates how to define the first and second annotations. In the example below, the first annotation is the ExportService annotation, and the second annotation is the ExportMethod annotation.

[0040] The specific definition code for ExportService is as follows:

[0041]

[0042] The first line of code indicates that the defined annotation can be used to describe classes, interfaces, or declarations; the second line of code indicates that the defined annotation will never be discarded and will be retained at runtime; the third line of code defines the annotation with the public modifier; the fourth line of code sets the name attribute (string type) of the ExportService annotation, which defaults to "not set"; the fifth line of code sets the desc attribute (string type) of the ExportService annotation, which defaults to "no description"; the sixth line of code sets the appGroup attribute (string type) of the ExportService annotation, which defaults to "application not grouped"; and the seventh line of code sets the serGroup attribute (string type) of the ExportService annotation, which defaults to "business not grouped".

[0043]

[0044] The first line of code indicates that the defined annotation can be used to describe methods; the second line of code indicates that the defined annotation will never be discarded and will be retained at runtime; the third line of code defines the annotation with the public modifier; the fourth line of code sets the name attribute (string type) of the ExportMethod annotation, which has a default value of "not set"; the fifth line of code sets the desc attribute (string type) of the ExportMethod annotation, which has a default value of "no description".

[0045] By setting the custom annotations described above, this invention can control which classes and methods will be subsequently populated into the test page, thereby enabling configurable operation of the test page data. It should be noted that the above code is merely an example and does not guarantee its functionality, nor does it impose any restrictions on the specific definition of the first and second annotations.

[0046] In step S101, after the first and second annotations are defined, the first annotation can be used to annotate the class to be tested in the application source code, and the second annotation can be used to annotate the method to be tested. In practical applications, the class to be tested is the implementation class of the application's interface to be tested, and the method to be tested is the method of the class to be tested.

[0047] The class to be tested can be labeled as shown in the following code:

[0048] @ExportService

[0049] public class JimCacheServiceImpl implements JimCacheService

[0050] Where class represents a class, JimCacheServiceImpl is the class to be tested, implements is the implementation keyword, and JimCacheService is the interface to be tested.

[0051] The method to be tested can be labeled as shown in the following code:

[0052] @ExportMethod

[0053] public long exportDelCache()

[0054] Where long represents a long integer and exportCache represents the method to be tested.

[0055] After the above annotations are made, the class and method to be tested can be populated into the interface template as components, which will be described in detail below.

[0056] Step S102: During application runtime, obtain the class to be tested based on the first annotation and the method to be tested based on the second annotation; output the obtained class to be tested and method to be tested to the pre-established interface model to generate a test interface for the class to be tested and method to be tested.

[0057] In this step, the annotations used in step S101 can be used to obtain the class and method under test during application runtime (including startup). For example, if the application is developed using the Spring framework (an open-source Java platform), the annotated classes and methods can be automatically registered in the Spring container (a space for managing managed beans) when the application starts. Then, the class under test is obtained from the Spring container based on the first annotation, and the method under test is obtained from the Spring container based on the second annotation. In specific applications, the getAnnotation method can be used to obtain the class under test. The input parameter of this method is the first annotation, and the output parameter is the class under test annotated with the first annotation.

[0058] In one embodiment, after obtaining the class and method to be tested, they can be output as components to a pre-established interface model to generate a test interface for the class and method to be tested. Specifically, the interface model refers to the front-end interface test interface model, which needs to interact with the interface (including the implementation class and its methods) code to generate the final test interface. It can be implemented using dynamic page frameworks such as Bootstrap. In specific applications, the obtained class and method to be tested can first be loaded into memory using a pre-created task class in the interface model, and then the class and method to be tested in memory can be populated into the interface model to generate the test interface. It is understood that before outputting the class and method to be tested to the interface model, the application needs to reference the interface model's package, such as the Java Archive (JAR) package.

[0059] It should be noted that in practical applications, the interface model can also leverage the pluggable functionality of Servlet 3.0 (an interface or server-side program written in Java) to achieve non-intrusive integration between the interface model and the application. When using this, the corresponding deployment description file can be placed in the META-INF directory (a directory storing metadata files) of the interface model JAR package, and the JAR package can be placed in the WEB-INF / lib directory (a directory storing JAR packages). In this way, the application does not need to declare the aforementioned task classes of the interface template and can directly interact with the interface template non-intrusively.

[0060] With the above settings, a user-friendly test interface can be generated for testers. During testing, the Java reflection mechanism can be used to call the class and method under test to perform the testing of the interface. As a known technology in this field, Java reflection refers to the ability, at runtime, to obtain all attributes and methods of any class; and to call any method and attribute of any object. In other words, through Java reflection, a Java program can load a class whose name is only known at runtime, learn its complete structure, generate its object instance, and then set its attributes or call its methods.

[0061] Figure 2 This is a schematic diagram of the implementation architecture of the interface testing method according to an embodiment of the present invention. Figure 2 As shown, after annotating the application source code with custom annotations and referencing the interface model package, multiple interface modules of the application (including the implementation classes and methods of each interface) can interact with the interface model non-intrusively, and generate a graphical test interface to implement the functional testing of the interface.

[0062] It should be noted that although the above description mainly uses JAVA as an example to illustrate the technical solution of this invention, this does not limit the application scope of the interface testing method provided by this invention. In fact, the method of this invention can be used for interface testing in any applicable software environment and achieve similar technical effects.

[0063] In the technical solution of this invention, custom annotations are first created in the application source code to mark the test class and method that implement the interface to be tested. During application runtime, the test class and method are obtained based on the custom annotations, and then populated as components into a pre-established interface model to generate a test interface. During testing, reflection is used to call the test class and method. This allows backend engineers to perform UI testing by simply annotating the test class and method and referencing the UI model package, thereby reducing development and testing costs, improving testing efficiency, and alleviating unnecessary workload for backend engineers. Furthermore, this invention also provides a unified and easy-to-use test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application.

[0064] It should be noted that, for the sake of ease of description, the foregoing method embodiments are described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, and some steps may actually be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential for implementing the present invention.

[0065] To facilitate better implementation of the above-described solutions of the embodiments of the present invention, related apparatus for implementing the above-described solutions is also provided below.

[0066] Please see Figure 3 As shown, an interface testing device 300 provided in this embodiment of the invention may include: a labeling unit 301 and a test interface generation unit 302.

[0067] The annotation unit 301 can be used to annotate the class to be tested with a first annotation and the method to be tested with a second annotation in the application source code; wherein the first annotation and the second annotation are both custom annotations, the class to be tested is the implementation class of the interface to be tested in the application, and the method to be tested is the method of the class to be tested.

[0068] The test interface generation unit 302 can be used to obtain the class to be tested based on the first annotation and the method to be tested based on the second annotation when the application is running; output the obtained class to be tested and method to be tested to a pre-established interface model to generate a test interface for the class to be tested and method to be tested.

[0069] In this embodiment of the invention, the device 300 may further include a testing unit, which is used to call the class to be tested and the method to be tested according to the reflection mechanism when testing is performed on the testing interface, so as to realize the testing of the class to be tested and the method to be tested.

[0070] In a specific application, the application is developed based on the Spring framework; and the test interface generation unit 302 can be further used to: register the annotated classes and methods to the Spring container when the application starts; obtain the class to be tested from the Spring container according to the first annotation, and obtain the method to be tested from the Spring container according to the second annotation.

[0071] Furthermore, in this embodiment of the invention, the test interface generation unit 302 can be further used to: load the obtained test class and test method into memory using the pre-created task class in the interface model; and fill the test class and test method in memory into the interface model.

[0072] In the technical solution of this invention, custom annotations are first created in the application source code to mark the test class and method that implement the interface to be tested. During application runtime, the test class and method are obtained based on the custom annotations, and then populated as components into a pre-established interface model to generate a test interface. During testing, reflection is used to call the test class and method. This allows backend engineers to perform UI testing by simply annotating the test class and method and referencing the UI model package, thereby reducing development and testing costs, improving testing efficiency, and alleviating unnecessary workload for backend engineers. Furthermore, this invention also provides a unified and easy-to-use test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application.

[0073] Figure 4 An exemplary system architecture 400 is shown that can be applied to the interface testing method or interface testing apparatus of the present invention.

[0074] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, and 403, network 404, and server 405 (this architecture is merely an example; the components included in a specific architecture may be adjusted according to the specific application). Network 404 serves as the medium for providing a communication link between terminal devices 401, 402, and 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.

[0075] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, and 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0076] Terminal devices 401, 402, and 403 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0077] Server 405 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 401, 402, and 403 (for example only). The backend management server can process received product information query requests and return the processing results (such as target push information and product information—for example only) to the terminal device.

[0078] It should be noted that the interface testing method provided in this embodiment of the invention is generally executed by server 405, and correspondingly, the interface testing device is generally set in server 405.

[0079] It should be understood that Figure 4 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0080] The present invention also provides an electronic device. The electronic device of an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the interface testing method provided by the present invention.

[0081] The following is for reference. Figure 5 It shows a schematic diagram of the structure of a computer system 500 suitable for implementing an electronic device according to embodiments of the present invention. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.

[0082] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 502 or programs loaded from storage section 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the computer system 500. The CPU 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0083] The following components are connected to I / O interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to I / O interface 505 as needed. A removable medium 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 510 as needed so that computer programs read from it can be installed into storage section 508 as needed.

[0084] In particular, according to the embodiments disclosed in this invention, the processes described in the above main step diagrams can be implemented as computer software programs. For example, embodiments of this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the main step diagrams. In the above embodiments, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by central processing unit 501, it performs the functions defined in the system of this invention.

[0085] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0086] The flowcharts and block diagrams in the accompanying drawings 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 a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0087] The units described in the embodiments of the present invention can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor can be described as including an annotation unit and a test interface generation unit. The names of these units do not necessarily limit the unit itself; for example, the test interface generation unit can also be described as "a unit that populates the class to be tested and the method to be tested as components into the interface model."

[0088] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the steps performed by the device include: in the application source code, annotating the class to be tested with a first annotation and annotating the method to be tested with a second annotation; wherein the first annotation and the second annotation are both custom annotations, the class to be tested is the implementation class of the application's interface to be tested, and the method to be tested is a method of the class to be tested; during application runtime, obtaining the class to be tested based on the first annotation and obtaining the method to be tested based on the second annotation; outputting the obtained class to be tested and method to be tested to a pre-established interface model to generate a test interface for the class to be tested and method to be tested.

[0089] In the technical solution of this invention, custom annotations are first created in the application source code to mark the test class and method that implement the interface to be tested. During application runtime, the test class and method are obtained based on the custom annotations, and then populated as components into a pre-established interface model to generate a test interface. During testing, reflection is used to call the test class and method. This allows backend engineers to perform UI testing by simply annotating the test class and method and referencing the UI model package, thereby reducing development and testing costs, improving testing efficiency, and alleviating unnecessary workload for backend engineers. Furthermore, this invention also provides a unified and easy-to-use test interface platform through the pre-established interface model, thereby improving the testability of the project and the robustness of the application.

[0090] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. An interface testing method, It is characterized in that include: In the source code of the application, the class to be tested is annotated with a first annotation, and the method to be tested is annotated with a second annotation; wherein the first annotation and the second annotation are both custom annotations, the class to be tested is an implementation class of the interface to be tested of the application, and the method to be tested is a method of the class to be tested; When the application is running, the class to be tested is obtained according to the first annotation, and the method to be tested is obtained according to the second annotation; the obtained class to be tested and the method to be tested are output to a pre-established interface model to generate a test interface for the class to be tested and the method to be tested.

2. The interface testing method according to claim 1, It is characterized in that The method further comprises: When testing is performed in the test interface, the class to be tested and the method to be tested are called according to the reflection mechanism to implement the testing of the class to be tested and the method to be tested.

3. The interface testing method according to claim 2, It is characterized in that The application is developed based on the Spring framework; and when the application is running, the class to be tested is obtained according to the first annotation, and the method to be tested is obtained according to the second annotation, specifically including: When the application starts, the annotated classes and methods are registered with the Spring container; Get the class to be tested from the Spring container based on the first annotation, and get the method to be tested from the Spring container based on the second annotation.

4. The interface testing method according to any one of claims 1 to 3, It is characterized in that The step of outputting the obtained classes and methods to be tested to a pre-established interface model specifically includes: Using the task class pre-created in the interface model, the acquired class to be tested and the method to be tested are loaded into the memory; Fill the class to be tested and the method to be tested in the memory into the interface model.

5. An interface testing device, It is characterized in that include: An annotation unit is used to annotate the class to be tested with a first annotation and the method to be tested with a second annotation in the source code of the application program; wherein the first annotation and the second annotation are both custom 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; A test interface generation unit is used to obtain the class to be tested according to the first annotation and the method to be tested according to the second annotation when the application is running; output the obtained class to be tested and the method to be tested to a pre-established interface model to generate a test interface for the class to be tested and the method to be tested.

6. The device according to claim 5, It is characterized in that The device further comprises: The test unit is used to call the class to be tested and the method to be tested according to the reflection mechanism when testing in the test interface, so as to implement the testing of the class to be tested and the method to be tested.

7. The device according to claim 6, It is characterized in that The application is developed based on the Spring framework; and the test interface generation unit is further used to: When the application is started, the classes and methods marked with annotations are registered with the Spring container; 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.

8. The device according to any one of claims 5 to 7, It is characterized in that The test interface generation unit is further used to: The obtained classes to be tested and methods to be tested are loaded into the memory by using the task classes pre-created in the interface model; and the classes to be tested and methods to be tested in the memory are filled into the interface model.

9. An electronic device, It is characterized in that include: one or more processors; a storage device 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 implement the interface testing method as described in any one of claims 1-4.

10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the interface testing method as described in any one of claims 1 to 4 is implemented.