CN115309449A - Method and device for generating interface unit test coding file based on Spring and Maven - Google Patents

Method and device for generating interface unit test coding file based on Spring and Maven Download PDF

Info

Publication number
CN115309449A
CN115309449A CN202210977094.2A CN202210977094A CN115309449A CN 115309449 A CN115309449 A CN 115309449A CN 202210977094 A CN202210977094 A CN 202210977094A CN 115309449 A CN115309449 A CN 115309449A
Authority
CN
China
Prior art keywords
test
file
maven
spring
interface
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210977094.2A
Other languages
Chinese (zh)
Inventor
陈子宏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China 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 Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202210977094.2A priority Critical patent/CN115309449A/en
Publication of CN115309449A publication Critical patent/CN115309449A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a method and a device for generating an interface unit test coding file based on Spring and Maven, which relate to the technical field of computer software development and can be used in the financial field, and the method comprises the following steps: in the project application development, the test coding elements are marked in the external annotation of the interface based on the Spring self-defined annotation form; triggering an interface information acquisition action by executing a Maven packing command of a project application to acquire the test coding elements; analyzing and assembling the test coding elements to generate a test coding framework file; and obtaining an interface unit test coding file by using the test coding skeleton file, the test input parameters and the expected result parameters. The method and the device can avoid repeated work to the maximum extent, reduce the energy and time of occupying developers, improve the working efficiency of the developers, reduce the phenomenon that the business interface codes are wrong due to omission of test branches of the developers, and reduce the code error rate.

Description

