CN115914053A - MQTT protocol-based interface testing method and device - Google Patents

MQTT protocol-based interface testing method and device Download PDF

Info

Publication number
CN115914053A
CN115914053A CN202211415268.2A CN202211415268A CN115914053A CN 115914053 A CN115914053 A CN 115914053A CN 202211415268 A CN202211415268 A CN 202211415268A CN 115914053 A CN115914053 A CN 115914053A
Authority
CN
China
Prior art keywords
tested
mqtt
test
case
interface
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
CN202211415268.2A
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.)
Shenzhen Miracle Intelligent Network Co Ltd
Original Assignee
Shenzhen Miracle Intelligent Network 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 Shenzhen Miracle Intelligent Network Co Ltd filed Critical Shenzhen Miracle Intelligent Network Co Ltd
Priority to CN202211415268.2A priority Critical patent/CN115914053A/en
Publication of CN115914053A publication Critical patent/CN115914053A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to an interface testing method and device based on an MQTT protocol. The method comprises the following steps: acquiring at least one target test case of an object to be tested; constructing an automatic testing framework based on an MQTT protocol by utilizing a target testing case; publishing messages and subscribing messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by utilizing the content of the published messages; and generating a test report according to the verification result. The invention realizes the automatic interface test based on the MQTT protocol, writes a target test case after converting the object model of the corresponding object to be tested into the Python object, and then constructs the automatic test framework based on the MQTT protocol, thereby being capable of conveniently realizing case arrangement and execution according to the service scene.

Description

