CN111930618A - Interface-based testing method and system - Google Patents

Interface-based testing method and system Download PDF

Info

Publication number
CN111930618A
CN111930618A CN202010758103.XA CN202010758103A CN111930618A CN 111930618 A CN111930618 A CN 111930618A CN 202010758103 A CN202010758103 A CN 202010758103A CN 111930618 A CN111930618 A CN 111930618A
Authority
CN
China
Prior art keywords
interface
test
template
parameters
json
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.)
Withdrawn
Application number
CN202010758103.XA
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.)
Yinsheng Payment Service Co Ltd
Original Assignee
Yinsheng Payment Service 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 Yinsheng Payment Service Co Ltd filed Critical Yinsheng Payment Service Co Ltd
Priority to CN202010758103.XA priority Critical patent/CN111930618A/en
Publication of CN111930618A publication Critical patent/CN111930618A/en
Withdrawn legal-status Critical Current

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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The embodiment of the invention provides an interface-based test method, which comprises the following steps: the method comprises the following steps: compiling a template test method according to the interface document; step two: generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method; step three: transferring the modified interface input parameter by calling the corresponding test interface; step four: and acquiring interface output parameters of the interface test based on the modified interface input parameters. According to the embodiment of the invention, the test codes are simplified by replacing the parameters of the interface, the separation of the test data and the test codes is realized, the tester is convenient to concentrate on the design of the test case, the time for compiling the test codes is reduced, and the test efficiency is further improved.

Description

