[go: up one dir, main page]

CN114020630A - Automatic generation method and system for interface use case - Google Patents

Automatic generation method and system for interface use case Download PDF

Info

Publication number
CN114020630A
CN114020630A CN202111321858.4A CN202111321858A CN114020630A CN 114020630 A CN114020630 A CN 114020630A CN 202111321858 A CN202111321858 A CN 202111321858A CN 114020630 A CN114020630 A CN 114020630A
Authority
CN
China
Prior art keywords
test
parameter
data
interface
rule
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
CN202111321858.4A
Other languages
Chinese (zh)
Inventor
王冈
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Pudong Development Bank Co Ltd
Original Assignee
Shanghai Pudong Development 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 Shanghai Pudong Development Bank Co Ltd filed Critical Shanghai Pudong Development Bank Co Ltd
Priority to CN202111321858.4A priority Critical patent/CN114020630A/en
Publication of CN114020630A publication Critical patent/CN114020630A/en
Pending legal-status Critical Current

Links

Images

Classifications

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

Landscapes

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

Abstract

本发明涉及一种接口用例自动生成方法及系统,所述方法包括以下步骤:S1:对待测试的接口进行解析,获取接口信息,所述的接口信息包括接口地址、参数名称、参数类型;S2:根据接口信息生成请求报文模板,并根据参数类型和参数名称获取测试用例模板;S3:构建标准报文数据,根据标准报文数据中参数的顺序生成每个参数的测试数据,将生成的测试数据输入到测试用例模板中,获取多个测试案例;S4:根据生成的测试案例创建测试任务,对测试案例进行接口测试。与现有技术相比,本发明具有测试场景更真实,避免无效测试案例,提高测试效率和稳定性等优点。

Figure 202111321858

The present invention relates to a method and system for automatically generating an interface use case. The method includes the following steps: S1: parse an interface to be tested, and obtain interface information, where the interface information includes an interface address, parameter name, and parameter type; S2: Generate a request message template according to the interface information, and obtain a test case template according to the parameter type and parameter name; S3: construct standard message data, generate test data for each parameter according to the order of parameters in the standard message data, and use the generated test Data is input into the test case template, and multiple test cases are obtained; S4: Create a test task according to the generated test case, and perform interface testing on the test case. Compared with the prior art, the present invention has the advantages of more realistic test scenarios, avoiding invalid test cases, and improving test efficiency and stability.

Figure 202111321858

Description

