Movatterモバイル変換


[0]ホーム

URL:


CN109032920A - A kind of method and device for being tested protocol interface - Google Patents

A kind of method and device for being tested protocol interface
Download PDF

Info

Publication number
CN109032920A
CN109032920ACN201810570582.5ACN201810570582ACN109032920ACN 109032920 ACN109032920 ACN 109032920ACN 201810570582 ACN201810570582 ACN 201810570582ACN 109032920 ACN109032920 ACN 109032920A
Authority
CN
China
Prior art keywords
format
test case
test
interface
testing
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
CN201810570582.5A
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.)
Beijing Qianxin Technology Co Ltd
Original Assignee
Beijing Qianxin Technology 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 Beijing Qianxin Technology Co LtdfiledCriticalBeijing Qianxin Technology Co Ltd
Priority to CN201810570582.5ApriorityCriticalpatent/CN109032920A/en
Publication of CN109032920ApublicationCriticalpatent/CN109032920A/en
Pendinglegal-statusCriticalCurrent

Links

Classifications

Landscapes

Abstract

Embodiment of the invention discloses a kind of method and device for being tested protocol interface, the corresponding data structure information of the interface is converted into the second relatively conventional format after receiving the solicited message tested a certain interface by terminal.The test case tested preset interface can be quickly generated by the second format, the first format for supporting terminal and server-side to communicate test case conversion layer is then converted by format again, sends test case, realizes test function.Since the second format can efficiently generate test case, generating test case by the second format can be realized efficient test, when being tested especially by the test case of batch, can obviously save time cost.

Description