Method and device for generating interface unit test coding file based on Spring and Maven
Technical Field
The invention relates to the technical field of computer software development, can be used in the financial field, and particularly relates to a method and a device for generating an interface unit test coding file based on Spring and Maven.
Background
In the daily production task of background system software products, unit testing of interfaces is indispensable, but the task is often complex and tedious work, because each logic branch of each interface needs to be covered, a lot of time is needed to encode the unit testing method of the interface, the work efficiency of developers is greatly reduced, and a great part of effort and time of the developers is occupied. When the interface branches are complex, a developer easily omits a test branch, so that an error interface code is not found, a subsequent production task is blocked, and even a production problem occurs.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for generating an interface unit test code file based on Spring and Maven to solve at least one of the above-mentioned problems.
In order to achieve the purpose, the invention adopts the following scheme:
according to a first aspect of the present invention, there is provided a method for generating an interface unit test code file based on Spring and Maven, the method including: in the project application development, the test coding elements are marked in the external annotation of the interface based on the Spring self-defined annotation form; triggering an interface information acquisition action by executing a Maven packing command of a project application to acquire the test coding elements; analyzing and assembling the test coding elements to generate a test coding skeleton file; and obtaining an interface unit test coding file by using the test coding skeleton file, the test input parameters and the expected result parameters.
According to a second aspect of the present invention, there is provided an interface unit test code file generating apparatus based on Spring and Maven, the apparatus including: the marking unit is used for marking the test coding element in the external annotation of the interface based on the Spring user-defined annotation form in the project application development; the acquisition unit is used for triggering an interface information acquisition action by executing a Maven packing command of the project application so as to acquire the test coding elements; the skeleton generation unit is used for analyzing and assembling the test coding elements to generate a test coding skeleton file; and the file generating unit is used for obtaining an interface unit test coding file by utilizing the test coding skeleton file, the test input parameters and the expected result parameters.
According to a third aspect of the present invention, there is provided an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the above method when executing the computer program.
According to a fourth aspect of the invention, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method.
According to a fifth aspect of the invention, there is provided a computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the above method.
According to the technical scheme, the test coding elements are marked in the external annotation of the interface in the project application development through the Spring annotation form, then the acquisition command is triggered when the project application Maven is used for packaging, the acquired test coding elements are generated into the test coding skeleton file, and the test coding skeleton file is further generated into the test coding file, so that repeated work can be avoided to the maximum extent, the energy and time occupied by developers are reduced, the working efficiency of the developers is improved, the phenomenon that the business interface coding is wrong due to the fact that the developers miss test branches can be reduced, and the code error rate is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the prior art descriptions will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts. In the drawings:
fig. 1 is a schematic flowchart of a method for generating an interface unit test code file based on Spring and Maven according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a method for generating an interface unit test code file based on Spring and Maven according to another embodiment of the present application;
fig. 3 is a schematic structural diagram of an interface unit test code file generating device based on Spring and Maven according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a framework generation unit provided in an embodiment of the present application;
fig. 5 is a schematic diagram of an electronic device provided in an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings. The exemplary embodiments and descriptions of the present invention are provided to explain the present invention, but not to limit the present invention.
The following first presents some technical terms related to the present application in a simplified form:
the term "Spring": the Spring framework is an open source code J2EE application program framework and is a lightweight container for managing the life cycle of a software organization model (bean).
The term "Maven": the Java project management system is a project management tool and can be used for building and managing the dependency of Java projects.
The term "mock": that is, in the testing process, for some objects which are not easy to construct/obtain, a mock object is created to simulate the behavior of the object.
Fig. 1 is a schematic flow chart of a method for generating an interface unit test code file based on Spring and Maven according to an embodiment of the present application, where the method includes the following steps:
step S101: and in the project application development, the test coding elements are marked in the external annotation of the interface based on the Spring self-defined annotation form.
In the process of developing a project application, after a service interface is developed, the present embodiment marks a test coding element, which is necessary for a subsequent coding test of the interface, in an external annotation of the service interface in a form of Spring custom annotation.
Preferably, the test code element may include, but is not limited to, the following: and testing a target class, a mock method and a mock branch, wherein different other elements can be added according to different interfaces.
Step S102: and triggering an interface information acquisition action by executing a Maven packed command of the project application to acquire the test coding elements.
After the project application development is completed, in the Maven packaging process of the application, the information acquisition action of the interface is triggered according to the packaging command, and the test coding elements are acquired from the external annotation of the interface.
Step S103: and analyzing and assembling the test coding elements to generate a test coding skeleton file.
Step S104: and obtaining an interface unit test coding file by using the test coding skeleton file, the test input parameters and the expected result parameters.
According to the technical scheme, the interface unit test code file generation method based on Spring and Maven marks the test code elements in the external notes of the interface in the project application development in the Spring note form, triggers the acquisition command when the project application Maven is used for packaging, generates the acquired test code elements into the test code skeleton file, and further generates the test code file. It can be seen that the test coding elements of one interface are marked when the interface is completed in the application, so that the interface cannot be omitted in the subsequent interface test, in addition, the test coding skeleton file automatically generated can avoid repeated work to the maximum extent, the energy and time occupied by developers are reduced, the working efficiency of the developers is improved, the phenomenon that the business interface codes are wrong due to the fact that test branches are omitted by the developers can be reduced, and the code error rate is reduced.
Fig. 2 is a schematic flow chart of a method for generating an interface unit test code file based on Spring and Maven according to another embodiment of the present application, where the method includes the following steps:
step S201: and in the project application development, the test coding elements are marked in the external annotation of the interface based on the Spring self-defined annotation form. The test encoding elements may include, but are not limited to, the following: and testing a target class, a mock method and a mock branch, wherein different other elements can be added according to different interfaces.
Step S202: and introducing the test code file generation plug-in into a pom file of the project in a Maven coordinate dependence mode, and triggering the acquisition action of the test code file generation plug-in to acquire the test code elements by executing a Maven packaging command of the project application when the project application is packaged at the project application completion stage.
Step S203: analyzing and assembling the test coding elements into a Java entity, wherein the attributes of the Java entity comprise a test target class name, a mock member variable name, a mock class name and a mock method name, and a test framework file is generated according to the Java entity.
Step S204: and obtaining an interface unit test coding file by using the test coding skeleton file, the test input parameters and the expected result parameters.
According to the technical scheme, the interface unit test code file generation method based on Spring and Maven marks the test code elements in the external notes of the interface in the project application development in the Spring note form, triggers the acquisition command when the project application Maven is used for packaging, generates the acquired test code elements into the test code skeleton file, and further generates the test code file. It can be seen that the test coding elements of one interface are marked when the interface is completed in the application, so that the interface cannot be omitted in the subsequent interface test, in addition, the test coding skeleton file automatically generated can avoid repeated work to the maximum extent, the energy and time occupied by developers are reduced, the working efficiency of the developers is improved, the phenomenon that the business interface codes are wrong due to the fact that test branches are omitted by the developers can be reduced, and the code error rate is reduced.
Fig. 3 is a schematic structural diagram of an interface unit test code file generating device based on Spring and Maven according to an embodiment of the present application, where the device includes: the annotation unit 310, the acquisition unit 320, the skeleton generation unit 330 and the file generation unit 340 are connected in sequence.
The annotation unit 310 is used for annotating the test coding element in the external annotation of the interface based on the Spring self-defined annotation form in the project application development. In the process of developing a project application, after a service interface is developed, the present embodiment marks a test coding element, which is necessary for a subsequent coding test of the interface, in an external annotation of the service interface in a form of Spring custom annotation.
The collecting unit 320 is configured to trigger an interface information collecting action by executing a Maven packed command of the project application to collect the test code element. After the project application development is finished, in the Maven packaging process of the application, the information acquisition action of the interface is triggered according to the packaging command, and the test coding elements are acquired from the external annotation of the interface.
The skeleton generating unit 330 is configured to parse and assemble the test coding elements, and generate a test coding skeleton file.
The file generating unit 340 is configured to obtain an interface unit test code file by using the test code skeleton file, the test input parameter, and the expected result parameter.
Preferably, the test coding element includes: and testing a target class, a mock method and a mock branch.
Preferably, as shown in fig. 4, the skeleton generating unit 330 in this embodiment may include an analyzing and assembling module 331 and a skeleton generating module 332, where the analyzing and assembling module 331 is configured to analyze and assemble the test coding elements into a Java entity, and attributes of the Java entity include a test target class name, a mock member variable name, a mock class name, and a mock method name; the framework generation module 332 is configured to generate a test framework file according to the Java entity.
Preferably, the collecting unit 320 may further be specifically configured to: and introducing the test code file generation plug-in into a pom file of the project in a Maven coordinate dependent mode, and triggering the acquisition action of the test code file generation plug-in by executing a Maven packaging command of the project application when the project application is packaged at the project application completion stage.
According to the technical scheme, the interface unit test coding file generation device based on Spring and Maven marks the test coding elements in the external annotation of the interface in the project application development through the Spring annotation form, triggers the acquisition command when the project application Maven is used for packaging, generates the test coding skeleton file from the acquired test coding elements, and regenerates the test coding file. Therefore, the method and the device can finish the test coding element of one interface and mark the interface, so that the interface cannot be omitted in the subsequent interface test, in addition, the test coding framework file automatically generated can avoid repeated work to the maximum extent, the energy and time occupied by developers can be reduced, the working efficiency of the developers can be improved, the phenomenon that the business interface coding is wrong due to the fact that test branches are omitted by the developers can be reduced, and the code error rate can be reduced.
Fig. 5 is a schematic diagram of an electronic device provided in an embodiment of the present invention. The electronic device shown in fig. 5 is a general-purpose data processing apparatus comprising a general-purpose computer hardware structure including at least a processor 501 and a memory 502. The processor 501 and the memory 502 are connected by a bus 503. Memory 502 is adapted to store one or more instructions or programs that are executable by processor 501. The one or more instructions or programs are executed by the processor 501 to implement the steps of the method for generating the interface unit test code file based on Spring and Maven.
The processor 501 may be an independent microprocessor or a set of one or more microprocessors. Thus, the processor 501 implements the processing of data and the control of other devices by executing commands stored in the memory 502 to execute the method flows of the embodiments of the present invention as described above. The bus 503 connects the above components together, and also connects the above components to a display controller 504 and a display device and an input/output (I/O) device 505. Input/output (I/O) device 505 may be a mouse, keyboard, modem, network interface, touch input device, motion sensitive input device, printer, and other devices known in the art. Typically, input/output (I/O) devices 505 are connected to the system through an input/output (I/O) controller 506.
The memory 502 may store, among other things, software components such as an operating system, communication modules, interaction modules, and application programs. Each of the modules and applications described above corresponds to a set of executable program instructions that perform one or more functions and methods described in embodiments of the invention.
An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the step of generating the Spring and Maven-based interface unit test code file.
An embodiment of the present invention further provides a computer program product, which includes a computer program/instruction, and when the computer program/instruction is executed by a processor, the step of generating the interface unit test code file based on Spring and Maven is implemented.
In summary, according to the method and the device for generating the interface unit test code file based on Spring and Maven provided by the embodiments of the present invention, the test code elements are marked in the external annotation of the interface in the project application development in the form of Spring annotation, and then the acquisition command is triggered when the project application Maven is used for packaging, so as to generate the test code skeleton file from the acquired test code elements, and further generate the test code file. Therefore, the method and the device can finish the test coding element of one interface and mark the interface, so that the interface cannot be omitted in the subsequent interface test, in addition, the test coding framework file automatically generated can avoid repeated work to the maximum extent, the energy and time occupied by developers can be reduced, the working efficiency of the developers can be improved, the phenomenon that the business interface coding is wrong due to the fact that test branches are omitted by the developers can be reduced, and the code error rate can be reduced.
The preferred embodiments of the present invention have been described above with reference to the accompanying drawings. The many features and advantages of the embodiments are apparent from the detailed specification, and thus, it is intended by the appended claims to cover all such features and advantages of the embodiments which fall within the true spirit and scope thereof. Further, since numerous modifications and changes will readily occur to those skilled in the art, it is not desired to limit the embodiments of the invention to the exact construction and operation illustrated and described, and accordingly, all suitable modifications and equivalents may be resorted to, falling within the scope thereof.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (11)