Automatic generation method and system for interface use case
Technical Field
The invention relates to the technical field of test case generation, in particular to an automatic interface case generation method and system.
Background
The test case generation method of the prior art scheme adopts the interface parameter document to be obtained according to the obtained interface test case generation instruction; analyzing the interface parameter document, determining an array of each interface based on the interface parameter document, assigning the array to each interface, and loading the array assigned to each interface onto a script to obtain an execution script, wherein the script is created on an interface test tool in advance; and performing interface test on the interface test tool by using the execution script to generate an interface test case. In the prior art, the applied service scenes are limited, the authenticity is poor, repeated and invalid cases are easy to occur, and the test effect is poor.
Disclosure of Invention
The present invention aims to overcome the defects of the prior art and provide a method and a system for automatically generating an interface case.
The purpose of the invention can be realized by the following technical scheme:
an automatic generation method of an interface use case comprises the following steps:
s1: analyzing an interface to be tested to obtain interface information, wherein the interface information comprises an interface address, a parameter name and a parameter type;
s2: generating a request message template according to the interface information, and acquiring a test case template according to the parameter type and the parameter name;
s3: constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into a test case template to obtain a plurality of test cases;
s4: and establishing a test task according to the generated test case, and carrying out interface test on the test case.
Preferably, the interface analysis method in step S1 includes a class method, a plug-in method, and a probe method.
Preferably, the specific step of generating the test data of each parameter includes: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule.
Preferably, the generation rule includes a type logic rule, an expression rule, a value range rule, a fixed value rule, a database selection rule, and a random generation rule.
Preferably, the type logic rule generates corresponding test data according to the type of the parameter and the parameter logic corresponding to the type;
the expression rule generates corresponding test data according to the regular expression corresponding to the parameters;
the value range rule obtains test data of corresponding types according to a parameter appointed range corresponding to the parameters;
the fixed value rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library;
the random generation rule randomly generates test data belonging to the data type according to the data type of the parameter, and the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length.
An automatic interface case generation system comprises an interface analysis module, a template acquisition module, a test case acquisition module and a test module,
the interface analysis module is used for analyzing an interface to be tested to acquire interface information, wherein the interface information comprises an interface address, a parameter name and a parameter type;
the template acquisition module is used for generating a request message template according to the interface information and acquiring a test case template according to the parameter type and the parameter name;
the test case acquisition module is used for constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into a test case template to acquire a plurality of test cases;
the test module is used for creating a test task according to the generated test case and carrying out interface test on the test case.
Preferably, the interface analysis module analyzes the interface in a class method, a plug-in method, and a probe method.
Preferably, the specific steps of the test case acquiring module generating the test data of each parameter include: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule.
Preferably, the generation rule includes a type logic rule, an expression rule, a value range rule, a fixed value rule, a database selection rule, and a random generation rule.
Preferably, the type logic rule generates corresponding test data according to the type of the parameter and the parameter logic corresponding to the type;
the expression rule generates corresponding test data according to the regular expression corresponding to the parameters;
the value range rule obtains test data of corresponding types according to a parameter appointed range corresponding to the parameters;
the fixed value rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library;
the random generation rule randomly generates test data belonging to the data type according to the data type of the parameter, and the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length.
Compared with the prior art, the invention has the following advantages:
(1) the invention can effectively analyze the interface, obtain the request message template and the test case template and obtain the test data corresponding to each parameter based on the customized generation rule to form the test case, can solve part of scenes related to the service according to the rule, is closer to the real scene, and has more accurate test and better test effect;
(2) the case data is acquired based on the generation rule, so that more repeated and invalid cases are prevented, the cases are controlled to be on a reasonable horizontal line, the time cost is reduced during subsequent re-execution, and the efficiency is improved;
(3) the test case can be conveniently and synchronously pushed to the service based on the corresponding test task, bubble verification is rapidly carried out, and long-term stability and availability of the online service are ensured.
Drawings
FIG. 1 is a flow chart of the present invention.
Detailed Description
The invention is described in detail below with reference to the figures and specific embodiments. Note that the following description of the embodiments is merely a substantial example, and the present invention is not intended to be limited to the application or the use thereof, and is not limited to the following embodiments.
Examples
An automatic interface use case generation method is shown in fig. 1, and includes the following steps:
s1: the interface to be tested is analyzed, and interface information is obtained, wherein the interface information comprises an interface address, a parameter name and a parameter type.
The method for analyzing the interface in step S1 includes a class method, a plug-in method, and a probe method.
Specifically, the three modes are as follows:
the class mode is as follows: providing a fixed analysis class, and generating an interface file in a mode of directly executing in a source code;
the plug-in mode: the method can be integrated into a development tool, such as Idea, and executes a command in a plug-in mode to generate an interface file;
the probe mode is as follows: providing a Jar package, starting with an application when the application is started, and directly displaying in a platform in a data acquisition mode;
in this embodiment, bytecode analysis is performed on Java Controller classes, that is, interface implementation classes, to obtain a hierarchical relationship among interface URLs, request manners, parameter names, parameter types, and parameter items, so as to provide basic data for data generation and use case construction.
S2: and generating a request message template according to the interface information, and acquiring a test case template according to the parameter type and the parameter name.
S3: and constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into a test case template to obtain a plurality of test cases.
Specifically, in this embodiment, the specific step of generating the test data of each parameter includes: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule.
The generation rules comprise type logic rules, expression rules, value range rules, fixed value rules, database selection rules and random generation rules.
And confirming the corresponding generation rule according to the name and the type of each parameter, and generating the test data, wherein the generation flow of each rule is as follows.
The type logic rule generates corresponding test data according to the type of the parameter and the parameter logic corresponding to the type, such as String: NULL, special character, normal character, extra-long character; time: wrong year, month, day, non-time type value, current value; int: non-numeric type, overflow, 0; bool: true, false.
And the expression rule generates corresponding test data according to the regular expression corresponding to the parameters.
Configuring a regular expression, generating data according to the regular expression, generating data in accordance with a specific format or range, and configuring a corresponding data generator according to test requirements; the writing rule of the expression is similar to a regular expression, and the [ ] part represents the range { } part represents the quantity, which can be used in combination, for example, as follows:
100, 200 numbers between 100 and 200
[ a-z,0-9] {2,5 }: generating character strings of length 5 to 5 consisting of lower case letters or numbers
[ wait, processing, success, fail ] randomly taking a value from wait, processing, success, fail
15[6,9] [0-9] {8}, generating a mobile phone number beginning with 156 or 159
[ a-Z, A-Z ] {3,5} [1-9] {2} @126.com. cn: generation of an Email consisting of 3 to 5 letters and 2 digits.
The value range rule obtains test data of corresponding types according to parameter appointed ranges corresponding to the parameters, data are generated based on the value ranges appointed in the parameter annotations in the codes, and the test data are generated according to different types of data.
And the fixed value rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library. In this embodiment, the fixed value is, for example, a country, an administrative area, a school name, a school calendar, a driver's license type, or the like; fixed format data such as: mobile phone number, identification card number, license plate, etc.
And the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length. Specifically, the data is randomly generated according to the Java data type, the maximum value and the minimum value of the type are taken, and data is fetched according to a certain step length.
In this embodiment, test data is generated in rounds according to the iteration form, and parameters are selected in each round to generate test data until different types of test case situations are covered.
In an embodiment of the present invention, a method for using the generation rule includes: a. and generating an expression for each parameter item associated data generator or filling data in the interface meta information, so that the requirement of generating personalized data is met, and the generated data is more consistent with a service scene. b. Automatically selecting according to the parameter name; and c, setting the priority of different rules, and automatically adapting according to the priority if the rules conflict.
S4: and establishing a test task according to the generated test case, and carrying out interface test on the test case. Specifically, in this embodiment, a plurality of automation tasks are created according to the generated test cases, the execution sequence of the use cases in the test tasks is arranged, and the automatically generated test use cases are executed in a targeted and ordered manner. Meanwhile, in order to meet the requirements of flexible and distributed execution, the idle state of the execution machine is automatically monitored, a reasonable distribution strategy is carried out, and the use case execution efficiency is improved.
Based on the test task result of the invention, an HTML test report is formed by adopting a fixed template, the returned Json message is analyzed, the code and the message in the message are highlighted, and the part of the corresponding request message in which the data is automatically generated is highlighted, so that the interpretation of the subsequent test report is facilitated.
Based on the same inventive concept, the embodiment of the invention also provides an automatic generation system of the interface use case, and as the principle of solving the problems of the devices is similar to the automatic generation method of the interface use case, the implementation of the method can be referred, and repeated parts are not repeated.
An interface case automatic generation system comprises an interface analysis module, a template acquisition module, a test case acquisition module and a test module, wherein the interface analysis module is used for analyzing an interface to be tested and acquiring interface information, and the interface information comprises an interface address, a parameter name and a parameter type; the template acquisition module is used for generating a request message template according to the interface information and acquiring a test case template according to the parameter type and the parameter name; the test case acquisition module is used for constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into the test case template to acquire a plurality of test cases; the test module is used for creating a test task according to the generated test case and carrying out interface test on the test case.
The interface analysis module analyzes the interface in a class method, a plug-in mode and a probe mode.
The specific steps of the test case acquisition module for generating the test data of each parameter comprise: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule. The generation rules comprise type logic rules, expression rules, value range rules, fixed value rules, database selection rules and random generation rules.
Specifically, the type logic rule generates corresponding test data according to the type of the parameter and the parameter logic corresponding to the type; the expression rule generates corresponding test data according to the regular expression corresponding to the parameters; the value range rule acquires test data of corresponding types according to a parameter appointed range corresponding to the parameters; the fixed value-taking rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library; and the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length.
The above embodiments are merely examples and do not limit the scope of the present invention. These embodiments may be implemented in other various manners, and various omissions, substitutions, and changes may be made without departing from the technical spirit of the present invention.