MQTT protocol-based interface testing method and device
Technical Field
The present application relates to the field of network communication technologies, and in particular, to an interface testing method and apparatus based on MQTT protocol.
Background
MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol published by IBM in 1999 and based on publish/subscribe (publish/subscribe) mode, and can provide real-time and reliable Message service for connecting remote devices with very few codes and limited bandwidth.
At present, an automatic testing scheme on the market is an interface automatic testing tool (such as postman, meter and the like) based on an HTTP protocol and an automatic testing framework of a UI layer, and because an MQTT adopts a publishing and subscribing mode, the interface automatic testing scheme at the present stage cannot be compatible with the testing of an MQTT server interface, and a mature automatic testing framework based on the MQTT protocol is not provided, so that the development of the automatic testing of the MQTT protocol is difficult.
Disclosure of Invention
Therefore, it is necessary to provide an interface testing method and device based on MQTT protocol to implement an automated testing framework based on MQTT protocol according to a preset target test case, so as to complete testing of MQTT interface.
An interface testing method based on MQTT protocol is applied to a testing end, and comprises the following steps:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by using a target testing case;
publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
In one embodiment, the step of obtaining at least one target test case of the object to be tested includes:
acquiring an object model of an object to be detected;
converting the object model into a Python object through a JSON Schema mode in a Python library;
and writing a target test case by utilizing a Python object, and storing the target test case in a case library.
In one embodiment, the step of building an MQTT protocol-based automated test framework using the target test cases includes:
screening a required target test case from a case library according to the service scene requirement;
and combining and sequencing the screened target test cases by using a preset case engine to form an automatic test frame based on the MQTT protocol.
In one embodiment, before the step of publishing a message and subscribing a message to the MQTT interface of the object to be tested, the method further includes:
and connecting the object to be tested through a Paho library in the Python library to realize communication connection based on the MQTT protocol.
In one embodiment, the step of publishing a message and a subscription message to an MQTT interface of an object to be tested through an automated testing framework, and checking the content of the subscription message by using the content of the published message includes:
generating a test session object according to the automatic test framework;
calling a test session object to publish messages and subscribe messages to an MQTT interface of an object to be tested;
comparing the published message content with the subscribed message content returned by the object to be tested;
and finishing verification on the subscription message by judging whether the corresponding contents are consistent.
In one embodiment, the target test case at least includes: publish topic and message content, subscribe topic, content to be verified, and desired content.
An interface testing device based on MQTT protocol, the device comprises:
the case acquisition module is used for acquiring at least one target test case of the object to be tested;
the framework building module is used for building an automatic testing framework based on the MQTT protocol by using the target test case;
the test execution module is used for publishing messages and subscribing messages to an MQTT interface of the object to be tested through an automatic test framework and verifying the content of the subscribed messages by utilizing the content of the published messages;
and the report generating module is used for generating a test report according to the checking result.
A computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by utilizing a target testing case;
publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by using a target testing case;
publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
The interface testing method, the device, the computer equipment and the storage medium based on the MQTT protocol solve the problems of the automatic interface testing based on the MQTT protocol, the interface automatic case arrangement and the conversion of the 'object model' into the testing automation elements. After the object model of the corresponding object to be tested is converted into a Python object, a target test case is compiled, then an automatic test framework based on the MQTT protocol is constructed, the automatic test of an interface of the MQTT protocol is realized, meanwhile, the automatic test framework can be released from the existing complicated Json operation, and the object model corresponding to the object to be tested can be conveniently operated by depending on a case editor; the use case arrangement can be conveniently realized through the preset use case engine, and the use case arrangement execution can be realized according to the service scene.
Drawings
FIG. 1 is a diagram of an application environment of an interface testing method based on MQTT protocol in one embodiment;
FIG. 2 is a schematic flowchart of an interface testing method based on MQTT protocol in one embodiment;
FIG. 3 is a block diagram of an interface testing device based on MQTT protocol in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application 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 present application and are not intended to limit the present application.
The interface testing method based on the MQTT protocol can be applied to the application environment shown in FIG. 1. The application environment comprises a testing end and at least one object to be tested, and the testing end and the object to be tested adopt an MQTT protocol to publish and subscribe messages. The test end in the application environment can be an independent server or a server cluster formed by a plurality of servers, and the object to be tested can be, but is not limited to, an intelligent box gateway, a personal computer, a notebook computer, a smart phone, a tablet computer and portable wearable equipment.
As shown in fig. 2, an interface testing method based on MQTT protocol is provided, and is described by taking the example that the method is applied to the testing end in fig. 1, and includes the following steps:
step S101, obtaining at least one target test case of an object to be tested;
s102, constructing an automatic testing framework based on an MQTT protocol by using a target testing case;
step S103, publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and step S104, generating a test report according to the verification result.
In one embodiment, before the step of obtaining at least one target test case of the object to be tested in step S101, the method includes:
acquiring an object model of an object to be detected;
converting the object model into a Python object through a JSON Schema mode in a Python library;
and writing a target test case by using the Python object and storing the target test case in a case library.
The object model in the embodiment abstracts the object to be measured into an object model, and the object model is configured with information such as attributes, services, events and the like, so that the attributes and the capability of the object to be measured can be visually reflected through the object model.
Each target test case may include a test operation and test data, and the test operation may include three steps, for example, a case pre-operation, a case execution, and a case environment recovery operation. The test data may be configured before the target test case is obtained, or the data may be preset in the automated test framework, for example, listed in a file resource.
Further, the target test case in this embodiment is a code block of Python coding, that is, a Python object, the case engine is a rule processing center, and different inputs may screen out cases according to rules. And screening out the target test cases according to the requirements of the service scene. For example: the use case name is: "add broadcast program a, and play at 12 noon 00", that this service scenario is that program a is to be played at 12 noon 00, then the case engine will screen out, play add program case, play program usefulness, the combined time is tested.
In one embodiment, in step S102, the step of constructing an MQTT protocol-based automated test framework using the target test case includes:
screening a required target test case from a case library according to the service scene requirement;
and combining and sequencing the screened target test cases by using a preset case engine to form an automatic test frame based on the MQTT protocol.
Further, the automated testing framework in this embodiment is represented as a set of multiple target test cases combined and sorted based on business scenario requirements. The case engine can be expressed as a rule module packaged corresponding to the automatic test framework, and then a target test case under the automatic test framework is screened according to the corresponding rule to be executed. The business scenario requirements are combined according to the using scenario of the equipment or the steps to be tested, each target test case has a single step of verifying the software function, and each target test case corresponds to a corresponding business scenario.
In this embodiment, the step of constructing an MQTT protocol-based automated test framework using the target test case further includes: and configuring the test environment information. For example, the environment 192.168.54.234 is tested, and the corresponding test environment information includes the test end and the object to be tested. The use case configuration is single use case configuration information, for example, the target test use case is information indicating that a program is specifically played by issuing an instruction, the use case configuration information, and the like.
And S103, publishing a message and a subscription message to the MQTT interface of the object to be tested through an automatic testing framework, and checking the content of the subscription message by using the content of the published message.
Before the step of publishing and subscribing the preset message to the MQTT interface of the object to be tested, the method further comprises the following steps: and connecting the object to be tested through a Paho library in the Python library to realize communication connection based on the MQTT protocol.
In step S103, publishing a message and a subscription message to an MQTT interface of an object to be tested through an automated testing framework, and verifying the content of the subscription message by using the published message content, including:
generating a test session object according to the automatic test framework;
calling a test session object to publish messages and subscribe messages to an MQTT interface of an object to be tested;
comparing the published message content with the subscribed message content returned by the object to be tested;
and finishing verification on the subscription message by judging whether the corresponding contents are consistent.
Wherein, the target test case at least comprises: publish topic and message content, subscribe to topics, content to be verified, and desired content.
Further, since the target test case includes corresponding expected content, when the content of the subscribed message is consistent with the expected content, the current test is successful, and when the content of the subscribed message is inconsistent with the expected content, the current test is failed.
To explain further, the published message content is represented as a first message and the subscribed message content is represented as a second message. As for at least one target test case under the automated test framework, the first test step in the automated test framework is taken as the current test step, and the following MQTT interface test steps are executed:
packaging the test operation and test data of the current test step into a first message to be issued to an object to be tested, subscribing a second message of the object to be tested, comparing the subscribed second message with the first message, and if the subscribed second message is different from the subscribed first message, generating a test report of test failure; if the current testing step is the last step of the automated testing framework, further judging whether the current testing step is the last step of the automated testing framework, if so, generating a testing report of successful testing, if not, taking the next testing step as the current testing step, and continuing to execute the testing step of the MQTT interface.
And step S104, generating a test report according to the verification result. Further, the generated test report is saved after the target test case is executed each time.
In the interface testing method based on the MQTT protocol, the problems of the automatic interface testing based on the MQTT protocol, the interface automatic case arrangement and the conversion of the 'object model' into the testing automation elements are solved. The object model of the corresponding object to be tested is converted into a Python object, a target test case is compiled, then an automatic test framework based on the MQTT protocol is constructed, the interface automatic test of the MQTT protocol is realized, meanwhile, the automatic test framework can be liberated from the existing complicated Json operation, and the object model corresponding to the object to be tested can be conveniently operated by virtue of a case editor; the use case arrangement can be conveniently realized through the preset use case engine, and the use case arrangement execution can be realized according to the service scene.
In one embodiment, as shown in fig. 3, there is provided an interface testing apparatus based on MQTT protocol, including: a use case obtaining module 101, a framework building module 102, a test executing module 103 and a report generating module 104, wherein:
the case acquiring module 101 is used for acquiring at least one target test case of an object to be tested;
the framework construction module 102 is used for constructing an automatic test framework based on an MQTT protocol by using a target test case;
the test execution module 103 issues messages and subscription messages to the MQTT interface of the object to be tested through an automatic test framework, and verifies the content of the subscribed messages by using the content of the issued messages;
and a report generating module 104, configured to generate a test report according to the verification result.
For the specific definition of the interface testing device based on MQTT protocol, reference may be made to the above definition of the interface testing method based on MQTT protocol, which is not described herein again. The modules in the interface testing device based on the MQTT protocol may be implemented in whole or in part by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing interface test data based on the MQTT protocol. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement an interface testing method based on the MQTT protocol.
In one embodiment, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement an interface testing method based on the MQTT protocol. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on a shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the present embodiment is only a block diagram of a part of the structure related to the present application, and does not limit the computer device to which the present application is applied, and a specific computer device may include more or less components than those shown in the drawings, or combine some components, or have different arrangements of components.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory having a computer program stored therein, the processor implementing the following steps when executing the computer program:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by utilizing a target testing case;
publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, performs the steps of:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by utilizing a target testing case;
publishing messages and subscription messages to an MQTT interface of an object to be tested through an automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), rambus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
All possible combinations of the technical features in the above embodiments may not be described for the sake of brevity, but should be considered as being within the scope of the present disclosure as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (9)

1. An interface testing method based on MQTT protocol is applied to a testing end and is characterized by comprising the following steps:
acquiring at least one target test case of an object to be tested;
constructing an automatic testing framework based on an MQTT protocol by utilizing the target testing case;
publishing messages and subscription messages to the MQTT interface of the object to be tested through the automatic testing framework, and verifying the content of the subscribed messages by using the published message content;
and generating a test report according to the verification result.
2. The MQTT protocol-based interface testing method according to claim 1, wherein the step of obtaining at least one target test case of an object to be tested is preceded by:
acquiring an object model of the object to be detected;
converting the object model into a Python object through a JSON Schema mode in a Python library;
and compiling the target test case by using the Python object and storing the target test case in a case library.
3. The MQTT protocol-based interface testing method according to claim 2, wherein the step of constructing an MQTT protocol-based automated testing framework using the target test cases comprises:
screening the required target test cases from the case library according to the service scene requirements;
and combining and sequencing the screened target test cases by using a preset case engine to form an automatic test frame based on the MQTT protocol.
4. The MQTT protocol-based interface testing method according to claim 1, wherein before the step of publishing and subscribing messages to the MQTT interface of the object to be tested, the method further comprises:
and connecting the object to be tested through a Paho library in a Python library to realize communication connection based on the MQTT protocol.
5. The MQTT protocol-based interface testing method according to claim 1, wherein the step of publishing and subscribing messages to the MQTT interface of the object to be tested through an automated testing framework and checking the subscribed message contents by using the published message contents comprises:
generating a test session object according to the automatic test framework;
calling the test session object to publish a message and a subscription message to an MQTT interface of the object to be tested;
comparing the published message content with the subscribed message content returned by the object to be tested;
and finishing verification on the subscription message by judging whether the corresponding contents are consistent.
6. The MQTT protocol-based interface testing method of claim 1, wherein the target test case at least comprises: publish topic and message content, subscribe topic, content to be verified, and desired content.
7. An interface testing device based on MQTT protocol, characterized in that the device comprises:
the case acquisition module is used for acquiring at least one target test case of the object to be tested;
the frame construction module is used for constructing an automatic test frame based on an MQTT protocol by utilizing the target test case;
the test execution module issues messages and subscription messages to the MQTT interface of the object to be tested through the automatic test framework, and verifies the content of the subscribed messages by using the content of the issued messages;
and the report generating module is used for generating a test report according to the checking result.
8. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN202211415268.2A 2022-11-11 2022-11-11 MQTT protocol-based interface testing method and device Pending CN115914053A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211415268.2A CN115914053A (en) 2022-11-11 2022-11-11 MQTT protocol-based interface testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211415268.2A CN115914053A (en) 2022-11-11 2022-11-11 MQTT protocol-based interface testing method and device

