CN107122296B - Method and apparatus for data assertion for test interface - Google Patents

Method and apparatus for data assertion for test interface Download PDF

Info

Publication number
CN107122296B
CN107122296B CN201710254399.XA CN201710254399A CN107122296B CN 107122296 B CN107122296 B CN 107122296B CN 201710254399 A CN201710254399 A CN 201710254399A CN 107122296 B CN107122296 B CN 107122296B
Authority
CN
China
Prior art keywords
interface
test
request message
determining
result
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.)
Active
Application number
CN201710254399.XA
Other languages
Chinese (zh)
Other versions
CN107122296A (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.)
Shanghai Raxtone Software Co ltd
Original Assignee
Shanghai Raxtone Software Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Raxtone Software Co ltd filed Critical Shanghai Raxtone Software Co ltd
Priority to CN201710254399.XA priority Critical patent/CN107122296B/en
Publication of CN107122296A publication Critical patent/CN107122296A/en
Application granted granted Critical
Publication of CN107122296B publication Critical patent/CN107122296B/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/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The method comprises the steps of obtaining a request message of a calling interface of a test interface; determining a data assertion scheme according to the request message; determining a test result of the test interface according to the data assertion scheme and a request message of a calling interface of the test interface, thereby solving the problem of single assertion mode; further, determining a query result from a database, and processing the query result into a dictionary format; comparing the acquired request message of the calling interface of the test interface with the dictionary format query result to determine whether the same key and the corresponding value thereof exist; therefore, the method can be connected with a designated database to acquire or update test related data, solves the problem that the database cannot be read and written, and can quickly and massively assert whether the data of the calling interface is accurate or not by comparing the acquired request message of the calling interface with the database query result in a key-value pair mode.

Description