Claims (10)

1. An automatic generation method of an interface use case is characterized by comprising the following steps:
s1: analyzing an interface to be tested to obtain interface information, wherein the interface information comprises an interface address, a parameter name and a parameter type;
s2: generating a request message template according to the interface information, and acquiring a test case template according to the parameter type and the parameter name;
s3: constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into a test case template to obtain a plurality of test cases;
s4: and establishing a test task according to the generated test case, and carrying out interface test on the test case.
2. The method for automatically generating an interface use case according to claim 1, wherein the analyzing manner of the interface in step S1 includes a class method, a plug-in manner, and a probe manner.
3. The method for automatically generating an interface use case according to claim 1, wherein the specific step of generating the test data of each parameter includes: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule.
4. The method for automatically generating the interface use case according to claim 3, wherein the generation rule includes a type logic rule, an expression rule, a value range rule, a fixed value rule, a database selection rule, and a random generation rule.
5. The method for automatically generating the interface use case according to claim 4, wherein the type logic rule generates the corresponding test data according to the type of the parameter and the parameter logic corresponding to the type;
the expression rule generates corresponding test data according to the regular expression corresponding to the parameters;
the value range rule obtains test data of corresponding types according to a parameter appointed range corresponding to the parameters;
the fixed value rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library;
the random generation rule randomly generates test data belonging to the data type according to the data type of the parameter, and the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length.
6. An automatic interface case generation system is characterized by comprising an interface analysis module, a template acquisition module, a test case acquisition module and a test module,
the interface analysis module is used for analyzing an interface to be tested to acquire interface information, wherein the interface information comprises an interface address, a parameter name and a parameter type;
the template acquisition module is used for generating a request message template according to the interface information and acquiring a test case template according to the parameter type and the parameter name;
the test case acquisition module is used for constructing standard message data, generating test data of each parameter according to the sequence of the parameters in the standard message data, and inputting the generated test data into a test case template to acquire a plurality of test cases;
the test module is used for creating a test task according to the generated test case and carrying out interface test on the test case.
7. The system according to claim 6, wherein the interface analysis module analyzes the interface in a class method, a plug-in method, or a probe method.
8. The system for automatically generating interface use cases according to claim 6, wherein the specific steps of the test case obtaining module generating the test data of each parameter include: and acquiring the name and the type of the parameter, confirming a generation rule corresponding to the parameter, and generating test data of the parameter according to the generation rule.
9. The system for automatically generating an interface use case according to claim 8, wherein the generation rule includes a type logic rule, an expression rule, a value range rule, a fixed value rule, a database selection rule, and a random generation rule.
10. The system for automatically generating interface use cases according to claim 9, wherein the type logic rule generates corresponding test data according to the type to which the parameter belongs and the parameter logic corresponding to the type;
the expression rule generates corresponding test data according to the regular expression corresponding to the parameters;
the value range rule obtains test data of corresponding types according to a parameter appointed range corresponding to the parameters;
the fixed value rule constructs a data generation library, generates data with fixed values and fixed format types, and selects test data corresponding to the parameter types from the data generation library;
the random generation rule randomly generates test data belonging to the data type according to the data type of the parameter, and the test data generated by the random generation rule comprises the maximum value and the minimum value of the data type and a middle value taken according to a preset step length.
CN202111321858.4A 2021-11-09 2021-11-09 Automatic generation method and system for interface use case Pending CN114020630A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111321858.4A CN114020630A (en) 2021-11-09 2021-11-09 Automatic generation method and system for interface use case

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111321858.4A CN114020630A (en) 2021-11-09 2021-11-09 Automatic generation method and system for interface use case