Interface-based testing method and system
Technical Field
The invention relates to the technical field of computer testing, in particular to a testing method and a testing system based on an interface.
Background
The interface test is generally used for interactive development among multiple systems or test of development of an application system with multiple subsystems. The interface test is suitable for the bottom-layer framework system and the central service system which provide services for other systems, and mainly tests the interfaces provided by the systems to the outside to verify the correctness and stability of the interfaces. The interface test is also suitable for a service layer interface in an upper layer system, and the test difficulty is higher the upper layer is.
At present, when an interface is tested, an interface can be tested comprehensively only by a large number of test cases, and when the interface is tested, a test method is generally written by one case, most codes in the test methods are basically the same, and only individual interface parameters are different. This method increases a large amount of test codes, wastes time, has high code coupling, and once we need to modify the test data, the corresponding test codes must be modified, and frequent modification of the test codes may cause other problems and affect the test quality.
Summary of the invention
In order to overcome the defects of the prior art, the invention provides an interface-based test method for solving the problem of low efficiency caused by frequent modification of test codes.
The technical scheme adopted by the invention for solving the technical problems is as follows: an interface-based testing method comprises the following steps:
the method comprises the following steps: compiling a template test method according to the interface document;
step two: generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method;
step three: transferring the modified interface input parameter by calling the corresponding test interface;
step four: and acquiring interface output parameters of the interface test based on the modified interface input parameters.
Preferably, before writing the template testing method according to the interface document, the steps further include:
storing a target document to a svn server or an interface management platform in advance, wherein the target document comprises a Word document or a Markdown document;
and acquiring the interface document from the svn server or the interface management platform.
Specifically, the template test method is written according to an interface document, and the steps include:
defining the name, interface input parameter and interface output parameter of the template test method;
creating the interface entry parameters of the interface test and setting initial values;
calling callmethod method, and transferring path, params, keys, interface class, request method, and interface entry into the parameter.
Specifically, based on the test parameters received and analyzed by the template test method, interface entry parameters of the interface test are generated, and the steps include:
analyzing the interface access parameter params in the template method, and converting the interface access parameter into map for storage;
the key value in the map stores a jsonPath path, and the value stores a jsonPath value.
Specifically, the steps include:
and converting the interface entries in the template method into json by calling a json tool.
Specifically, based on the test parameters received and analyzed by the template test method, interface entry parameters of the interface test are generated, and the steps include:
traversing the map, and modifying the json Path value corresponding to the json into the value corresponding to the key in the map by using the json Path according to the json Path of the key value in the map to obtain a modified new json.
Specifically, based on the test parameters received and analyzed by the template test method, interface entry parameters of the interface test are generated, and the steps include:
and calling a json tool to convert the modified new json into an interface entry.
Specifically, the steps include:
and calling the corresponding interface according to the template test method, and transmitting the modified interface access parameter into the interface access parameter object.
Specifically, the step of calling the corresponding interface includes:
and analyzing the path value in the interface input parameter of the template test method, and calling different protocol interfaces according to the path value.
An interface-based test system, the system comprising:
the compiling unit is used for compiling the template test method according to the interface document;
the generating unit is used for generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method;
the input unit is used for inputting the modified interface input parameters by calling the corresponding test interface;
and the acquisition unit is used for acquiring the interface output parameter of the interface test based on the modified interface input parameter.
The invention has the beneficial effects that: through the access of the replacement interface, the test code is simplified, the separation of the test data and the test code is realized, the tester is convenient to concentrate on the design of the test case, the time for writing the test code is reduced, and the test efficiency is further improved.
Drawings
Fig. 1 is a flow chart diagram of an interface-based testing method.
FIG. 2 is a functional block diagram of an interface-based test system.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The following detailed description of specific implementations of the present invention is provided in conjunction with specific embodiments:
the first embodiment is as follows:
fig. 1 shows an implementation flow of an interface-based testing method provided in the first embodiment of the present invention, and for convenience of description, only the relevant parts related to the first embodiment of the present invention are shown, which are detailed as follows:
in step S101: compiling a template test method according to the interface document;
in the embodiment of the application, the interface document is provided by a developer and is generally stored to the svn server as a word document or a Markdown document or directly stored to the interface management platform.
The interface document generally includes the following: interface class, request method, request address, interface dependency, request parameter and description, response parameter and description, as follows:
Figure BDA0002612248340000031
Figure BDA0002612248340000041
a tester obtains an interface document from an svn server or an interface management platform, and writes a template test method according to the interface document, wherein the template test method mainly comprises interface addresses, interface methods, interface input parameters, interface output parameters and the like.
An example template method is as follows:
// define template method name, enter and exit
public String autWithNameIdCardPhoneBankNoTest(String url,String params,String keys){
Creating entries for interfaces to be tested and setting initial values
RealNameAutParam autParam=new RealNameAutParam();
autParam.setPaygateNo("100000");
autParam.setSendChannelSn("123456");
autParam.setVersion("1.0");
authname ("zhang");
autParam.setIdCard("");
autParam.setBankNo("");
autParam.setPhone("");
v/calling callMethod to process interface input and interface, and obtaining interface output and processing
return callMethod(url,IChannelReal.class,"autWithNameIdCardPhoneBankNo",params,keys,autParam);
}
The method for writing the template comprises the following steps:
defining template test method name, entry and exit
Example (c): public String au WithNameIdCardPheBank NoTest (String path, String params, String keys)
Name of template testing method: autWithNameIdCardPhoneBank NoTest
Template test methods are described in reference to 1: and path, a specific hessian interface address can be transmitted, or a hessian interface configuration file path can be transmitted, or a dubbo interface configuration file path can be transmitted, so that the interface request address can be conveniently analyzed from the parameters.
Template test methods are described in reference to 2: params, formatted as k1: v1# k2: v2# k3: v3 …, facilitates subsequent parsing from this parameter into maps for modifying json.
Template methods are described in reference to fig. 3: keys, in the format k1# k2# k3 …, facilitate subsequent extraction of interface arguments from the arguments.
Creating an interface entry to be tested and setting an initial value:
RealNameAutParam autParam=new RealNameAutParam();
autParam.setPaygateNo("100000");
……
calling a callMethod method, and transmitting path, interface class, request method, params, keys and interface entry into the participant. In the callMethod, interface request address analysis, interface input and reference processing, interface calling, interface output and reference processing and the like are performed.
Preferably, a target document is stored in an svn server or an interface management platform in advance, wherein the target document comprises a Word document or a Markdown document;
and acquiring the interface document from the svn server or the interface management platform.
Specifically, defining the name, interface input parameter and interface output parameter of the template test method;
creating the interface entry parameters of the interface test and setting initial values;
calling callmethod method, and transferring path, params, keys, interface class, request method, and interface entry into the parameter.
In step S102: generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method;
in the embodiment of the present application, the method for receiving and analyzing the template test is referred to as 2: params analyzes the entry in the template method, converts the entry into map for storage, stores the key value in the map as a jsonPath path, and stores the value corresponding to jsonPtah.
For example, the template test method autWithNameIdCardPhoneBank NoTest, in which the params transmission value is name: Li four # idCard:101000000000000000# bankNo:620000000000000000, will be resolved into map, and its key-value key value pair is as follows:
name, value, lie, four
key=$.idCard,value=101000000000000000
key=$.bankNo,value=620000000000000000
And calling a json tool to convert the interface entry objects in the template test method into json, so that the value of any certain attribute in the interface entry objects can be modified conveniently.
For example, the entry of the interface in the template test method autWithNameIdCardPhoneBank NoTest is autParam, and a json tool is used for the entry, and the conversion is as follows:
{ "name": Zhang three "," idCard ":" "," bankNo ":" "," phone ":", "paygateway No": 100000"," sendChannelSn ": 123456", "version": 1.0"} traverse the map, and according to the jsonPath in key value, the value of the json corresponding path is modified to the value corresponding to key in map using json Path
For example, if the pair of key values in the map is key $. name, value $ lie four, and the json path with json value "zhangsan" is also $. name, then using the json path tool will modify json "zhangsan" into "lie four. Finally, the new json modified according to the map is:
{ "name": Liquan "," idCard ": 101000000000000000", "bankNo": 620000000000000000"," phone ":", "paygate No": 100000"," sendChannelSn ": 123456", "version": 1.0"} then invokes a json tool to convert the modified json into an interfaced referenced object
Converting the modified json into an interface entry object by using a json tool, wherein the name, idCard and bankn have been modified into values in params, which is equivalent to the following operation:
RealNameAutParam autParam=new RealNameAutParam();
autParam.setPaygateNo("100000");
autParam.setSendChannelSn("123456");
autParam.setVersion("1.0");
authname ("zhang");
autParam.setIdCard("101000000000000000");
autParam.setBankNo("620000000000000000");
autParam.setPhone("");
specifically, the interface in the template method is analyzed by a parameter params, and is converted into a map for storage; the key value in the map stores a jsonPath path, and the value stores a jsonPath value.
More specifically, the interface entries in the template method are converted into json by calling a json tool.
Further specifically, traversing the map, and modifying the json Path value corresponding to the json to the value corresponding to the key in the map by using the json Path according to the json Path of the key value in the map to obtain a modified new json.
And further specifically, calling a json tool to convert the modified new json into an interface entry.
In step S103: transferring the modified interface input parameter by calling the corresponding test interface;
in the embodiment of the application, according to the content in the template method, the corresponding interface is called, the modified access object is transmitted, the path in the access of the template method is analyzed, and different protocol interfaces are called according to the specific value.
For example, if the incoming value is the hessian interface address, the interface is called in the hessian form and the json-converted entry object is incoming;
for example, if the incoming value is the address of the hessian configuration file, the interface is called in the hessian form, and the json-converted entry object is incoming;
for example, if the incoming value is the dubbo profile address, the interface is called in dubbo form and the json converted to the entry object is incoming.
In step S104: and acquiring interface output parameters of the interface test based on the modified interface input parameters.
In the embodiment of the present application, when the autwithnameidcardphonebank no is called and the biography of the name of the user is "zhangsan", the transaction state tranState in the participating party is 99; when the transmission value of the username is 'Liquad', the trade state tranState in the participator is 00, and after the parameter changing processing, the template method autWithNameIdCardPhoneBank NoTest is transmitted to the participator 2 params: zhang III, template method is introduced in 3 keys: the tranState execution template method can obtain the value of the tranState in the interface output parameters, then whether the value is equal to 99 is judged, and when the value of the tranState is equal to 99, the result is in accordance with the expected result; when the value of tranState is not equal to 99, which indicates that the test case is not in accordance with the expected result, the short message or the mail can be sent to notify the tester that the test case is failed to be executed, and the test case is automatically re-executed, or the data in the interface parameters is extracted to perform other operations, specifically, for example, the test result is stored in a database for statistical analysis, or the data in the interface parameters is used as the parameters of other test cases to perform multi-scenario service test.
Specifically, according to the template test method, the corresponding interface is called, and the modified interface access parameter is transmitted to the interface access parameter object. Further specifically, the path value in the interface input parameter of the template test method is analyzed, and different protocol interfaces are called according to the path value.
It will be understood by those skilled in the art that all or part of the steps in the method for implementing the above embodiments may be implemented by relevant hardware instructed by a program, and the program may be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc.
Example two:
fig. 2 shows a structure of an interface-based test system according to a second embodiment of the present invention, and for convenience of description, only the relevant parts of the second embodiment of the present invention are shown, which are detailed as follows:
a compiling unit 201 for compiling a template test method according to the interface document;
a generating unit 202, configured to generate an interface entry parameter for interface testing based on the test parameter received and analyzed by the template testing method;
the input unit 203 is used for inputting the modified interface input parameter by calling the corresponding test interface;
an obtaining unit 204, configured to obtain an interface parameter of the interface test based on the modified interface parameter.
In the embodiment of the invention, a template test method is compiled according to an interface document, the test method comprises an interface address, an interface method, interface input parameters and interface output parameters, the interface input parameters of the interface test are generated based on the test parameters received and analyzed by the template test method, the modified interface test interface input parameters are transmitted by calling a corresponding test interface, the interface output parameters of the interface test are obtained based on the modified interface input parameters, the test codes are simplified by replacing the input parameters of the interface, the separation of the test data and the test codes is realized, test case design is facilitated for testers, the test code compiling time is reduced, and the test efficiency is further improved. The detailed implementation of each unit can refer to the description of the first embodiment, and is not repeated herein.
Example three:
specifically, the parameter changing principle is realized:
writing test methods, defining test methods into paramepamas (format k1: v1# k2: v2# k3: v3 …); newly building an object obj1 to be participated, and setting an initial value of obj 1; converting the object obj1 into a json string json 1; modifying the json character string json1 according to parmas to generate a new json character string json 2; the newly generated json character string json2 is converted into a parameter entry object obj2 to call an interface to be tested, the interface is transmitted into a parameter obj2, the entry of the interface is replaced, test codes are simplified, separation of test data and the test codes is achieved, testers can conveniently concentrate on test case design, test code compiling time is reduced, and test efficiency is improved.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the embodiments described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation.
Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention. The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. An interface-based test method is characterized by comprising the following steps:
the method comprises the following steps: compiling a template test method according to the interface document;
step two: generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method;
step three: transferring the modified interface input parameter by calling the corresponding test interface;
step four: and acquiring interface output parameters of the interface test based on the modified interface input parameters.
2. The interface-based testing method of claim 1, wherein before writing the template testing method according to the interface document, the steps further comprise:
storing a target document to a svn server or an interface management platform in advance, wherein the target document comprises a Word document or a Markdown document;
and acquiring the interface document from the svn server or the interface management platform.
3. The interface-based testing method of claim 2, wherein the template testing method is written according to the interface document, and the steps comprise:
defining the name, interface input parameter and interface output parameter of the template test method;
creating the interface entry parameters of the interface test and setting initial values;
calling callmethod method, and transferring path, params, keys, interface class, request method, and interface entry into the parameter.
4. The interface-based testing method of claim 3, wherein the interface parameters of the interface test are generated based on the test parameters received and analyzed by the template testing method, and the steps include:
analyzing the interface access parameter params in the template method, and converting the interface access parameter into map for storage;
the key value in the map stores a jsonPath path, and the value stores a jsonPath value.
5. The interface-based testing method of claim 4, wherein the interface parameters of the interface test are generated based on the test parameters received and analyzed by the template testing method, and the steps include:
and converting the interface entries in the template method into json by calling a json tool.
6. The interface-based testing method of claim 5, wherein the interface parameters of the interface test are generated based on the test parameters received and analyzed by the template testing method, and the steps comprise:
traversing the map, and modifying the json Path value corresponding to the json into the value corresponding to the key in the map by using the json Path according to the json Path of the key value in the map to obtain a modified new json.
7. The interface-based testing method of claim 6, wherein the interface parameters of the interface test are generated based on the test parameters received and analyzed by the template testing method, and the steps include:
and calling a json tool to convert the modified new json into an interface entry.
8. The interface-based testing method of claim 7, wherein the modified interface entries are imported by calling the corresponding testing interface, and the steps comprise:
and calling the corresponding interface according to the template test method, and transmitting the modified interface access parameter into the interface access parameter object.
9. The interface-based testing method according to claim 8, wherein the step of calling the corresponding interface comprises:
and analyzing the path value in the interface input parameter of the template test method, and calling different protocol interfaces according to the path value.
10. An interface-based test system, the system comprising:
the compiling unit is used for compiling the template test method according to the interface document;
the generating unit is used for generating interface input parameters of the interface test based on the test parameters received and analyzed by the template test method;
the input unit is used for inputting the modified interface input parameters by calling the corresponding test interface;
and the acquisition unit is used for acquiring the interface output parameter of the interface test based on the modified interface input parameter.
CN202010758103.XA 2020-07-31 2020-07-31 Interface-based testing method and system Withdrawn CN111930618A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010758103.XA CN111930618A (en) 2020-07-31 2020-07-31 Interface-based testing method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010758103.XA CN111930618A (en) 2020-07-31 2020-07-31 Interface-based testing method and system

Publications (1)

Publication Number Publication Date
CN111930618A true CN111930618A (en) 2020-11-13

Family

ID=73314988

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010758103.XA Withdrawn CN111930618A (en) 2020-07-31 2020-07-31 Interface-based testing method and system

Country Status (1)

Country Link
CN (1) CN111930618A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112380142A (en) * 2020-12-11 2021-02-19 上海中通吉网络技术有限公司 Interface document management method and device and test equipment
CN113138811A (en) * 2021-04-23 2021-07-20 上海中通吉网络技术有限公司 JsonPath-based unified service calling method
CN113553519A (en) * 2021-06-23 2021-10-26 深圳平安智汇企业信息管理有限公司 Interface address display method and device, computer equipment and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112380142A (en) * 2020-12-11 2021-02-19 上海中通吉网络技术有限公司 Interface document management method and device and test equipment
CN113138811A (en) * 2021-04-23 2021-07-20 上海中通吉网络技术有限公司 JsonPath-based unified service calling method
CN113553519A (en) * 2021-06-23 2021-10-26 深圳平安智汇企业信息管理有限公司 Interface address display method and device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111930618A (en) Interface-based testing method and system
CN107608889B (en) Method and system for automatically generating test script
US9916224B2 (en) Integrating quality analysis with a code review tool
US8977652B2 (en) Client-side API framework for uniform resource identifier (URI) manipulations
US7698688B2 (en) Method for automating an internationalization test in a multilingual web application
CN112187558B (en) Data verification method and device and electronic equipment
US20150347281A1 (en) Automation testing using descriptive maps
CN109542780B (en) Test method, test device and storage medium for natural language processing application
CN110955409B (en) Method and device for creating resources on cloud platform
CN110716743B (en) Aggregation API development method and system suitable for multiparty collaborative development
CN111767229A (en) Performance test method, device and equipment
CN113778897B (en) Automatic test method, device and equipment for interface and storage medium
CN110689285A (en) Test method, test device, electronic equipment and computer readable storage medium
CN111427796A (en) System testing method and device and electronic equipment
CN114745449B (en) Message processing method and device, storage medium and electronic equipment
CN111367791B (en) Method, device, medium and electronic equipment for generating test case
CN110990275B (en) Page display test method and device for mobile banking
CN113434382A (en) Database performance monitoring method and device, electronic equipment and computer readable medium
CN113609014A (en) Interface field checking method and device, storage medium and electronic equipment
CN111143186A (en) Method and apparatus for application program interface API testing
CN111143221B (en) Test method and device
CN117349188B (en) Test case generation method and device based on large model
CN117472367B (en) Heterogeneous resource intelligent identification and access method, device, equipment and storage medium
CN114979100B (en) Cloud resource inspection method and related device
CN116414688A (en) Interface testing method, device and system suitable for micro-service

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
WW01 Invention patent application withdrawn after publication

Application publication date: 20201113

WW01 Invention patent application withdrawn after publication