Publications (1)

Publication Number Publication Date
CN115914053A true CN115914053A (en) 2023-04-04

Family

ID=86473751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211415268.2A Pending CN115914053A (en) 2022-11-11 2022-11-11 MQTT protocol-based interface testing method and device

Country Status (1)

Country Link
CN (1) CN115914053A (en)

Similar Documents

Publication Publication Date Title
CN108134708B (en) Method and device for monitoring third-party interface
CN112714158B (en) Transaction processing method, relay network, cross-link gateway, system, medium and equipment
CN107807841B (en) Server simulation method, device, equipment and readable storage medium
CN111008132B (en) Application debugging method and device for Android system, computer equipment and storage medium
CN112100078B (en) Method, device and equipment for generating interface test case
CN110737548B (en) Data request method and server
CN116700907B (en) Service call demand document storage method, device, electronic equipment and readable medium
CN110888800A (en) Service interaction function test method, device, storage medium and test system
CN113191889A (en) Wind control configuration method, configuration system, electronic device and readable storage medium
CN108345508B (en) Interface call testing method and device
CN112650689A (en) Test method, test device, electronic equipment and storage medium
CN103561113A (en) Web Service interface generating method and device
CN110825538A (en) MQ-based method for dynamically interacting data by self-defining data types
CN115914053A (en) MQTT protocol-based interface testing method and device
CN115185841A (en) System reconfiguration test method, device, equipment and storage medium
CN112765038B (en) Distributed cluster software testing method, device, equipment and storage medium
CN114371884A (en) Method, device, equipment and storage medium for processing Flink calculation task
CN114567571A (en) Performance test method and device, electronic equipment and computer readable storage medium
CN112650509B (en) Application installation package generation method and device, computer equipment and storage medium
CN112699023B (en) Project interface testing method and device, computer equipment and storage medium
CN113852686B (en) Block chain network communication method, device, equipment and readable storage medium
CN111026650B (en) Method and device for testing software, storage medium and electronic equipment
CN117891433A (en) Order flow management system, operation method thereof and related medium
CN113407440A (en) System and method for testing wireless communication module
CN117075871A (en) Method, device, equipment and storage medium for generating calling code of application program interface

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