Publications (1)

Publication Number Publication Date
CN114020630A true CN114020630A (en) 2022-02-08

Family

ID=80062775

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111321858.4A Pending CN114020630A (en) 2021-11-09 2021-11-09 Automatic generation method and system for interface use case

Country Status (1)

Country Link
CN (1) CN114020630A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115237814A (en) * 2022-09-20 2022-10-25 北京结慧科技有限公司 Method and system for automatically generating interface test case, storage medium and equipment
CN115914028A (en) * 2022-12-27 2023-04-04 知行汽车科技(苏州)股份有限公司 A network communication test method, device, equipment and readable storage medium
CN116340187A (en) * 2023-05-25 2023-06-27 建信金融科技有限责任公司 Rule engine migration test method and device, electronic equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434396A (en) * 2021-06-22 2021-09-24 中国农业银行股份有限公司 Interface test method, device, equipment, storage medium and program product

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434396A (en) * 2021-06-22 2021-09-24 中国农业银行股份有限公司 Interface test method, device, equipment, storage medium and program product

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115237814A (en) * 2022-09-20 2022-10-25 北京结慧科技有限公司 Method and system for automatically generating interface test case, storage medium and equipment
CN115237814B (en) * 2022-09-20 2022-12-13 北京结慧科技有限公司 Method and system for automatically generating interface test case, storage medium and equipment
CN115914028A (en) * 2022-12-27 2023-04-04 知行汽车科技(苏州)股份有限公司 A network communication test method, device, equipment and readable storage medium
CN116340187A (en) * 2023-05-25 2023-06-27 建信金融科技有限责任公司 Rule engine migration test method and device, electronic equipment and storage medium
CN116340187B (en) * 2023-05-25 2023-08-15 建信金融科技有限责任公司 Rule engine migration test method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN114020630A (en) Automatic generation method and system for interface use case
CN104866599B (en) The production method and system of Visual Report Forms
CN104657140B (en) Code generating method and device
CN110389898A (en) Acquisition method, device, terminal and computer-readable storage medium of test strategy
CN108446221A (en) System detection method, device, computer equipment and storage medium
CN104657274B (en) software interface test method and device
CN109726098A (en) Interface test method, device and computer readable storage medium
CN103631783B (en) A kind of generation method and system of front end page
CN105930274A (en) Automated test method and system
CN111143228B (en) Test code generation method and device based on decision table method
CN111984241B (en) Method, device, equipment and medium for dynamically taking effect of online codes
CN102736915A (en) Automatic program generation device, method, and computer program
CN110928802A (en) Test method, device, equipment and storage medium based on automatic generation of case
CN110597728A (en) Method, device and system for constructing test data
CN105005295A (en) Test system and test method for control logic
CN111158656A (en) Method and device for generating test codes based on fruit tree method
WO2007001108A1 (en) System for providing feature-oriented software product line engineering environment
CN114115890A (en) Microservice development method and system
CN111026670A (en) Test case generation method, test case generation device and storage medium
CN113434542B (en) Data relationship identification method and device, electronic equipment and storage medium
CN109614325B (en) Method and device for determining control attribute, electronic equipment and storage medium
CN113126955A (en) Random data generation method and device, intelligent terminal and storage medium
CN112559343B (en) Test path generation method and related equipment
CN116126291A (en) Quick development method, device, equipment and storage medium based on information management
CN117333002A (en) Business process processing system, method and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination