CN112905458A - Interface automation contract testing method and device - Google Patents

Interface automation contract testing method and device Download PDF

Info

Publication number
CN112905458A
CN112905458A CN202110170928.4A CN202110170928A CN112905458A CN 112905458 A CN112905458 A CN 112905458A CN 202110170928 A CN202110170928 A CN 202110170928A CN 112905458 A CN112905458 A CN 112905458A
Authority
CN
China
Prior art keywords
contract
interface
service
request
test
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110170928.4A
Other languages
Chinese (zh)
Other versions
CN112905458B (en
Inventor
韩靖
暨光耀
张洁芳
林秋玲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202110170928.4A priority Critical patent/CN112905458B/en
Publication of CN112905458A publication Critical patent/CN112905458A/en
Application granted granted Critical
Publication of CN112905458B publication Critical patent/CN112905458B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

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

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)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention relates to a computer technology, in particular to an interface automation contract testing method and a testing device, wherein the testing method comprises the following steps: analyzing the contract text according to a preset contract text format to obtain interface data; determining the IP of a service provider to establish connection and a port corresponding to a locally subscribed service according to the full class name of the tested interface in the interface data; establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request; receiving return information sent by a service provider aiming at the test request; and performing contract testing according to the test request and the return information. The invention solves the problems that the DUBBO service interface is lack of contract testing framework support and is difficult to develop, and provides the DUBBO service contract testing method which is simple to realize and low in implementation cost.

Description