Method and apparatus for data assertion for test interface
Technical Field
The present application relates to the field of computers, and in particular, to a method and apparatus for data assertion for a test interface.
Background
With the development of the test industry, functional tests, performance tests and automatic tests successively appear, at present, the architecture of most of platforms is no longer the traditional MVC structure, the system continuously develops towards the directions of distribution, service centralization and high availability, the system architecture is numerous and complex nowadays, interfaces among systems are numerous and diverse, the traditional functional tests, performance tests and automatic tests are difficult to meet the requirements of system development, a more effective and practical test mode capable of being continuously carried out is urgently needed to ensure the quality of the system, the traditional interface tests mainly aim at the test of a single interface, linkage tests of a plurality of interfaces cannot be carried out, return data of a front interface cannot be transmitted, and the test and the quick iteration are difficult.
At present, Postman is an interface testing tool which can adapt to most service scenes, is convenient and quick, and a flow chart of an overall architecture idea is shown in fig. 1. The framework has a single assertion mode, only has one static assertion mode, and cannot quickly assert whether interface data are accurate in a large quantity.
Content of application
An object of the present application is to provide a method and an apparatus for data assertion for a test interface, which solve the problems in the prior art that an assertion manner is single and a data base cannot be read and written.
According to one aspect of the present application, there is provided a method for testing data assertion of an interface, the method comprising:
acquiring a request message of a calling interface of a test interface;
determining a data assertion scheme according to the request message;
and determining the test result of the test interface according to the data assertion scheme and the request message of the call interface of the test interface.
Further, determining a data assertion scheme from the request message includes:
and judging whether the request message has a structured query statement, if not, determining a data assertion scheme as a test result of the test interface according to a static data assertion mode and the request message of the call interface of the test interface.
Further, determining a data assertion scheme from the request message includes:
and judging whether the request message has a structured query statement, if so, determining a data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and the request message of the call interface of the test interface.
Further, determining a test result of the test interface according to a static data assertion manner and a request message of a call interface of the test interface, including:
and judging whether the request message of the calling interface of the test interface meets the current service requirement according to a preset static data assertion condition, and if so, determining that the test result of the test interface is successful.
Further, determining a test result of the test interface according to a dynamic data assertion manner and a request message of a call interface of the test interface, including:
determining a query result according to the structured query statement in the request message;
and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful.
Further, determining a query result according to the structured query statement in the request message includes:
and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database.
Further, formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result and the request message are the same, determining that the test result of the test interface is a successful test, including:
formatting the query result into a dictionary format;
and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful.
According to another aspect of the present application, there is also provided an apparatus for testing data assertion of an interface, the apparatus comprising:
the acquisition device is used for acquiring a request message of a calling interface of the test interface;
determining means for determining a data assertion scheme from the request message;
and the testing device is used for determining the testing result of the testing interface according to the data assertion scheme and the request message of the calling interface of the testing interface.
Further, the determining means is configured to:
and judging whether the request message has a structured query statement, if not, determining a data assertion scheme as a test result of the test interface according to a static data assertion mode and the request message of the call interface of the test interface.
Further, the determining means is configured to:
and judging whether the request message has a structured query statement, if so, determining a data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and the request message of the call interface of the test interface.
Further, the determining means is configured to:
and judging whether the request message of the calling interface of the test interface meets the current service requirement according to a preset static data assertion condition, and if so, determining that the test result of the test interface is successful.
Further, the determining means is configured to:
determining a query result according to the structured query statement in the request message;
and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful.
Further, the determining means is configured to:
and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database.
Further, the determining means is configured to:
formatting the query result into a dictionary format;
and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful.
Compared with the prior art, the method and the device have the advantages that the request message of the calling interface of the test interface is obtained; determining a data assertion scheme according to the request message; determining a test result of the test interface according to the data assertion scheme and a request message of a calling interface of the test interface, thereby solving the problem of single assertion mode; further, querying a corresponding database according to the structured query statement in the request message, determining a query result from the database, and formatting the query result into a dictionary format; comparing the obtained request message of the calling interface of the test interface with the dictionary format query result to determine whether the same key exists, if so, comparing the same key to determine whether the corresponding values are the same, and if so, determining that the test result of the test interface is successful; therefore, the method can be connected with a designated database to acquire or update test related data, solves the problem that the database cannot be read and written, and can quickly and massively assert whether the data of the calling interface is accurate or not by comparing the acquired request message of the calling interface with the database query result in a key-value pair mode.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 illustrates an architecture diagram of interface testing in the prior art;
FIG. 2 is a schematic diagram illustrating an interface architecture of an efficient hierarchical server side according to an embodiment of the present application;
FIG. 3 illustrates a method flow diagram for testing data assertion for an interface provided in accordance with an aspect of the present application;
FIG. 4 is a schematic flow chart diagram illustrating a dynamic data assertion approach according to an embodiment of the present application;
FIG. 5 illustrates an apparatus diagram for data assertion for a test interface provided in accordance with another aspect of the present application;
the same or similar reference numbers in the drawings identify the same or similar elements.
Detailed Description
The present application is described in further detail below with reference to the attached figures.
In a typical configuration of the present application, the terminal, the device serving the network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory computer readable media (transient media), such as modulated data signals and carrier waves.
FIG. 2 is a schematic diagram illustrating an interface architecture of an efficient hierarchical server side according to an embodiment of the present application; firstly, running a script, and loading an environment, a Uniform Resource Locator (URL), a port name, an account number, request parameters, an assertion condition and a structured query statement (SQL statement); loading a configuration file, taking out a session unique identifier (SID) stored in a local file according to an account, loading an encryption template to generate encryption information, automatically generating a legal message header (header) according to an incoming parameter, after requesting an interface, judging whether the interface correctly processes the request by analyzing the content returned by a server, if so, taking out the content of a message Body (Body), connecting a corresponding database when an SQL statement is incoming, executing the SQL statement, returning a query result, processing the query result into a JSON format, checking whether a corresponding value (value) is correct by traversing a key (key), if so, passing the test, and if not, outputting a test result of the local round; and when the taken Body content is not transmitted into the SQL statement, entering a static assertion flow, judging whether the result meets the service requirement through assertion conditions, if so, passing the test, if not, failing the test, judging whether other unexecuted cases exist, and if so, reading the next case for testing. And if the login is successful, the acquired SID stores a local file in a key value pair mode, the SID stored in the local file is taken out according to an account number, and the test process is executed. When the interface is not processed correctly and the SID is not expired, the error information is extracted, and if the result is an expected result, the test is successful.
Through the interface test architecture diagram shown in fig. 2, the problem of weak script universality is solved, and through the design of shallow encapsulation, template mode and the like of data and modules, after receiving an execution command, the script can automatically generate a parameter set corresponding to the execution command without manually configuring excessive parameters, so that quick and convenient execution is realized. The problem of locally reading and writing files is solved, the key data are stored to the local, the storage format is Dictionary (Dictionary), data are read in the later period, the corresponding value (value) can be found through a key (key), the problem that an external library cannot be introduced is solved, the encrypted data are directly returned to a calling function, the problem that the data cannot be read and written in the database is solved, the specified database can be connected to obtain or update test related data, the problem that the assertion mode is too single is solved, after the interface returned data and the database query data are obtained, whether the assertion interface data are accurate or not can be rapidly and massively judged in a key-value comparison mode, meanwhile, by using the framework, an Application Program Interface (API) can be opened for other tests or open frameworks, and expansion can be carried out.
The test mode using the interface architecture diagram shown in fig. 2 has a fast and accurate parameter assertion process, and adds a dynamic assertion mode on the basis of a static assertion mode, so that the assertion mode is no longer single, whether interface data are accurate can be asserted rapidly in large quantity, and test related data can be acquired or updated by calling packets of other database servers to connect with a designated database, so that the database can be read and written. The specific implementation mode is realized by the following embodiments:
fig. 3 is a flow chart illustrating a method for testing data assertion of an interface according to an aspect of the present application, wherein the method comprises: step S11 to step S13, in step S11, obtaining a request message of a call interface of the test interface; in step S12, determining a data assertion scheme from the request message; in step S13, the test result of the test interface is determined according to the data assertion scheme and the request message of the call interface of the test interface, so that the problem of single assertion mode is solved, and whether the interface data is accurate or not can be quickly and massively asserted.
Specifically, in step S11, a request message for calling an interface of the test interface is obtained; here, the request message includes a session unique identifier, encryption information, and interface parameters for calling, where the session unique identifier SID and the encryption information are placed in a header (header) of the request message for testing the interface, and a corresponding message body generation template, including the determined finished interface parameters, can be found in a message body (body) of the request message according to the uniform resource locator URL and the configuration file. And further, under different scenes, generating a specific parameter set by using the parameter template. When the assertion is performed, the parameter in the header in the request message may be asserted, and the parameter in the body in the request message may also be asserted.
Specifically, in step S12, a data assertion scheme is determined according to the request message; the parameters are obtained from the header in the request message or the parameters are obtained from the body, a data assertion scheme is determined according to the obtained specific parameters, if the parameters exist, a static assertion mode can be selected, and if the parameters exist, a dynamic assertion mode can be selected, so that the interface parameters are quickly and massively asserted, and whether the interface parameters are accurate or not is judged.
Specifically, in step S13, the test result of the test interface is determined according to the data assertion scheme and the request message of the call interface of the test interface. In this embodiment of the present application, the assertion of the interface parameter is no longer a single way, and the assertion flows of the static assertion way and the dynamic assertion way are different, and the interface parameter is asserted according to the selected assertion way, so as to determine whether the interface parameter is accurate, and obtain a test result.
In an embodiment of the present application, in step S12, when determining the data assertion scheme according to the request message, an assertion manner may be selected by determining whether a structured query statement exists in the request message, and if not, determining that the data assertion scheme is a test result of the test interface according to a static data assertion manner and a request message of a call interface of the test interface; and if so, determining the data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and a request message of a call interface of the test interface. And judging whether the data structure of the query statement in the request message is of a dictionary type, if so, judging that the data assertion scheme is a static data assertion mode, and if not, judging that the data assertion scheme is a dynamic data assertion mode, and comparing the key value pair only by converting the query result into the dictionary type so as to assert.
Preferably, in step S12, if a static data assertion manner is selected, it is determined whether a request message of a call interface of the test interface meets a current service requirement according to a preset static data assertion condition, and if so, it is determined that a test result of the test interface is a test success. Herein, whether the called interface parameters such as parameters in the body meet the current business requirements is judged according to the preset static data assertion conditions, and the test is successful when the current business requirements are met, wherein the preset static data assertion conditions may be whether the values corresponding to the called interface parameters are consistent according to the key comparison in the returned data result, for example, in the ticket buying process, if the purchase fails, the server only needs to obtain specific contents from the body, and determines that the purchase failure includes any one of the sold tickets, repeated ticket buying, purchase overtime and the like according to the interface document protocol, wherein one parameter name key represents the purchase status, the value of the value may represent that the tickets determined according to the interface document protocol are sold, repeated ticket buying, purchase overtime and the like, for example, when the value of the purchase status represents that the purchase failure, the corresponding value is compared with the value corresponding to the same key in the prediction result in the test of the interface, if the two are consistent, the test is successful, and if the two are not consistent, the test is failed.
Preferably, in step S12, if a dynamic data assertion manner is selected, determining a query result according to a structured query statement in the request message; and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful. And if the query result is the same as the return data called by the interface at this time, the test is successful, and if a value is different, the test is failed.
In an embodiment of the present application, in step S12, a query result is determined according to the structured query statement in the request message, which is specifically implemented by: and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database. The Pymysqldb module can be called to execute the transmitted SQL statement, wherein the Pymysqldb module can call a package of the mysql database server for inquiring and modifying the database, and the Pymysqldb module can be called to connect with the specified database to acquire or update test related data, so that the function of reading and writing the database is realized.
Next to the above embodiment, in step S12, formatting the query result into a dictionary format; and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful. After the interface return data and the database query data are obtained, whether the interface return data are accurate is judged in a key-value comparison mode in a dictionary, specifically, a dictionary format is firstly formatted on a query result, whether values of the query result are equal or not is compared according to the same key, after all parameters returned by the calling interface are traversed, if the values are equal, the test is successful, and if any value is not equal, the test is failed. The dictionary format is formatted through the database query result, and quick and large-scale comparison with interface return parameters is realized. For example, after a ticket purchased on the day is queried and a database is queried, a query result is processed into a dictionary format { signed ": 123 ',' price ': 1}, an interface return result is { signed": 123', 'price': 2}, keys in the query result are the same as keys of the interface return result and are signed, then values corresponding to the keys are compared, namely the value of signed is compared, if the values are the same, traversal is continued, the next group of keys and the corresponding values are compared, all parameters returned by calling the interface are compared, and if the values are equal, the test is successful.
Fig. 4 shows a flow diagram of a dynamic data assertion manner in an embodiment of the present application, where an assertion module first receives interface return data and a query statement, and executes the query statement sent by a sub-module by calling a pymysql ldb module, and formats the query result into a JSON format, and specifically processes the query result into a dictionary format in the JSON, a verification module receives the interface return data and the formatted database query result, compares whether values of the interface return data and the formatted database query result are equal according to the same key, and after traversing all return parameters, if the values are equal, the test is passed, and if the values are not equal, and if different keys or unequal values exist, the test fails, thereby implementing fast and accurate parameter assertion, and at the same time, a designated database can be connected, test-related data can be obtained or updated, and the problem that a data base cannot be read or written in a test interface process is solved.
Fig. 5 is a schematic diagram illustrating an apparatus for testing data assertion of an interface according to another aspect of the present application, where the apparatus includes: the device comprises an acquisition device 11, a determination device 12 and a test device 13, wherein the acquisition device 11 is used for acquiring a request message of a call interface of a test interface; the determining device 12 is used for determining a data assertion scheme according to the request message; the test device 13 is configured to determine a test result of the test interface according to the data assertion scheme and the request message of the call interface of the test interface, so as to solve the problem of a single assertion mode, and quickly assert whether a large amount of interface data is accurate.
FIG. 2 is a schematic diagram illustrating an interface architecture of an efficient hierarchical server side according to an embodiment of the present application; firstly, running a script, and loading an environment, a Uniform Resource Locator (URL), a port name, an account number, request parameters, an assertion condition and a structured query statement (SQL statement); loading a configuration file, taking out a session unique identifier (SID) stored in a local file according to an account, loading an encryption template to generate encryption information, automatically generating a legal message header (header) according to an incoming parameter, after requesting an interface, judging whether the interface correctly processes the request by analyzing the content returned by a server, if so, taking out the content of a message Body (Body), connecting a corresponding database when an SQL statement is incoming, executing the SQL statement, returning a query result, processing the query result into a JSON format, checking whether a corresponding value (value) is correct by traversing a key (key), if so, passing the test, and if not, outputting a test result of the local round; and when the taken Body content is not transmitted into the SQL statement, entering a static assertion flow, judging whether the result meets the service requirement through assertion conditions, if so, passing the test, if not, failing the test, judging whether other unexecuted cases exist, and if so, reading the next case for testing. And if the login is successful, the acquired SID stores a local file in a key value pair mode, the SID stored in the local file is taken out according to an account number, and the test process is executed. When the interface is not processed correctly and the SID is not expired, the error information is extracted, and if the result is an expected result, the test is successful.
Through the interface test architecture diagram shown in fig. 2, the problem of weak script universality is solved, and through the design of shallow encapsulation, template mode and the like of data and modules, after receiving an execution command, the script can automatically generate a parameter set corresponding to the execution command without manually configuring excessive parameters, so that quick and convenient execution is realized. The problem of locally reading and writing files is solved, the key data are stored to the local, the storage format is Dictionary (Dictionary), data are read in the later period, the corresponding value (value) can be found through a key (key), the problem that an external library cannot be introduced is solved, the encrypted data are directly returned to a calling function, the problem that the data cannot be read and written in the database is solved, the specified database can be connected to obtain or update test related data, the problem that the assertion mode is too single is solved, after the interface returned data and the database query data are obtained, whether the assertion interface data are accurate or not can be rapidly and massively judged in a key-value comparison mode, meanwhile, by using the framework, an Application Program Interface (API) can be opened for other tests or open frameworks, and expansion can be carried out.
The test mode using the interface architecture diagram shown in fig. 2 has a fast and accurate parameter assertion process, and adds a dynamic assertion mode on the basis of a static assertion mode, so that the assertion mode is no longer single, whether interface data are accurate can be asserted rapidly in large quantity, and test related data can be acquired or updated by calling packets of other database servers to connect with a designated database, so that the database can be read and written. The specific implementation manner is implemented by the device shown in fig. 5:
specifically, the obtaining device 11 is configured to obtain a request message of a call interface of the test interface; here, the request message includes a session unique identifier, encryption information, and interface parameters for calling, where the session unique identifier SID and the encryption information are placed in a header (header) of the request message for testing the interface, and a corresponding message body generation template, including the determined finished interface parameters, can be found in a message body (body) of the request message according to the uniform resource locator URL and the configuration file. And further, under different scenes, generating a specific parameter set by using the parameter template. When the assertion is performed, the parameter in the header in the request message may be asserted, and the parameter in the body in the request message may also be asserted.
In particular, the determining means 12 is configured to determine a data assertion scheme according to the request message; the parameters are obtained from the header in the request message or the parameters are obtained from the body, a data assertion scheme is determined according to the obtained specific parameters, if the parameters exist, a static assertion mode can be selected, and if the parameters exist, a dynamic assertion mode can be selected, so that the interface parameters are quickly and massively asserted, and whether the interface parameters are accurate or not is judged.
Specifically, the determining device 13 is configured to determine the test result of the test interface according to the data assertion scheme and the request message of the call interface of the test interface. In this embodiment of the present application, the assertion of the interface parameter is no longer a single way, and the assertion flows of the static assertion way and the dynamic assertion way are different, and the interface parameter is asserted according to the selected assertion way, so as to determine whether the interface parameter is accurate, and obtain a test result.
In an embodiment of the present application, the determining device 12 is configured to, when determining the data assertion scheme according to the request message, select an assertion manner by judging whether a structured query statement exists in the request message, and if not, determine that the data assertion scheme is a test result of the test interface according to a static data assertion manner and a request message of a call interface of the test interface; and if so, determining the data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and a request message of a call interface of the test interface. And judging whether the data structure of the query statement in the request message is of a dictionary type, if so, judging that the data assertion scheme is a static data assertion mode, and if not, judging that the data assertion scheme is a dynamic data assertion mode, and comparing the key value pair only by converting the query result into the dictionary type so as to assert.
Preferably, the determining device 12 is configured to, if a static data assertion manner is selected, determine whether a request message of a call interface of the test interface meets a current service requirement according to a preset static data assertion condition, and if so, determine that a test result of the test interface is a test success. Herein, whether the called interface parameters such as parameters in the body meet the current business requirements is judged according to the preset static data assertion conditions, and the test is successful when the current business requirements are met, wherein the preset static data assertion conditions may be whether the values corresponding to the called interface parameters are consistent according to the key comparison in the returned data result, for example, in the ticket buying process, if the purchase fails, the server only needs to obtain specific contents from the body, and determines that the purchase failure includes any one of the sold tickets, repeated ticket buying, purchase overtime and the like according to the interface document protocol, wherein one parameter name key represents the purchase status, the value of the value may represent that the tickets determined according to the interface document protocol are sold, repeated ticket buying, purchase overtime and the like, for example, when the value of the purchase status represents that the purchase failure, the corresponding value is compared with the value corresponding to the same key in the prediction result in the test of the interface, if the two are consistent, the test is successful, and if the two are not consistent, the test is failed.
Preferably, the determining device 12 is configured to determine, if a dynamic data assertion manner is selected, a query result according to a structured query statement in the request message; and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful. And if the query result is the same as the return data called by the interface at this time, the test is successful, and if a value is different, the test is failed.
In an embodiment of the present application, the determining device 12 is configured to determine a query result according to the structured query statement in the request message, and specifically, the determining is implemented by: and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database. The Pymysqldb module can be called to execute the transmitted SQL statement, wherein the Pymysqldb module can call a package of the mysql database server for inquiring and modifying the database, and the Pymysqldb module can be called to connect with the specified database to acquire or update test related data, so that the function of reading and writing the database is realized.
Following the above embodiment, the determining device 12 is configured to format the query result into a dictionary format; and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful. After the interface return data and the database query data are obtained, whether the interface return data are accurate is judged in a key-value comparison mode in a dictionary, specifically, a dictionary format is firstly formatted on a query result, whether values of the query result are equal or not is compared according to the same key, after all parameters returned by the calling interface are traversed, if the values are equal, the test is successful, and if any value is not equal, the test is failed. The dictionary format is formatted through the database query result, and quick and large-scale comparison with interface return parameters is realized. For example, after a ticket purchased on the day is queried and a database is queried, a query result is processed into a dictionary format { signed ": 123 ',' price ': 1}, an interface return result is { signed": 123', 'price': 2}, keys in the query result are the same as keys of the interface return result and are signed, then values corresponding to the keys are compared, namely the value of signed is compared, if the values are the same, traversal is continued, the next group of keys and the corresponding values are compared, all parameters returned by calling the interface are compared, and if the values are equal, the test is successful.
Fig. 4 shows a flow diagram of a dynamic data assertion manner in an embodiment of the present application, where an assertion module first receives interface return data and a query statement, and executes the query statement sent by a sub-module by calling a pymysql ldb module, and formats the query result into a JSON format, and specifically processes the query result into a dictionary format in the JSON, a verification module receives the interface return data and the formatted database query result, compares whether values of the interface return data and the formatted database query result are equal according to the same key, and after traversing all return parameters, if the values are equal, the test is passed, and if the values are not equal, and if different keys or unequal values exist, the test fails, thereby implementing fast and accurate parameter assertion, and at the same time, a designated database can be connected, test-related data can be obtained or updated, and the problem that a data base cannot be read or written in a test interface process is solved.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.
It should be noted that the present application may be implemented in software and/or a combination of software and hardware, for example, implemented using Application Specific Integrated Circuits (ASICs), general purpose computers or any other similar hardware devices. In one embodiment, the software programs of the present application may be executed by a processor to implement the steps or functions described above. Likewise, the software programs (including associated data structures) of the present application may be stored in a computer readable recording medium, such as RAM memory, magnetic or optical drive or diskette and the like. Additionally, some of the steps or functions of the present application may be implemented in hardware, for example, as circuitry that cooperates with the processor to perform various steps or functions.
In addition, some of the present application may be implemented as a computer program product, such as computer program instructions, which when executed by a computer, may invoke or provide methods and/or techniques in accordance with the present application through the operation of the computer. Program instructions which invoke the methods of the present application may be stored on a fixed or removable recording medium and/or transmitted via a data stream on a broadcast or other signal-bearing medium and/or stored within a working memory of a computer device operating in accordance with the program instructions. An embodiment according to the present application comprises an apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, trigger the apparatus to perform a method and/or a solution according to the aforementioned embodiments of the present application.
It will be evident to those skilled in the art that the present application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the apparatus claims may also be implemented by one unit or means in software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.

Claims (14)

1. A method for testing data assertion for an interface, wherein the method comprises:
acquiring a request message of a calling interface of a test interface, wherein the request message comprises a session unique identifier, encryption information and interface parameters for calling;
the session unique identifier and the encryption information are put into a message header of a request message for testing an interface, and a corresponding message body generation template is found in a message body of the request message according to a uniform resource locator and a configuration file so as to generate an interface parameter group;
acquiring parameters in an interface parameter group from a message header or a message body of the request message, and determining a data assertion scheme according to the parameters;
determining a test result of the test interface according to the data assertion scheme and a request message of a calling interface of the test interface;
when the called test interface is not processed correctly, judging whether the session unique identifier is overdue, if so, calling a login module, and generating parameters and encrypted information for logging according to the environment and a request end;
and if the login is successful, storing the acquired session unique identifier in a local file in a key value pair mode.
2. The method of claim 1, wherein determining a data assertion scheme from the parameters comprises:
and judging whether the request message has a structured query statement, if not, determining a data assertion scheme as a test result of the test interface according to a static data assertion mode and the request message of the call interface of the test interface.
3. The method of claim 1, wherein determining a data assertion scheme from the parameters comprises:
and judging whether the request message has a structured query statement, if so, determining a data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and the request message of the call interface of the test interface.
4. The method of claim 2, wherein determining the test result of the test interface according to a static data assertion manner and a request message of a call interface of the test interface comprises:
and judging whether the request message of the calling interface of the test interface meets the current service requirement according to a preset static data assertion condition, and if so, determining that the test result of the test interface is successful.
5. The method of claim 3, wherein determining the test result of the test interface according to the dynamic data assertion manner and the request message of the call interface of the test interface comprises:
determining a query result according to the structured query statement in the request message;
and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful.
6. The method of claim 5, wherein determining query results from a structured query statement in the request message comprises:
and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database.
7. The method of claim 5, wherein formatting the query result, comparing the formatted query result with the request message of the call interface of the test interface, and if the formatted query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is a test success, comprises:
formatting the query result into a dictionary format;
and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful.
8. An apparatus for testing data assertion for an interface, wherein the apparatus comprises:
the device comprises an acquisition device and a test interface, wherein the acquisition device is used for acquiring a request message of a calling interface of a test interface, and the request message comprises a session unique identifier, encryption information and interface parameters for calling;
the acquisition device is used for putting the session unique identifier and the encrypted information into a message header of a request message for testing an interface, and finding a corresponding message body generation template in a message body of the request message according to a uniform resource locator and a configuration file to generate an interface parameter group;
a determining device, configured to obtain parameters in the interface parameter set from a message header or a message body of the request message, and determine a data assertion scheme according to the parameters;
the testing device is used for determining the testing result of the testing interface according to the data assertion scheme and the request message of the calling interface of the testing interface;
the testing device is used for judging whether the session unique identifier is overdue or not when the called testing interface is not processed correctly, and calling the login module if the session unique identifier is overdue, and generating parameters and encrypted information for login according to the environment and the request end; and if the login is successful, storing the acquired session unique identifier in a local file in a key value pair mode.
9. The apparatus of claim 8, wherein the determining means is to:
and judging whether the request message has a structured query statement, if not, determining a data assertion scheme as a test result of the test interface according to a static data assertion mode and the request message of the call interface of the test interface.
10. The apparatus of claim 8, wherein the determining means is to:
and judging whether the request message has a structured query statement, if so, determining a data assertion scheme as a test result of the test interface according to a dynamic data assertion mode and the request message of the call interface of the test interface.
11. The apparatus of claim 9, wherein the determining means is configured to:
and judging whether the request message of the calling interface of the test interface meets the current service requirement according to a preset static data assertion condition, and if so, determining that the test result of the test interface is successful.
12. The apparatus of claim 10, wherein the determining means is configured to:
determining a query result according to the structured query statement in the request message;
and formatting the query result, comparing the processed query result with the request message of the call interface of the test interface, and if the query result is the same as the request message of the call interface of the test interface, determining that the test result of the test interface is successful.
13. The apparatus of claim 12, wherein the determining means is configured to:
and querying a corresponding database according to the structured query statement in the request message, and determining a query result from the database.
14. The apparatus of claim 12, wherein the determining means is configured to:
formatting the query result into a dictionary format;
and comparing whether the obtained request message of the calling interface of the test interface and the dictionary format query result have the same key, if so, comparing whether the corresponding values are the same according to the same key, and if so, determining that the test result of the test interface is successful.
CN201710254399.XA 2017-04-18 2017-04-18 Method and apparatus for data assertion for test interface Active CN107122296B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710254399.XA CN107122296B (en) 2017-04-18 2017-04-18 Method and apparatus for data assertion for test interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710254399.XA CN107122296B (en) 2017-04-18 2017-04-18 Method and apparatus for data assertion for test interface

Publications (2)

Publication Number Publication Date
CN107122296A CN107122296A (en) 2017-09-01
CN107122296B true CN107122296B (en) 2020-06-19

Family

ID=59725333

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710254399.XA Active CN107122296B (en) 2017-04-18 2017-04-18 Method and apparatus for data assertion for test interface

Country Status (1)

Country Link
CN (1) CN107122296B (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108829584B (en) * 2018-05-24 2022-02-11 携程计算机技术(上海)有限公司 Service logic interface mock test method and system
CN110740071B (en) * 2018-07-18 2021-07-13 优信拍(北京)信息科技有限公司 Method, device and system for monitoring network interface
CN109542872B (en) * 2018-10-26 2021-01-22 金蝶软件(中国)有限公司 Data reading method and device, computer equipment and storage medium
CN110059302A (en) * 2019-03-15 2019-07-26 平安城市建设科技(深圳)有限公司 Data Date formatting method, device, equipment and readable storage medium storing program for executing
CN113049948B (en) * 2019-07-01 2022-09-02 成都奥卡思微电科技有限公司 Correction method, storage medium and terminal for verifying assertion space-time property based on form of externally introduced logic circuit
CN110704306B (en) * 2019-09-09 2024-03-22 武汉安辰鑫信息科技有限公司 Assertion processing method, device, equipment and storage medium in test
CN110908892A (en) * 2019-09-18 2020-03-24 泰康保险集团股份有限公司 Interface data testing method and device and readable storage medium
CN110489349B (en) * 2019-09-23 2022-06-03 四川长虹电器股份有限公司 JSON configuration file-based interface test method
CN110990250B (en) * 2019-10-12 2022-09-06 深圳平安医疗健康科技服务有限公司 Interface test method, device, equipment and storage medium
CN111831547A (en) * 2020-05-29 2020-10-27 大数金科网络技术有限公司 Automatic interface test platform
CN112486810A (en) * 2020-11-25 2021-03-12 上海中通吉网络技术有限公司 Interface verification method, system, computer and storage medium of Jmeter platform
CN113434419A (en) * 2021-06-29 2021-09-24 青岛海尔科技有限公司 Interface test case assertion method and device
CN113641747B (en) * 2021-10-15 2022-03-18 北京新氧科技有限公司 Method, device and system for accessing postman tool to database

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102315945A (en) * 2011-10-20 2012-01-11 江苏三源教育实业有限公司 Unified identity authentication method based on private agreement
WO2017015955A1 (en) * 2015-07-30 2017-02-02 Hewlett-Packard Development Company,L.P. Application testing

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102841841B (en) * 2011-06-20 2016-06-01 阿里巴巴集团控股有限公司 A kind of test asserts processing method and system
CN106155891B (en) * 2015-04-02 2019-07-05 阿里巴巴集团控股有限公司 Interface test method, interface description data library generating method and device
CN105099811B (en) * 2015-06-03 2019-01-22 北京金山安全软件有限公司 Interface testing method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102315945A (en) * 2011-10-20 2012-01-11 江苏三源教育实业有限公司 Unified identity authentication method based on private agreement
WO2017015955A1 (en) * 2015-07-30 2017-02-02 Hewlett-Packard Development Company,L.P. Application testing

Also Published As

Publication number Publication date
CN107122296A (en) 2017-09-01

Similar Documents

Publication Publication Date Title
CN107122296B (en) Method and apparatus for data assertion for test interface
CN107122258B (en) Method and equipment for checking state code of test interface
CN107122297B (en) Method and equipment for generating request message of test interface
CN107092535B (en) Method and apparatus for data storage of test interface
US20200293519A1 (en) Solution for implementing computing service based on structured query language statement
US11561889B2 (en) Orchestration for automated performance testing
CN111818035B (en) Permission verification method and device based on API gateway
CN112532490A (en) Regression testing system and method and electronic equipment
CN112035363A (en) Automatic interface testing method and device
CN111767226A (en) Method, system and equipment for testing cloud computing platform resources
CN111314535A (en) Method and equipment for recording quality inspection process of mobile phone
CN111159040A (en) Test data generation method, device, equipment and storage medium
CN112860507B (en) Control method and device for sampling rate of distributed link tracking system
CN108809896A (en) A kind of information calibration method, device and electronic equipment
CN113836014A (en) Interface testing method and device, electronic equipment and storage medium
CN108268369B (en) Test data acquisition method and device
CN113114794A (en) Method and device for processing domain name based on secondary proxy
CN112256984A (en) Method and device for acquiring interface background screenshot corresponding to webpage
CN116069577A (en) Interface testing method, equipment and medium for RPC service
CN108135000B (en) Authentication method and equipment
CN111026631A (en) Automatic interface detection method and device and server
CN112433933A (en) Method and equipment for automatically testing interface
CN111708691B (en) Figerprint automatic adaptation method and device based on android platform
CN114048145A (en) Transaction checking test method and device, electronic equipment and storage medium
CN116775441A (en) Test method and device, electronic equipment and computer readable storage medium

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