CN115470152B - Test code generation method, test code generation device, and storage medium - Google Patents

Test code generation method, test code generation device, and storage medium Download PDF

Info

Publication number
CN115470152B
CN115470152B CN202211361205.3A CN202211361205A CN115470152B CN 115470152 B CN115470152 B CN 115470152B CN 202211361205 A CN202211361205 A CN 202211361205A CN 115470152 B CN115470152 B CN 115470152B
Authority
CN
China
Prior art keywords
control class
target control
test code
interface
test
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
CN202211361205.3A
Other languages
Chinese (zh)
Other versions
CN115470152A (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.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank 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 Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202211361205.3A priority Critical patent/CN115470152B/en
Publication of CN115470152A publication Critical patent/CN115470152A/en
Application granted granted Critical
Publication of CN115470152B publication Critical patent/CN115470152B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Abstract

The application discloses a test code generation method, a test code generation device and a storage medium, wherein the test code generation method comprises the following steps: acquiring an item to be tested, wherein the item to be tested comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct. By means of the method, the control class in the item to be tested can be scanned and automatically generated to generate the test code corresponding to the control class, and flexible configuration and generation of the interface test code are achieved.

Description

Test code generation method, test code generation device, and storage medium
Technical Field
The present invention relates to the field of software testing, and in particular, to a test code generating method, a test code generating device, and a storage medium.
Background
With the continuous development of the internet industry, the scale of software is larger and the structure is complex in the software development process, and each component in the software depends on interfaces to exchange call and data between the components. Therefore, in order to verify whether the function of the interface is correct, the interface in the software needs to be tested.
In an application scenario, when a tester performs interface test, the interface needs to be obtained by operating the whole local project to extract the interface, or accessing the project file through an automatic interface test code generating tool, so that the process of generating the interface test code is complicated, and the requirement on project safety is higher. The interface test code is written through the interface document provided by the developer, and the situation that the test code is wrong due to careless mistakes when the developer writes the interface document can occur.
Disclosure of Invention
The technical problem to be solved mainly by the application is how to realize safe and automatic generation of interface test codes, and in this regard, the application provides a test code generation method, a test code generation device and a storage medium.
In order to solve the technical problems, one technical scheme adopted by the application is as follows: there is provided a test code generation method including: acquiring an item to be tested, wherein the item to be tested comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct.
Scanning a target control class in at least one control class to acquire key information of an interface in the target control class, wherein the method comprises the following steps: scanning at least one control class and an interface method in the target control class to obtain corresponding code annotation; key information of the target control class is obtained based on the code annotation.
Wherein obtaining key information of the target control class based on the code annotation comprises: and acquiring first address information and a request mode of the target control class as key information based on the code annotation of the target control class.
Wherein, the request mode is one of get request and post request.
Wherein obtaining key information of the target control class based on the code annotation comprises: the code annotation based on the interface method acquires the second address information, the request parameter type and the return result type of the interface method as key information.
Wherein after obtaining the key information of the target control class based on the code annotation, further comprising: annotations of the interface methods are obtained and populated into the templates.
The method comprises the steps of scanning a target control class in at least one control class, and before obtaining key information of an interface in the target control class, further comprising: searching all classes in the item to be tested; judging whether each class in all classes is a control class or not; based on the judgment result, the unresolved information is prompted for other classes which are not control classes in all the classes.
Wherein, obtain the project to be tested, include: acquiring a project file of a project to be tested; and acquiring the running code of the item to be tested from the item file.
Wherein scanning the target control class of the at least one control class comprises: a target control class of the at least one control class is scanned based on the run code.
Solves the technical problems, and the other technical scheme adopted by the application is as follows: there is provided a test code generation apparatus comprising a processor and a memory coupled to the processor, the memory storing program data, the processor being operable to execute the program data to implement a test code generation method as described above.
In order to solve the technical problems, another technical scheme adopted by the application is as follows: there is provided a computer readable storage medium storing program data which, when executed, is adapted to carry out the test code generation method described above.
The beneficial effects of this application are: different from the condition of the prior art, the test code generation method provided by the application is applied to a test code generation device, the test code generation device obtains a to-be-tested item, and the to-be-tested item comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct. Compared with the conventional test code generation method, the method for generating the test code by scanning the control class in the item to be tested to acquire the key information and filling the key information into the test template can acquire the interface information by directly analyzing the code of the item file, the interface information is not acquired by an automatic interface test code generation tool, and the safety of the item content is ensured. The test code generating method generates the interface test code based on the code of the project file, and can flexibly configure the interface test code according to the code content of different project files so as to be suitable for various application situations. The interface test codes automatically generated by the test code generating tool can be directly operated, so that the production and the application are performed, the flow of writing the test codes by a tester and actually putting into test is reduced, and the test efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. Wherein:
FIG. 1 is a flow chart of an embodiment of a test code generation method provided in the present application;
FIG. 2 is a flow chart of a test code generation apparatus executing a test code generation method provided in the present application;
FIG. 3 is a schematic view of the first embodiment of the test code generating device provided in the present application;
FIG. 4 is a schematic diagram of a second embodiment of a test code generation apparatus provided herein;
fig. 5 is a schematic structural diagram of an embodiment of a computer readable storage medium provided in the present application.
Detailed Description
The following description of the technical solutions in the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
Referring to fig. 1 and 2, fig. 1 is a flowchart illustrating an embodiment of a test code generating method provided in the present application; fig. 2 is a schematic flow chart of a test code generating device executing a test code generating method.
An interface is a set of predefined functions aimed at enabling intercommunication between applications of different functions, enabling an developer to use the functions provided by other applications in their own application without having to access the source code of the application or understand the details of the internal working mechanism.
The interface test is a test for testing interfaces between components of a system, and is mainly used for testing interfaces between the system and other external systems and interfaces between all sub-modules in the system. The key points of the test are to check the correctness of the interface parameter transmission, the correctness of the interface function realization, the correctness of the output result and the integrity and rationality of fault tolerance treatment of various abnormal conditions. I.e. by url to a server or other module etc. transmitting the data that we want to transmit and then looking at what they return is not what we expect.
As shown in fig. 1 and 2, the test code generating method in the embodiment of the present application includes:
step 11: obtaining an item to be tested, wherein the item to be tested comprises at least one control class.
Specifically, the test code generating device obtains a project file of the project to be tested based on a selection instruction of a user, and obtains an operation code of the project to be tested from the project file.
Alternatively, the test code generating device may implement the scanning of the interface by opening the project file locally based on the plug-in provided by the IDEA tool, without running the project file to parse the code. The IDEA tool is a code editor commonly used by developers, users are familiar with the using method of the tool, and the problem that errors occur due to the fact that the tool is sparse is not easy to generate. And the resources of the server are not required to be additionally occupied, so that the burden of the system is reduced.
Specifically, the test code generating device searches all classes in the item to be tested; judging whether each class in all classes is a control class or not; based on the judging result, prompting the unresolved information to the user on the display screen for other classes which are not control classes in all the classes.
Specifically, the running code of one project file includes an entity class, a control class and a boundary class. The entity class is used to map each entity in the demand, preserving the information that needs to be stored in persistent storage. The control class is a class in the running code for describing the event flow control behavior of one use case and controlling the sequence of events in one use case. A boundary class is a class used to model interactions between the system's external environment and its internal workings. In the interface test, whether the function realized by the interface is correct or not is tested, so that the test code generating device only needs to analyze the control class in the code, and the time for generating the test code can be reduced.
In an embodiment of the present application, the test code generating device may scan a single control class, or may scan an entire project file, to generate an interface test code corresponding to an interface therein.
Step 12: scanning the target control class in at least one control class to acquire the key information of the interface in the target control class.
Specifically, the test code generating device scans a target control class in at least one control class and an interface method in the target control class to obtain a corresponding code annotation;
key information of the target control class is obtained based on the code annotation. The key information comprises first address information of a target control class, second address information of a request mode and an interface method, a request parameter type and a return result type.
Specifically, the test code generating device respectively acquires url address information of the target control class and the interface method, namely first address information and second address information, through @ RequestMapping notes of the target control class and the interface method in the scan code, and splices the url address information into a complete url address. The test code generating device may further obtain a type of request mode according to a method attribute in the @ request mapping annotation, where the request mode may be one of a GET request and a POST request. Both the GET request and the POST request are used for requesting to acquire data, the GET request only generates one tcp data packet, the requested header file and the data are sent to the server together, the POST request generates two tcp data packets, and the header file and the data are respectively sent to the server. The request mode defines that the url can only request in the request mode to obtain a response.
Specifically, the test code generating device may further obtain a request parameter type and a return result type of the interface method through a parameter attribute and a process attribute in the @ request mapping annotation of the interface method obtained from the code file, analyze the request parameter type into a character string form, and analyze the return result type into an assertion item as key information of the interface method. The test code generating device obtains key information of the interface request through analysis of the original code, and generates request parameters and assertion information corresponding to the key information by default, so that the subsequently generated test code can be directly operated, and the automatic generation efficiency of the interface test code is improved.
Step 13: and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct.
With continued reference to fig. 2, the test code generating device fills all the key information acquired in step 12 into a pre-configured test template, which can be configured by user definition in the IDEA tool to meet different interface test requirements. The test code generating device generates complete interface automation test codes corresponding to the target control class to be tested by using the filled test templates.
Optionally, the test code generating device also obtains comments of the interface method and fills the comments into the test template, so that a user can more clearly know the function of the interface method.
Different from the condition of the prior art, the test code generation method provided by the application is applied to a test code generation device, the test code generation device obtains a to-be-tested item, and the to-be-tested item comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct. Compared with the conventional test code generation method, the method for generating the test code by scanning the control class in the item to be tested to acquire the key information and filling the key information into the test template can acquire the interface information by directly analyzing the code of the item file, the interface information is not acquired by an automatic interface test code generation tool, and the safety of the item content is ensured. The test code generating method generates the interface test code based on the code of the project file, and can flexibly configure the interface test code according to the code content of different project files so as to be suitable for various application situations. The interface test codes automatically generated by the test code generating tool can be directly operated, so that the production and the application are performed, the flow of writing the test codes by a tester and actually putting into test is reduced, and the test efficiency is improved. The test personnel does not write the test code based on the interface document provided by the developer, but directly analyzes the source code to obtain the interface information therein so as to generate the test code, so that the test code which is wrong and is influenced by the test personnel to generate can be avoided when the developer writes the interface document.
The method of the above embodiment may be implemented by using a test code generating device, and is described below with reference to fig. 3, where fig. 3 is a schematic structural diagram of a first embodiment of the test code generating device provided in the present application.
As shown in fig. 3, the test code generating device 30 in the embodiment of the present application includes an acquisition module 31, a scanning module 32, and a code generating module 33.
The obtaining module 31 is configured to obtain an item to be tested, where the item to be tested includes at least one control class.
And the scanning module 32 is configured to scan a target control class in at least one control class, and obtain key information of an interface in the target control class.
The code generating module 33 is configured to fill the key information into a pre-configured test template, and generate a test code corresponding to the target control class in the item to be tested, where the test code is used to test whether the function of the interface in the target control class is correct.
The method of the above embodiment may be implemented by a test code generating device, and referring to fig. 4, fig. 4 is a schematic structural diagram of a second embodiment of the test code generating device provided in the present application, where the test code generating device 40 includes a memory 41 and a processor 42, the memory 41 is used for storing program data, and the processor 42 is used for executing the program data to implement the following method:
acquiring an item to be tested, wherein the item to be tested comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an embodiment of a computer readable storage medium provided in the present application, where the computer readable storage medium 50 stores program data 51, and the program data 51, when executed by a processor, is configured to implement the following method:
acquiring an item to be tested, wherein the item to be tested comprises at least one control class; scanning a target control class in at least one control class to acquire key information of an interface in the target control class; and filling the key information into a pre-configured test template, and generating a test code corresponding to the target control class in the item to be tested, wherein the test code is used for testing whether the function of the interface in the target control class is correct.
Embodiments of the present application are implemented in the form of software functional units and sold or used as a stand-alone product, which may be stored on a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution, in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing description is only of embodiments of the present application, and is not intended to limit the scope of the patent application, and all equivalent structures or equivalent processes using the descriptions and the contents of the present application or other related technical fields are included in the scope of the patent application.

Claims (7)

1. A test code generation method, characterized in that the test code generation method comprises:
acquiring an item to be tested, wherein the item to be tested comprises at least one control class;
scanning a target control class in the at least one control class based on a plug-in provided by an IDEA tool to acquire key information of an interface in the target control class;
filling the key information into a pre-configured test template, and generating a test code corresponding to a target control class in the item to be tested, wherein the test code is used for testing whether the function of an interface in the target control class is correct;
scanning a target control class in the at least one control class to obtain key information of an interface in the target control class, wherein the scanning comprises the following steps:
scanning a target control class in the at least one control class and an interface method in the target control class to obtain a corresponding code annotation;
acquiring key information of the target control class based on the code annotation;
the obtaining key information of the target control class based on the code annotation comprises the following steps:
acquiring first address information and a request mode of the target control class as the key information based on the code annotation of the target control class;
acquiring second address information, request parameter type and return result type of the interface method based on the code annotation of the interface method as the key information;
the obtaining key information of the target control class based on the code annotation further comprises:
respectively acquiring first address information of the target control class and second address information of the interface method based on the @ RequestMapping annotation of the target control class and the interface method;
acquiring the request mode based on a method attribute in the @ RequestMapping annotation of the target control class;
and acquiring the request parameter type and the return result type based on the param attribute and the process attribute in the @ RequestMapping annotation of the interface method.
2. The test code generation method of claim 1, wherein,
the request mode is one of a get request and a post request.
3. The test code generation method of claim 1, wherein,
after the obtaining of the key information of the target control class based on the code annotation, further comprising:
and obtaining the annotation of the interface method and filling the annotation into the template.
4. The test code generation method of claim 1, wherein,
before scanning the target control class in the at least one control class and acquiring the key information of the interface in the target control class, the method further comprises the following steps:
searching all classes in the item to be tested;
judging whether each class in all the classes is a control class or not;
and prompting the information which cannot be analyzed for other classes which are not control classes in all the classes based on the judging result.
5. The test code generation method of claim 1, wherein,
the acquiring the item to be tested comprises the following steps:
acquiring a project file of the project to be tested;
acquiring an operation code of the item to be tested from the item file;
the scanning for a target control class of the at least one control class includes:
and scanning a target control class in the at least one control class based on the running code.
6. A test code generation apparatus, comprising a memory and a processor coupled to the memory;
wherein the memory is for storing program data and the processor is for executing the program data to implement the test code generation method of any one of claims 1 to 5.
7. A computer storage medium for storing program data which, when executed by a computer, is adapted to carry out the test code generation method of any one of claims 1 to 5.
CN202211361205.3A 2022-11-02 2022-11-02 Test code generation method, test code generation device, and storage medium Active CN115470152B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211361205.3A CN115470152B (en) 2022-11-02 2022-11-02 Test code generation method, test code generation device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211361205.3A CN115470152B (en) 2022-11-02 2022-11-02 Test code generation method, test code generation device, and storage medium

Publications (2)

Publication Number Publication Date
CN115470152A CN115470152A (en) 2022-12-13
CN115470152B true CN115470152B (en) 2023-04-28

Family

ID=84336096

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211361205.3A Active CN115470152B (en) 2022-11-02 2022-11-02 Test code generation method, test code generation device, and storage medium

Country Status (1)

Country Link
CN (1) CN115470152B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116680171B (en) * 2023-05-22 2024-03-08 前海飞算云智软件科技(深圳)有限公司 Test method, device, storage medium and electronic equipment

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109189379A (en) * 2018-09-04 2019-01-11 百度在线网络技术(北京)有限公司 code generating method and device
CN112861059A (en) * 2021-03-17 2021-05-28 平安消费金融有限公司 Visual component generation method and device, computer equipment and readable storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060101392A1 (en) * 2004-10-27 2006-05-11 Microsoft Corporation Strongly-typed UI automation model generator
CN106598853A (en) * 2016-12-05 2017-04-26 广州唯品会信息科技有限公司 Method and system for automatically generating test item
CN108255513B (en) * 2017-12-28 2021-03-16 平安科技(深圳)有限公司 Electronic device, springmvc-based data interface, automatic generation method of description of springmvc-based data interface, and storage medium
CN111414194B (en) * 2020-03-19 2023-08-11 政采云有限公司 Interface information generation method, system, electronic equipment and storage medium
CN113760359A (en) * 2020-06-29 2021-12-07 北京沃东天骏信息技术有限公司 Data processing method, device, equipment and computer readable storage medium
CN113778848A (en) * 2021-01-29 2021-12-10 北京沃东天骏信息技术有限公司 Test code generation method, device, computer system and medium
CN114356783A (en) * 2022-01-20 2022-04-15 南方电网数字电网研究院有限公司 Method and device for automatically generating unit test code, storage medium and equipment

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109189379A (en) * 2018-09-04 2019-01-11 百度在线网络技术(北京)有限公司 code generating method and device
CN112861059A (en) * 2021-03-17 2021-05-28 平安消费金融有限公司 Visual component generation method and device, computer equipment and readable storage medium

Also Published As

Publication number Publication date
CN115470152A (en) 2022-12-13

Similar Documents

Publication Publication Date Title
US10642721B2 (en) Generation of automated testing scripts by converting manual test cases
CN111061526B (en) Automatic test method, device, computer equipment and storage medium
US8745641B1 (en) Automatic verification and anomaly detection in a representational state transfer (REST) application programming interface
CN111930635A (en) Swagger-based rapid automatic testing method and system
CN108628748B (en) Automatic test management method and automatic test management system
US11449414B2 (en) Mapping test parameter data elements during heterogeneous component-based testing in a portable automation framework in both API mode and UI mode
CN115470152B (en) Test code generation method, test code generation device, and storage medium
KR102226463B1 (en) UI/UX solution providing server linked with process automation program, process automation method using the same, and computer program executing the same
US20190129832A1 (en) System and method for test data generation for use in model based testing using source code test annotations and constraint solving
US20070092069A1 (en) Method and system for testing enterprise applications
CN111124937B (en) Method and system for assisting in improving test case generation efficiency based on instrumentation function
CN113836014A (en) Interface testing method and device, electronic equipment and storage medium
US11269712B1 (en) Customized categorial error handling framework for heterogeneous component-based testing in a portable automation framework
CN112367220A (en) Interface testing method and device, storage medium and electronic equipment
CN107797917B (en) Performance test script generation method and device
CN112433929A (en) Webpage debugging method and device, computer equipment and storage medium
US11734134B2 (en) Automatically locating resources using alternative locator expressions during heterogeneous component-based testing in a portable automation framework
CN115599361A (en) Software development method, device, equipment and medium
CN113094281B (en) Test method and device for hybrid App
US11310680B2 (en) Reusing provisioned resources during heterogeneous component-based testing in a portable automation framework
CN111813396B (en) Script editing method and device, computer equipment and readable storage medium
CN112799956B (en) Asset identification capability test method, device and system device
JP5683209B2 (en) Client computer with automatic document generation function
CN113094281A (en) Hybrid App testing method and device
CN115509923A (en) Unit test case generation method and device and computer storage medium

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