Method and device for testing protocol interface
Technical Field
The embodiment of the invention relates to the technical field of protocol interface testing, in particular to a method and a device for testing a protocol interface.
Background
In the technical field of interface testing, some interfaces support protocols which are special, and in the process of testing the interfaces, the efficiency of a testing process is low because the recognition capability of testing equipment to a format is limited or a worker is not familiar with the format supported by the characteristic protocol. For example, like other RPC systems, a gRPC is a service-based protocol. By default, the gRPC uses protocol buffers as an Interface Definition Language (IDL) to interface a batch of gRPC servers to be tested, but the efficiency of testing the gRPC protocol interfaces is low because the protocol buffers are complex.
In the process of implementing the embodiment of the invention, the inventor finds that the existing method for testing the protocol interface is low in testing efficiency because the format corresponding to the tested protocol interface is complex.
Disclosure of Invention
The technical problem to be solved by the invention is how to solve the problem that the existing method for testing the protocol interface is low in testing efficiency because the format corresponding to the tested protocol interface is complex.
In view of the above technical problem, an embodiment of the present invention provides a method for testing a protocol interface, including:
after request information for testing a preset interface sent by a server is received, acquiring data structure information corresponding to the preset interface from the request information;
converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format;
converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result;
and generating the test case through the second format more efficiently than the first format.
Optionally, the generating, according to the data structure information converted into the second format, a first test case for testing the preset interface in the second format includes:
and generating a plurality of first test cases in the second format for each test item in the data structure information converted into the second format, and separating different first test cases through preset characters.
Optionally, the converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result includes:
and for each first test case read according to the preset characters, converting the first test case from the second format into the first format to obtain a second test case, sending the second test case to the server, receiving the test result returned by the server, and if the received test result is judged to be abnormal, judging that the preset interface is abnormal.
Optionally, the first format is a protocol buffers format, and the second format is a json format.
In a second aspect, the present embodiment provides an apparatus for testing a protocol interface, including:
the acquisition module is used for acquiring data structure information corresponding to a preset interface from request information after receiving the request information for testing the preset interface, which is sent by a server;
the generating module is used for converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format;
the test module is used for converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result;
and generating the test case through the second format more efficiently than the first format.
Optionally, the generating module is further configured to generate, for each test item in the data structure information converted into the second format, a plurality of first test cases in the second format, and separate different first test cases by using preset characters.
Optionally, the test module is further configured to, for each first test case read according to the preset character, convert the first test case from the second format to the first format to obtain a second test case, send the second test case to the server, receive the test result returned by the server, and if it is determined that none of the received test results is abnormal, the preset interface is not abnormal.
Optionally, the first format is a protocol buffers format, and the second format is a json format.
In a third aspect, the present embodiment provides an electronic device, including:
at least one processor, at least one memory, a communication interface, and a bus; wherein,
the processor, the memory and the communication interface complete mutual communication through the bus;
the communication interface is used for information transmission between the electronic equipment and the communication equipment of the server;
the memory stores program instructions executable by the processor, the processor calling the program instructions to perform the method of any of the above.
In a fourth aspect, the present embodiments provide a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform the method of any of the above.
The embodiment of the invention provides a method and a device for testing a protocol interface. And a test case for testing the preset interface can be quickly generated through the second format, and then the test case is sent through the first format for enabling the test case conversion layer to support the communication between the terminal and the server through format conversion, so that the test function is realized. The second format can efficiently generate the test cases, so that efficient testing can be realized by generating the test cases through the second format, and particularly, time and cost can be obviously saved when testing is performed through batch test cases.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flow chart illustrating a method for testing a protocol interface according to an embodiment of the present invention;
fig. 2 is a block diagram of an apparatus for testing a protocol interface according to another embodiment of the present invention;
fig. 3 is a block diagram of an electronic device according to another embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flowchart of a method for testing a protocol interface according to this embodiment, and referring to fig. 1, the method includes:
101: after request information for testing a preset interface sent by a server is received, acquiring data structure information corresponding to the preset interface from the request information;
102: converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format;
103: converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result;
and generating the test case through the second format more efficiently than the first format.
The method provided by the embodiment is executed by a testing device (for example, a computer, a mobile phone or a special testing device). The server is a platform for providing a certain service. Generally, a protocol supported by the terminal and the server for communication is complex, and therefore, it is inefficient to generate the test case directly according to a format supported by the protocol. In order to solve the problem, in this embodiment, after receiving request information for testing a preset interface, a terminal converts data structure information corresponding to the interface into a format that is simpler or more familiar to a worker, and then generates a test case, and when the test case is used for testing, the format of the test case is converted, so that the generation efficiency of the test case is improved, and the test efficiency is further improved.
The service end is preset with a test logic for testing a certain service, so that the service end can send request information for testing an interface of the certain service to the terminal according to the test logic. And when the terminal receives the request information, acquiring the data structure information corresponding to the interface from the request information. For example, the interface is used for processing a character representing an animal or an interface for processing a character representing a sex of a person. The second format is generally a more common format than the first format, for example, the first format is a protocol buffers format (pb format), and the second format is a json format, and the test case can be generated more efficiently through the second format. The conversion between the first format and the second format may be implemented by format conversion software, which is not particularly limited in this embodiment. For example, software for realizing the mutual conversion between pb format and json format (a Parse method of protocol buffers is called to convert json into pb format).
In this embodiment, after receiving request information for testing a certain interface, a terminal converts data structure information corresponding to the interface into a second format that is relatively common. And a test case for testing the preset interface can be quickly generated through the second format, and then the test case is sent through the first format for enabling the test case conversion layer to support the communication between the terminal and the server through format conversion, so that the test function is realized. The second format can efficiently generate the test cases, so that efficient testing can be realized by generating the test cases through the second format, and particularly, time and cost can be obviously saved when testing is performed through batch test cases.
Further, on the basis of the foregoing embodiment, the generating, according to the data structure information converted into the second format, the first test case for testing the preset interface in the second format includes:
and generating a plurality of first test cases in the second format for each test item in the data structure information converted into the second format, and separating different first test cases through preset characters.
The preset character may be a delimiter "|", which is not particularly limited in this embodiment. For example, if two test items, i.e., name and gender, are included in the certain data structure information, a plurality of first test cases are generated for the name (for example, the test cases are "zhang" and "123" sent), and a plurality of first test cases are also generated for the gender (for example, the test cases are "male" sent, "female" sent, and "cat" sent), and these test cases are separated by a predetermined character.
The embodiment provides a method for testing a protocol interface, which separates test cases through preset characters when test cases of a certain preset interface are generated in batch, so as to perform format conversion on each test case according to the preset characters.
Further, on the basis of the foregoing embodiment, the converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result includes:
and for each first test case read according to the preset characters, converting the first test case from the second format into the first format to obtain a second test case, sending the second test case to the server, receiving the test result returned by the server, and if the received test result is judged to be abnormal, judging that the preset interface is abnormal.
For example, if a plurality of test cases for testing the preset interface are generated in the json format, the first test case in each json format needs to be converted into the second test case in the pb format according to the preset characters. And sending each second test case to the server side, and returning the test result by the server side. For example, the test results are "the name sent" zhang san "is correct, the name sent" 123 "is incorrect," the sex sent "male" is correct, the sex sent "female" is correct, and the sex sent "cat" is incorrect. And because the judgment of each test case in the test result is correct, the preset interface is proved to be abnormal. And if the test result has an abnormal result, the preset interface has an abnormality.
The embodiment provides a method for testing a protocol interface, which tests the interface through a test case and accurately and quickly judges whether the interface is abnormal or not through a test result.
Further, on the basis of the above embodiment, the first format is a protocol buffers format, and the second format is a json format.
As a specific embodiment, this embodiment provides a method for testing hundreds of gRPC service interfaces, including:
(1) after inquiring about official related documents of the gPRC, finding that a json format which is frequently edited and a protocol buffers data format which is defaulted by the gPRC can be mutually converted, editing a test case by using the json format for the protocol buffers data format provided by a server, then calling a Parse method of the protocol buffers to convert json into a pb format, and further accessing the gPRC service.
(2) And editing the batched json files through a commonly used text document according to a protocol buffers data structure provided by the gPC service, so as to realize the batched test cases.
(3) In the test case text, batch test cases of batch services are realized by adding a separator "|", and the readability of the test cases is increased by adding an annotation line through a # number. For example, for the invitation service, the json format test case produced by the invitation service can be written as:
#invitation
#same org
CreateData|{“visitor:{“visitor_staff”:{“oid:19,”“uid”:1122}},”uuid:“3F2504E0-4F89-11D39AOC-0000000000”,“v”:
#not same org
FetchData|{“visitor:{“visitor_staff”:{“oid:19,”“uid”:1122}},”k:“base_version”:“0”,“k_obj”:
(4) by means of python, the batch test cases of the batch interface are realized by analyzing the service and the test cases in the case text (namely, the test cases are converted into json format).
The embodiment provides a method, and when a set of complete system is faced, the gRPC service is many and each service uses many cases, the method provided by any embodiment can be used for realizing protocol buffers data of the service, and according to a test thought, batch cases of batch interfaces can be completed by editing json text test cases, so that the working efficiency is improved, and the time cost is saved.
Fig. 2 shows a block diagram of an apparatus for testing a protocol interface according to an embodiment of the present invention, and referring to fig. 2, the apparatus for testing a protocol interface according to the embodiment includes an obtaining module 201, a generating module 202, and a testing module 203, where,
an obtaining module 201, configured to obtain, after receiving request information for testing a preset interface sent by a server, data structure information corresponding to the preset interface from the request information;
a generating module 202, configured to convert the data structure information from a current first format into a second format, and generate a first test case for testing the preset interface in the second format according to the data structure information converted into the second format;
the test module 203 is configured to convert the first test case into the first format to obtain a second test case, and test the preset interface through the second test case to obtain a test result;
and generating the test case through the second format more efficiently than the first format.
The apparatus for testing a protocol interface provided in this embodiment is suitable for the method for testing a protocol interface provided in the foregoing embodiment, and details are not described here.
The embodiment of the invention provides a device for testing a protocol interface, and a terminal converts data structure information corresponding to an interface into a second format which is more common after receiving request information for testing the interface. And a test case for testing the preset interface can be quickly generated through the second format, and then the test case is sent through the first format for enabling the test case conversion layer to support the communication between the terminal and the server through format conversion, so that the test function is realized. The second format can efficiently generate the test cases, so that efficient testing can be realized by generating the test cases through the second format, and particularly, time and cost can be obviously saved when testing is performed through batch test cases.
Fig. 3 is a block diagram showing the structure of the electronic apparatus provided in the present embodiment.
Referring to fig. 3, the electronic device includes: a processor (processor)301, a memory (memory)302, a communication Interface (Communications Interface)303, and a bus 304;
wherein,
the processor 301, the memory 302 and the communication interface 303 complete mutual communication through the bus 304;
the communication interface 303 is used for information transmission between the electronic device and the communication device of the server;
the processor 301 is configured to call program instructions in the memory 302 to perform the methods provided by the above-mentioned method embodiments, including: after request information for testing a preset interface sent by a server is received, acquiring data structure information corresponding to the preset interface from the request information; converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format; converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result; and generating the test case through the second format more efficiently than the first format.
The present embodiments provide a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform the methods provided by the above method embodiments, for example, including: after request information for testing a preset interface sent by a server is received, acquiring data structure information corresponding to the preset interface from the request information; converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format; converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result; and generating the test case through the second format more efficiently than the first format.
The present embodiments disclose a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the methods provided by the above-described method embodiments, for example, comprising: after request information for testing a preset interface sent by a server is received, acquiring data structure information corresponding to the preset interface from the request information; converting the data structure information from a current first format into a second format, and generating a first test case for testing the preset interface in the second format according to the data structure information converted into the second format; converting the first test case into the first format to obtain a second test case, and testing the preset interface through the second test case to obtain a test result; and generating the test case through the second format more efficiently than the first format.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
The above-described embodiments of the electronic device and the like are merely illustrative, where the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may also be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the embodiments of the present invention, and are not limited thereto; although embodiments of the present invention have been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

CN201810570582.5A2018-06-052018-06-05A kind of method and device for being tested protocol interfacePendingCN109032920A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201810570582.5ACN109032920A (en)2018-06-052018-06-05A kind of method and device for being tested protocol interface

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201810570582.5ACN109032920A (en)2018-06-052018-06-05A kind of method and device for being tested protocol interface

Publications (1)

Publication NumberPublication Date
CN109032920Atrue CN109032920A (en)2018-12-18

Family

ID=64612071

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201810570582.5APendingCN109032920A (en)2018-06-052018-06-05A kind of method and device for being tested protocol interface

Country Status (1)

CountryLink
CN (1)CN109032920A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN110674027A (en)*2019-08-162020-01-10华东师范大学 SDN data plane software conformance testing system and method for P4 programming language
CN111752820A (en)*2019-03-292020-10-09上海哔哩哔哩科技有限公司Pressure testing method of gPC interface, computer equipment and storage medium
CN113360386A (en)*2021-06-172021-09-07锐捷网络股份有限公司Switching chip drive test method, device, electronic equipment and storage medium
CN115426291A (en)*2022-11-032022-12-02浙江正泰仪器仪表有限责任公司Communication protocol detection method, device and system

Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20010052089A1 (en)*2000-04-272001-12-13Microsoft CorporationAutomated testing
CN103605606A (en)*2013-12-012014-02-26北京航空航天大学Embedded software test case batch execution method capable of being automatically convertible
CN104834595A (en)*2015-02-152015-08-12网易(杭州)网络有限公司Visual automatic test method and system
CN106294177A (en)*2016-08-222017-01-04腾讯科技(深圳)有限公司The method for testing pressure of a kind of interface and test equipment
CN107908541A (en)*2017-07-262018-04-13平安壹钱包电子商务有限公司Interface test method, device, computer equipment and storage medium
CN107992421A (en)*2017-12-072018-05-04畅捷通信息技术股份有限公司Interface test method and its device and computer installation and its readable storage medium storing program for executing

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20010052089A1 (en)*2000-04-272001-12-13Microsoft CorporationAutomated testing
CN103605606A (en)*2013-12-012014-02-26北京航空航天大学Embedded software test case batch execution method capable of being automatically convertible
CN104834595A (en)*2015-02-152015-08-12网易(杭州)网络有限公司Visual automatic test method and system
CN106294177A (en)*2016-08-222017-01-04腾讯科技(深圳)有限公司The method for testing pressure of a kind of interface and test equipment
CN107908541A (en)*2017-07-262018-04-13平安壹钱包电子商务有限公司Interface test method, device, computer equipment and storage medium
CN107992421A (en)*2017-12-072018-05-04畅捷通信息技术股份有限公司Interface test method and its device and computer installation and its readable storage medium storing program for executing

Cited By (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111752820A (en)*2019-03-292020-10-09上海哔哩哔哩科技有限公司Pressure testing method of gPC interface, computer equipment and storage medium
CN111752820B (en)*2019-03-292024-01-19上海哔哩哔哩科技有限公司gRPC interface pressure test method, computer equipment and storage medium
CN110674027A (en)*2019-08-162020-01-10华东师范大学 SDN data plane software conformance testing system and method for P4 programming language
CN110674027B (en)*2019-08-162021-07-27华东师范大学 SDN data plane software conformance testing system and method for P4 programming language
CN113360386A (en)*2021-06-172021-09-07锐捷网络股份有限公司Switching chip drive test method, device, electronic equipment and storage medium
CN113360386B (en)*2021-06-172024-06-14锐捷网络股份有限公司Method and device for testing driving of switching chip, electronic equipment and storage medium
CN115426291A (en)*2022-11-032022-12-02浙江正泰仪器仪表有限责任公司Communication protocol detection method, device and system

Similar Documents

PublicationPublication DateTitle
CN107622135B (en)Method and apparatus for displaying information
CN109032920A (en)A kind of method and device for being tested protocol interface
CN108377247B (en)Message pushing method and device
CN108696899B (en)SIP message transmitting and receiving method and transmitting and receiving device
CN112260933B (en)Communication method, communication device, electronic equipment and medium
CN113973139B (en)Message processing method and device
CN111104556A (en)Service processing method and device
CN114513762A (en)Service processing method and device, electronic equipment and computer readable medium
CN113779422B (en)Method and device for realizing relationship chain label, electronic equipment and storage medium
US20200211027A1 (en)Business rules processing framework
CN113326060B (en) Service request processing method, device and system, and service configuration method and device
CN106453582B (en)Asynchronous message pushing method and system
CN113992460B (en)Message sending method, device, electronic equipment and storage medium
CN113824625B (en)Information interaction method and device
CN107330126B (en)Method and apparatus for outputting information
CN114253520A (en)Interface code generation method and device
CN113760714B (en)Software testing method and device
CN110399573A (en) An information processing method, device, device, and computer-readable storage medium
CN103428280A (en)Mobile terminal based mobile service data acquisition method and system
CN111414566B (en)Method and device for pushing information
CN113076256A (en)Pressure testing method and device
CN110830662B (en)Outbound telephone data generation method and device
CN113779018A (en) A data processing method and device
US20190190860A1 (en)Systems and methods for invisible identification of agents participating in on-line communication sessions
CN108667710B (en)Information processing method and device

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
RJ01Rejection of invention patent application after publication

Application publication date:20181218

RJ01Rejection of invention patent application after publication

[8]ページ先頭

©2009-2025 Movatter.jp