1. A method for generating an interface unit test coding file based on Spring and Maven is characterized by comprising the following steps:
in the project application development, the test coding elements are marked in the external annotation of the interface based on the Spring self-defined annotation form;
triggering an interface information acquisition action by executing a Maven packing command of a project application to acquire the test coding elements;
analyzing and assembling the test coding elements to generate a test coding framework file;
and obtaining an interface unit test coding file by using the test coding skeleton file, the test input parameters and the expected result parameters.
2. The Spring and Maven-based interface unit test code file generating method of claim 1, wherein the test code element comprises: and testing a target class, a mock method and a mock branch.
3. The method for generating a testing code file of an interface unit based on Spring and Maven of claim 2, wherein the analyzing and assembling the testing code elements to generate the testing code skeleton file comprises:
analyzing and assembling the test coding elements into a Java entity, wherein the attributes of the Java entity comprise a test target class name, a mock member variable name, a mock class name and a mock method name, and a test framework file is generated according to the Java entity.
4. The Spring and Maven-based interface unit test code file generating method of claim 1, wherein the triggering an interface information collection action to collect the test code elements by executing a Maven-packed command of a project application comprises: and introducing the test code file generation plug-in into a pom file of the project in a Maven coordinate dependence mode, and triggering the acquisition action of the test code file generation plug-in to acquire the test code elements by executing a Maven packaging command of the project application when the project application is packaged at the project application completion stage.
5. An interface unit test code file generating device based on Spring and Maven, characterized in that the device comprises:
the annotation unit is used for annotating the test coding elements in the external annotation of the interface based on the Spring user-defined annotation form in the project application development;
the acquisition unit is used for triggering an interface information acquisition action by executing a Maven packing command of the project application so as to acquire the test coding elements;
the skeleton generating unit is used for analyzing and assembling the test coding elements to generate a test coding skeleton file;
and the file generating unit is used for obtaining an interface unit test coding file by using the test coding framework file, the test input parameters and the expected result parameters.
6. The Spring and Maven-based interface unit test code file generating device of claim 5, wherein the test code element comprises: and testing a target class, a mock method and a mock branch.
7. The Spring and Maven-based interface unit test coding file generating device of claim 6, wherein the skeleton generating unit comprises an parsing and assembling module and a skeleton generating module, the parsing and assembling module is used for parsing and assembling the test coding elements into Java entities, and the attributes of the Java entities comprise test target class names, mock member variable names, mock class names and mock method names; and the framework generation module is used for generating a test framework file according to the Java entity.
8. The apparatus for generating a Spring and Maven-based interface unit test code file according to claim 5, wherein the collecting unit is specifically configured to: and introducing the test code file generation plug-in into a pom file of the project in a Maven coordinate dependent mode, and triggering the acquisition action of the test code file generation plug-in by executing a Maven packaging command of the project application when the project application is packaged at the project application completion stage.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 4 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 4.
11. A computer program product comprising computer programs/instructions, characterized in that the computer programs/instructions, when executed by a processor, implement the steps of the method of any of claims 1 to 4.
CN202210977094.2A 2022-08-15 2022-08-15 Method and device for generating interface unit test coding file based on Spring and Maven Pending CN115309449A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210977094.2A CN115309449A (en) 2022-08-15 2022-08-15 Method and device for generating interface unit test coding file based on Spring and Maven

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210977094.2A CN115309449A (en) 2022-08-15 2022-08-15 Method and device for generating interface unit test coding file based on Spring and Maven