Interface automation contract testing method and device
Technical Field
The invention relates to a computer technology, in particular to an automatic contract testing method and device for a DUBBO interface.
Background
Under the micro-service architecture system, the services are mutually dependent through API calling. The contract test is an action: and generating a file containing input data and expected return data from the perspective of an interface consumer, namely a contract file, inputting the input data in the file by an interface provider according to the contract to obtain a return value, comparing the return value with expected output, and completing a test for verifying the communication accuracy of the two parties. The contract file is used as a carrier for interface information change, and the contract test ensures that the influence of the modification of an interface provider or a consumer on the other side can be sensed.
Dubbo is a high-performance, lightweight Java RPC framework from an open source of Alibara, one of the core capabilities being the invocation of interface-oriented methods. Based on this, the framework can abstract two roles, service Provider (Provider) and service Consumer (Consumer). When the service provider is started, registering and issuing service to the registration center, and waiting for consumption; when the service consumer starts, the service consumer registers service consumption to the registration center, after the IP port of the provider registered on the service consumer is obtained, long connection is established with the address of the provider, request data is further sent to the address, return data is obtained, and calling of a service interface is completed.
And the validity and correctness of the call between the Dubbo consumer and the provider interface need contract test guarantee. In the use process of the existing Dubbo framework, if a certain service needs to be called, the call or the test can be carried out only by explicitly registering in a consumer xml configuration file and instantiating an object of the interface locally, so that the indiscriminate call of different Dubbo interfaces cannot be carried out, and the flexible playback of a contract file cannot be realized to carry out the contract test.
Disclosure of Invention
The invention relates to a computer technology, in particular to an interface automatic contract testing method with simple realization and low implementation cost, which comprises the following steps:
analyzing the contract text according to a preset contract text format to obtain interface data;
determining the IP of a service provider to establish connection and a port corresponding to a locally subscribed service according to the full class name of the tested interface in the interface data;
establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request;
receiving return information sent by a service provider aiming at the test request;
and performing contract testing according to the test request and the return information.
In an embodiment, the analyzing the contract text according to the preset contract text format to obtain the interface data includes:
and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters.
In an embodiment, determining an IP of a service provider to establish a connection and a port corresponding to a locally subscribed service according to a full class name of a tested interface in the interface data includes:
traversing all child nodes under the dubbo node of the registry which issues the service to obtain a target node matched with the full class name of the tested interface;
and acquiring the IP of the service provider and a port corresponding to the service from the service node under the target node.
In one embodiment, the test request comprises: request ID and actual output value; the return information includes: a response ID and a return value;
and performing contract testing according to the test request and the return information, wherein the contract testing comprises the following steps:
matching the request ID corresponding to the response ID;
updating the actual output value of the test request corresponding to the matched request ID by using the return value;
judging whether the updated actual output value is consistent with the expected output value in the interface data;
if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
The invention also provides an interface automatic contract testing device, which comprises:
the analysis module is used for analyzing the contract text according to a preset contract text format to obtain interface data;
the port determining module is used for determining the IP of a service provider to establish connection and a port corresponding to a locally subscribed service according to the full class name of the tested interface in the interface data;
the connection establishing module is used for establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request;
the information receiving module is used for receiving return information sent by the service provider aiming at the test request;
and the test module is used for carrying out contract test according to the test request and the return information.
In an embodiment, the parsing module is specifically configured to:
and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters.
In one embodiment, the port determination module comprises:
the node matching unit is used for traversing all sub-nodes under the dubbo node of the registration center which issues the service to obtain a target node matched with the full class name of the tested interface;
and the information acquisition unit is used for acquiring the IP of the service provider and the port corresponding to the service from the service node under the target node.
In one embodiment, the test request comprises: request ID and actual output value; the return information includes: a response ID and a return value;
the test module includes:
the information matching unit is used for matching the request ID corresponding to the response ID;
the data updating unit is used for updating the actual output value of the matched test request corresponding to the request ID by using the return value;
a result judging unit, configured to judge whether the updated actual output value is consistent with an expected output value in the interface data; if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
The contract test method defines a contract text format of the DUBBO contract test, and invents a DUBBO contract test mode developed based on the format; finding out the IP and the port where the called service is located by traversing the nodes of the registration center, and directly initiating access; the DUBBO bottom layer calling principle is simulated, the IP and the port of the service are connected, the message which accords with the DUBBO coding and decoding rule is directly sent and received, the uniform method is realized to carry out undifferentiated calling on the service, the limitation that a DUBBO framework needs to manually add consumer configuration and instantiates a specific called service object to complete calling is overcome, and the DUBBO contract testing is possible.
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, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a step diagram of an interface automation contract testing method provided by the present invention.
FIG. 2 is a flow chart of the DUBBO architecture.
Fig. 3 is a structural diagram of an interface automation contract testing apparatus provided by the present invention.
Fig. 4 is a structural diagram of another interface automation contract testing apparatus provided by the present invention.
Fig. 5 is a structural diagram of another interface automation contract testing apparatus provided by the present invention.
Fig. 6 is a structural diagram of another interface automation contract testing apparatus provided by the present invention.
Fig. 7 is a schematic structural diagram of an electronic device according to the present invention.
Detailed Description
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 only a part of the embodiments of the present invention, and not all of the embodiments. 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.
As shown in fig. 1, the method for testing an automated contract of a DUBBO interface provided by the present invention includes:
and step S102, analyzing the contract text according to a preset contract text format to obtain interface data. Before step S102, step S101 may be further included: and setting a contract text format, wherein the contract text format comprises interface data parameters required by the contract test.
The Interface data parameters in the preset contract text format include a full class name Interface, a Method name, a Version number Version, Input data in json format, and expected Output in json format of the Interface to be tested, for example, as follows:
Interface=com.fizzbuzz.test.service.FizzBuzz
Method=calculate
Version=1.0.1
Input=[{“java.lang.Integer”:“15”}]
Output=fizzbuzz
and step S104, determining the IP of the service provider to establish the connection and the port corresponding to the locally subscribed service according to the tested interface full class name in the interface data.
Referring to fig. 2, the DUBBO architecture can abstract two roles of a service Provider (Provider) and a service Consumer (Consumer), as well as a Registry (Registry), a monitoring center (Monitor) that counts the number of service calls and call time. The service provider issues the services provided by the service provider to the registry, and the service consumer subscribes the required services to the registry. The specific calling process comprises the following steps: when the service provider is started, registering the service provided by the service provider to a registration center; when the service consumer starts, the service consumer subscribes the service required by the service consumer to the registration center; the registry returns a list of addresses of the service providers to the consumer.
And step S106, establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request. The test request comprises interface data such as a tested interface full-class name, a method name, an interface version number, input parameters, expected output values and the like obtained by analyzing the contract text.
Specifically, the method for generating the test request includes: firstly, packaging a Contract class which comprises attributes of requestId, interface, method, version, inputParams, expectedOutput and actualOutput, and checking the expectedOutput and the actualOutput by using an issatified method. And then reading the contract text, and analyzing key-value of the contract text according to interface data parameters set based on the format of the contract text to obtain interface data such as the full-class name, the method name, the interface version number, the input parameters, the expected output value and the like of the tested interface. These data correspond to the attributes interface, method, version, inputParams, expectedOutput of the Contract class one by one, respectively. The parsing module 411 generates a track object based on the track class and the interface data, and since the interface data does not include interface data corresponding to the attributes requestId and actualOutput, the attributes requestId and actualOutput in the track object are null at the time of initialization. And after a Request object is subsequently generated, the Request ID is registered, and after the calling is finished, the actual return value actualOutput is registered.
Then generating a test request according to the interface data, specifically creating a com.alibaba.dubbo.remoting.exchange.request object according to a Contract object, and specifically comprising the following steps:
(1) initializing Map object interfaceMap according to the interface and version attributes of the Contract object, for example, as follows:
//eg:com.fizzbuzz.test.service.FizzBuzz
interfaceMap.put(“path”,contract.getInterface());
interfaceMap.put(“version”,contract.getVersion());//eg:1.0.1
(2) initializing Class <? The para [ objects ] paramTypes and Object [ objects paramValues, for example, are as follows:
Figure BDA0002938897050000051
Figure BDA0002938897050000061
(3) the RpcInvitation object rpcInvitation is initialized with the method attribute of the Contract object, the interfaceMap, the paramTypes, and the paramValues objects, as follows:
RpcInvocationrpcInvocation=new RpcInvocation(contract.getMethod(),paramTypes,
paramValues,interfaceMap);
(4) request object request is created with rpcvinvocation, along.
Request request=new Request();
request.setTwoWay(true);
request.setData(rpcInvocation);
(5) The request id field of a track object registers the id attribute of the request object and adds the track object to the track.
contract.setID(req.getId());
Contract.contracts.add(contract);
Step S108, receiving the return information sent by the service provider aiming at the test request;
and step S110, carrying out contract testing according to the test request and the return information.
The execution subject of the interface automation contract testing method shown in fig. 1 is a service consumer, which may be a computer, a mobile terminal, and the like.
As can be seen from the flow shown in fig. 1, the interface automated contract testing method in the above embodiment determines interface data parameters required for the contract test by setting a contract format text, and implements a unified method to make indiscriminate calls to services based on a DUBBO contract testing mode developed by the format, thereby overcoming the limitation that a DUBBO framework needs to add consumer configuration manually, instantiates a specific called service object to complete calls, and making the DUBBO contract test possible.
In an embodiment, step S102 specifically includes: and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters. In this step, the contract text needs to be read first, and key value analysis is performed on the contract text based on the interface data parameters set in the format of the contract text to obtain data corresponding to the interface data parameters, that is, interface data. The interface data at least includes: the method comprises the following steps of a tested interface full-class name, a method name, an interface version number, input parameters and an expected output value.
In an embodiment, step S104 may specifically include: traversing all child nodes under the dubbo node of the registry which issues the service to obtain a target node matched with the full class name of the tested interface; and acquiring the IP of the service provider and a port corresponding to the service from the service node under the target node.
The service consumer is connected with a registry where a service provider issues the locally subscribed service, and traverses all child nodes under the registry dubbo node to obtain a target node matched with the full class name of the tested interface; and reading the content of the service node under the target node, acquiring the IP of the service provider and the port corresponding to the service, and calling an address list of the service provider. The address list includes information such as IP, port, interface name, and method name.
In one embodiment, the test requests in steps S106 to S110 further include a request ID and an actual output value; the return information comprises a response ID and a return value; the contract testing according to the test request and the return information specifically comprises the following steps:
matching the request ID corresponding to the response ID;
updating the actual output value of the test request corresponding to the matched request ID by using the return value;
judging whether the updated actual output value is consistent with the expected output value in the interface data;
if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
In step S106, the service consumer establishes a connection with the service provider based on the IP of the service provider determined in step S104 of the foregoing embodiment and the port corresponding to the service, and sends a test request. The test request comprises a request ID and an actual output value besides a tested interface full-class name, a method name, an interface version number, an input parameter and an expected output value which are obtained by analyzing the contract text. When the test request is sent, the actual output value is null, and the update is carried out after the return information of the service provider is received in sequence.
Specifically, in order to establish a connection with a service provider, an org.jboss.netty.bootstrap.clientboottrap object clientboottrap needs to be created and initialized first. The method comprises the following specific steps:
(1) create org.jboss.netty.channel.socket.nio.nio.clientsocketchannelfactory object channelFactory, for example as follows:
ChannelFactorychannelFactory=new
NioClientSocketChannelFactory(Executors.newCachedThreadPool(newNamedThreadFactory("NettyClientBoss",true)),
Executors.newCachedThreadPool(new NamedThreadFactory("NettyClientWorker",true)),Constants.DEFAULT_IO_THREADS);
(2) create org.jboss.net.bootstrap.ClientBootstrap object with channel factory object, and set option, where keepAlive, tcpNoDelay are true, and connectittioutMillis default timeout. Examples are as follows:
ClientBootstrap bootstrap=new ClientBootstrap(channelFactory);
bootstrap.setOption("keepAlive",true);
bootstrap.setOption("tcpNoDelay",true);
bootstrap.setOption("connectTimeoutMillis",Constants.DEFAULT_TIMEOUT);
(3) the method includes the steps that the PipelineFactory attribute of a channelFactory object is set to be an implementation class of a channelPipelineFactory interface, a getPipeline method is achieved, a decoder and an encoder are specified to be a coder-decoder which accords with a coding rule of a dubbo protocol, and a handler is a customized com. Examples are as follows:
Figure BDA0002938897050000081
after creating and initializing org, blog, bootstrap, clientboottrap object bootstrap, the contract execution module can establish connection with the service provider. Specifically, a bootstrap is used to connect an IP and a port where a service provider is located, that is, a url transmitted by the contract preprocessing module 41, and an org. Examples are as follows:
ChannelFuture future=bootstrap.connect(new
InetSocketAddress(NetUtils.filterLocalHost(url.getHost()),url.getPort()));
Channel channel=future.getChannel();
and then sending a test request through the established connection channel, specifically: send a Dubbo Request to the service provider with the channel and wait for a period of time to receive the return information. Examples are as follows:
channel future (message); // message is request
future.await(Constants.DEFAULT_TIMEOUT);
In step S108, the service provider sends a return message to the test request sent by the service consumer, and the service consumer parses the return message to obtain the response ID and a return value.
In step S110, the service consumer identifies the response ID in the return information, matches the request ID of the test request for which the return information is intended, and updates the actual output value in the test request corresponding to the request ID with the return value in the return information; and comparing and judging whether the updated actual output value is consistent with the expected output value. If the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
Specifically, the MyHandler is customized, a com.alibaba.dubbo.remoting.ChannelHandler interface is realized, wherein a received method is called after receiving calling return information, corresponding Contract is positioned by matching the requestId and the responseId to be consistent, and the actual return value of Contract is updated. Examples are as follows:
Figure BDA0002938897050000091
it can be understood that, when receiving a test request, a service provider may generate a unique corresponding return ID according to the request ID of the test request, where the return ID may be a ciphertext obtained by encrypting the request ID, and when receiving the return information, a service consumer identifies and decrypts the return ID, so as to obtain the unique corresponding request ID; the return ID can also contain identification information which is the same as the request ID of the test request, and the service consumer can match the unique corresponding request ID through the identification information; the return ID may also be the same as the request ID. In short, it is sufficient if a unique request ID can be matched from the return ID.
The invention provides an automatic contract testing method of a DUBBO interface, which is a DUBBO service contract testing method with simple realization and low implementation cost, and solves the problems that the DUBBO service interface is lack of contract testing framework support and is difficult to develop. The contract test method defines the contract text format of the DUBBO contract test, invents the DUBBO contract test mode developed based on the format, realizes the undifferentiated call of the service by a unified method, overcomes the limitation that a DUBBO framework needs to manually add consumer configuration and instantiates a specific called service object to complete the call, and enables the DUBBO contract test to be possible.
Based on the same inventive concept, the embodiment of the present application further provides an interface automation contract testing apparatus, which can be used to implement the method described in the above embodiment, as described in the following embodiments. Because the principle of the interface automation contract testing device for solving the problems is similar to the interface automation contract testing method, the implementation of the interface automation contract testing device can refer to the implementation of the interface automation contract testing method, and repeated parts are not described again. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. While the system described in the embodiments below is preferably implemented in software, implementations in hardware, or a combination of software and hardware are also possible and contemplated.
The present invention also provides an interface automation contract testing apparatus, as shown in fig. 3, the system includes:
and the analysis module 31 is configured to analyze the contract text according to a preset contract text format to obtain interface data.
And the port determining module 32 is configured to determine, according to the full class name of the tested interface in the interface data, an IP of the service provider to establish the connection and a port corresponding to the locally subscribed service.
And a connection establishing module 33, configured to establish a connection with the service provider according to the IP and the port corresponding to the service, and send a test request.
And the information receiving module 34 is configured to receive return information sent by the service provider for the test request. The specific steps are as follows: after the connection establishing module 33 sends the test request through the established connection channel, the information receiving module 34 waits for a period of time to receive the return information.
And the test module 35 is configured to perform contract test according to the test request and the return information.
In an embodiment, the parsing module 31 is specifically configured to:
and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters.
In an embodiment, as shown in fig. 4, the port determining module 32 is specifically configured to determine an IP of a service provider to establish a connection and a port corresponding to a service subscribed by a service consumer, where the port determining module 32 includes:
the node matching unit 321 is configured to subscribe a service required by the node matching unit to the registry, specifically, connect a zookeeper registered by the service, traverse all child nodes under a dubbo node in the zookeeper, and each child node corresponds to a service name; matching a target node corresponding to the subscribed service according to the full class name Interface of the tested Interface;
an information obtaining unit 322, configured to read content of a provider node, which is a service node under the target node, obtain an IP of a service provider and a port corresponding to the service from the content, and call an address list of the service provider, that is, a url packet. An example of the address list of the service provider may refer to fig. 3, among others.
It should be noted here that the order of generating the test request and obtaining the IP of the service provider and the port corresponding to the locally subscribed service may be changed, that is, the test request may be generated first, and then the IP and the port of the service provider may be obtained, or the IP and the port of the service provider may be obtained first, and then the test request is generated, which is not limited in this application.
The test Request corresponds to the Request object in this example, and the IP of the service provider and the port corresponding to the service correspond to the address list of the service provider in this example, that is, the url packet.
In one embodiment, as shown in fig. 5 and 6, the test module 35 includes:
an information matching unit 351, configured to match the request ID corresponding to the response ID.
And a data updating unit 352, configured to update the actual output value of the test request corresponding to the matched request ID with the return value.
It can be understood that, when receiving a test request, a service provider may generate a unique corresponding return ID according to the request ID of the test request, where the return ID may be a ciphertext obtained by encrypting the request ID, and when receiving the return information, a service consumer identifies and decrypts the return ID, so as to obtain the unique corresponding request ID; the return ID can also contain identification information which is the same as the request ID of the test request, and the service consumer can match the unique corresponding request ID through the identification information; the return ID may also be the same as the request ID. In short, it is sufficient if a unique request ID can be matched from the return ID.
A result judging unit 353, configured to judge whether the updated actual output value is consistent with an expected output value in the interface data; if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
Specifically, the result determining unit 353 compares and determines whether the expectedOutput and the actualoutput in the updated content object are consistent, and if so, the Contract test is passed, otherwise, the Contract test is not passed.
The invention solves the problems that the DUBBO service interface is lack of contract testing framework support and is difficult to develop, and provides the DUBBO service contract testing device which is simple to realize and low in implementation cost. The contract testing device can realize the contract text format for defining the DUBBO contract test and the function of the DUBBO contract test developed based on the format; finding out the IP and the port where the called service is located by traversing the nodes of the registration center, and directly initiating access; the DUBBO bottom layer calling principle is simulated, the IP and the port of the service are connected, the message which accords with the DUBBO coding and decoding rule is directly sent and received, the uniform method is realized to carry out undifferentiated calling on the service, the limitation that a DUBBO framework needs to manually add consumer configuration and instantiates a specific called service object to complete calling is overcome, and the DUBBO contract testing is possible.
An embodiment of the present application further provides a specific implementation of an electronic device including the interface automation contract testing apparatus in the foregoing embodiment, referring to fig. 7, where the electronic device 700 specifically includes:
a central processing unit (processor)710, a memory 720, a communication module (Communications)730, an input unit 740, an output unit 750, and a power supply 760.
The memory (memory)720, the communication module (Communications)730, the input unit 740, the output unit 750 and the power source 760 are respectively connected to the central processing unit (processor) 710. The central processing unit 710 may call the computer program stored in the memory 720, and the central processing unit 710, when executing the computer program, implements all the steps of the interface automation contract testing method in the above embodiments.
Embodiments of the present application also provide a computer storage medium for storing a computer program executable by a processor. The computer program realizes any interface automation contract testing method provided by the invention when being executed by a processor.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein. The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment. In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of an embodiment of the specification.
In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction. The above description is only an example of the embodiments of the present disclosure, and is not intended to limit the embodiments of the present disclosure. Various modifications and variations to the embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of the embodiments of the present specification should be included within the scope defined by the claims of the present specification.

Claims (10)

1. An interface automation contract testing method is characterized by comprising the following steps:
analyzing the contract text according to a preset contract text format to obtain interface data;
determining the IP of a service provider to establish connection and a port corresponding to a locally subscribed service according to the full class name of the tested interface in the interface data;
establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request;
receiving return information sent by a service provider aiming at the test request;
and performing contract testing according to the test request and the return information.
2. The method for automatically testing the contract of the interface according to claim 1, wherein the step of analyzing the contract text according to a preset contract text format to obtain the interface data comprises the steps of:
and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters.
3. The method for testing the interface automation contract according to claim 2, wherein the determining the IP of the service provider to establish the connection and the port corresponding to the locally subscribed service according to the full class name of the tested interface in the interface data comprises:
traversing all child nodes under the dubbo node of the registry which issues the service to obtain a target node matched with the full class name of the tested interface;
and acquiring the IP of the service provider and a port corresponding to the service from the service node under the target node.
4. The interface automation contract testing method of any of claims 2-3, wherein the test request includes: request ID and actual output value; the return information includes: a response ID and a return value;
and performing contract testing according to the test request and the return information, wherein the contract testing comprises the following steps:
matching the request ID corresponding to the response ID;
updating the actual output value of the test request corresponding to the matched request ID by using the return value;
judging whether the updated actual output value is consistent with the expected output value in the interface data;
if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
5. An interface automation contract testing device, characterized by comprising:
the analysis module is used for analyzing the contract text according to a preset contract text format to obtain interface data;
the port determining module is used for determining the IP of a service provider to establish connection and a port corresponding to a locally subscribed service according to the full class name of the tested interface in the interface data;
the connection establishing module is used for establishing connection with the service provider according to the IP and the port corresponding to the service and sending a test request;
the information receiving module is used for receiving return information sent by the service provider aiming at the test request;
and the test module is used for carrying out contract test according to the test request and the return information.
6. The device for testing an interface automation contract according to claim 5, wherein the parsing module is specifically configured to:
and reading a contract text, and performing key value analysis on the contract text according to interface data parameters set based on the format of the contract text to obtain interface data corresponding to the interface data parameters.
7. The interface automation contract testing apparatus of claim 6, wherein the port determination module comprises:
the node matching unit is used for traversing all sub-nodes under the dubbo node of the registration center which issues the service to obtain a target node matched with the full class name of the tested interface;
and the information acquisition unit is used for acquiring the IP of the service provider and the port corresponding to the service from the service node under the target node.
8. The interface automation contract testing apparatus of any of claims 6-7, wherein the test request includes: request ID and actual output value; the return information includes: a response ID and a return value;
the test module includes:
the information matching unit is used for matching the request ID corresponding to the response ID;
the data updating unit is used for updating the actual output value of the matched test request corresponding to the request ID by using the return value;
a result judging unit, configured to judge whether the updated actual output value is consistent with an expected output value in the interface data; if the contract is consistent with the contract, prompting that the contract test is passed; and if not, prompting that the contract test fails.
9. An electronic device, comprising:
the interface automation contract testing method comprises a central processing unit, a storage and a communication module, wherein the central processing unit can call a computer program stored in the storage, and when the central processing unit executes the computer program, the interface automation contract testing method according to any one of claims 1-4 is realized.
10. A computer storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the interface automation contract testing method of any one of claims 1-4.
CN202110170928.4A 2021-02-08 2021-02-08 Interface automatic contract testing method and device Active CN112905458B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110170928.4A CN112905458B (en) 2021-02-08 2021-02-08 Interface automatic contract testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110170928.4A CN112905458B (en) 2021-02-08 2021-02-08 Interface automatic contract testing method and device

Publications (2)

Publication Number Publication Date
CN112905458A true CN112905458A (en) 2021-06-04
CN112905458B CN112905458B (en) 2024-05-07

Family

ID=76123999

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110170928.4A Active CN112905458B (en) 2021-02-08 2021-02-08 Interface automatic contract testing method and device

Country Status (1)

Country Link
CN (1) CN112905458B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103064788A (en) * 2012-12-24 2013-04-24 清华大学 Web service modeling and test method based on interface semantic contract model
CN108694120A (en) * 2017-04-12 2018-10-23 北京京东尚科信息技术有限公司 The method and apparatus of testing service component
CN110764996A (en) * 2019-09-06 2020-02-07 平安普惠企业管理有限公司 Contract testing method, system, storage medium and terminal equipment
CN110888800A (en) * 2019-10-18 2020-03-17 平安普惠企业管理有限公司 Service interaction function test method, device, storage medium and test system
CN111159025A (en) * 2019-12-23 2020-05-15 武汉联影医疗科技有限公司 Application program interface testing method and device, computer equipment and storage medium
CN111459801A (en) * 2020-03-09 2020-07-28 江苏苏宁物流有限公司 RSF remote service interface function test method, module, computer equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103064788A (en) * 2012-12-24 2013-04-24 清华大学 Web service modeling and test method based on interface semantic contract model
CN108694120A (en) * 2017-04-12 2018-10-23 北京京东尚科信息技术有限公司 The method and apparatus of testing service component
CN110764996A (en) * 2019-09-06 2020-02-07 平安普惠企业管理有限公司 Contract testing method, system, storage medium and terminal equipment
CN110888800A (en) * 2019-10-18 2020-03-17 平安普惠企业管理有限公司 Service interaction function test method, device, storage medium and test system
CN111159025A (en) * 2019-12-23 2020-05-15 武汉联影医疗科技有限公司 Application program interface testing method and device, computer equipment and storage medium
CN111459801A (en) * 2020-03-09 2020-07-28 江苏苏宁物流有限公司 RSF remote service interface function test method, module, computer equipment and storage medium

Also Published As

Publication number Publication date
CN112905458B (en) 2024-05-07

Similar Documents

Publication Publication Date Title
US10021549B2 (en) Service layer resource propagation across domains
US8656417B2 (en) Interface for telecommunication services using uniform resource identifiers
JP2007511018A (en) Method and apparatus for composing software
Wu et al. OneM2M-based IoT protocol integration
KR20110093876A (en) Device management server, client and method for locating target operation object
CN108376078A (en) Upgrade method, device and the household appliance of equipment
WO2023142911A1 (en) Service processing method and device
CN112988485A (en) Simulation test method and device for power Internet of things equipment
KR20190061060A (en) Profile-based content and services
CN115114044A (en) Message pushing method, device, equipment and medium
KR100738040B1 (en) Method for providing application Program Interface in open mobile business supporting system
CN111225018A (en) Request message processing method and device and electronic equipment
CN114448719B (en) Message interaction method, device and system
CN113238740A (en) Code generation method, code generation device, storage medium, and electronic apparatus
CN112565439A (en) Internet of things communication method and system
CN111190625A (en) APP version upgrading method, server, client and computer readable storage medium
CN113014626B (en) Data service management method and device, storage medium and electronic device
CN113806216A (en) Interface test method, device, medium and equipment
CN111930625B (en) Log acquisition method, device and system based on cloud service platform
CN111698310B (en) Multi-test environment scheduling method and device based on SWIFT network
CN112905458B (en) Interface automatic contract testing method and device
WO2023029881A1 (en) Device control method and apparatus
CN113709177B (en) Method for processing message and external call gateway
CN107911442B (en) Receiving response interface interaction method and device, computer equipment and storage medium
Zilhão et al. A Modular Tool for Benchmarking loT Publish-Subscribe Middleware

Legal Events

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