Publications (1)

Publication Number Publication Date
CN115309449A true CN115309449A (en) 2022-11-08

Family

ID=83862674

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210977094.2A Pending CN115309449A (en) 2022-08-15 2022-08-15 Method and device for generating interface unit test coding file based on Spring and Maven

Country Status (1)

Country Link
CN (1) CN115309449A (en)

Similar Documents

Publication Publication Date Title
CN103136406B (en) The method of visualization applications simulations function code
US20120254830A1 (en) Verification of computer-executable code generated from a model
JP5396979B2 (en) Software development support device, system, software development support device function expansion method, and program
US9864588B2 (en) Canonicalized versions of reuse candidates in graphical state diagrams
CN110209389B (en) XML-based data generation tool development system
CN103942099A (en) Parallel task execution method and device based on Hive
EP2141587A1 (en) Method and system for generating of a control flow graph for representing a program code
Wahler et al. CAST: Automating software tests for embedded systems
CN110955410A (en) Automatic code generation method, device, equipment and medium
Sjölund Tools and Methods for Analysis, Debugging, and Performance Improvement of Equation-Based Models
CN103678485A (en) Virtual experiment process node driving and movable packaging system
Yoong et al. Efficient implementation of IEC 61499 function blocks
Fahringer et al. Teuta: Tool support for performance modeling of distributed and parallel applications
CN115309449A (en) Method and device for generating interface unit test coding file based on Spring and Maven
Terrier et al. Mde benefits for distributed, real time and embedded systems
CN113296764A (en) IDL file generation system and method based on model driving and terminal
CN112230904A (en) Code generation method and device based on interface document, storage medium and server
Wang et al. MBD-DSP: A model based design solution for DSP
Apostol et al. UML to code, and code to UML, a view inside implementation challenges and cost
Kumaran et al. An approach to automatic generation of test cases based on use cases in the requirements phase
KR102413994B1 (en) Method for visualizing software source code after modifying it for improving performance and device thereof
Yildiz et al. A model-derivation framework for software analysis
Rodríguez-Echeverría et al. IFML-based Model-Driven Front-End Modernization
Simonov DSL Designing And Evaluating For Ocean Models
CN117193806A (en) Method and device for generating environment mirror image for compiling construction

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