CN114003510A - Script testing method, device, equipment and medium based on Mock service - Google Patents

Script testing method, device, equipment and medium based on Mock service Download PDF

Info

Publication number
CN114003510A
CN114003510A CN202111443013.2A CN202111443013A CN114003510A CN 114003510 A CN114003510 A CN 114003510A CN 202111443013 A CN202111443013 A CN 202111443013A CN 114003510 A CN114003510 A CN 114003510A
Authority
CN
China
Prior art keywords
customized
test
mock
message
target
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
CN202111443013.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.)
Pingan Payment Technology Service Co Ltd
Original Assignee
Pingan Payment Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Pingan Payment Technology Service Co Ltd filed Critical Pingan Payment Technology Service Co Ltd
Priority to CN202111443013.2A priority Critical patent/CN114003510A/en
Publication of CN114003510A publication Critical patent/CN114003510A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The embodiment of the application discloses a script testing method, device, equipment and medium based on Mock service. The method comprises the following steps: acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters; then determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein a plurality of customized Mock messages are stored in the customized Mock message database, and each customized Mock message comprises conventional data and a plurality of groups of customized data; determining multiple groups of target customization data corresponding to multiple request parameters from multiple groups of customization data of the target customization Mock message; determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message; and finally, respectively providing the target test data to the test script for script test to obtain a plurality of test results. The scheme can improve the testing efficiency of the script.

Description

Script testing method, device, equipment and medium based on Mock service
Technical Field
The application relates to the technical field of automatic testing, in particular to a script testing method, device, equipment and medium based on Mock service.
Background
In the development and growth process of financial enterprises, a local system generally needs to interact information with multiple sponsors, for example, in a loan process, a system of an external merchant, such as a bank, a security dealer and the like, needs to be docked, at this time, the local system needs to test the support of the external merchant to test whether the local system meets the requirements of the external merchant, but due to the replacement of a connection address of a test environment of the external merchant, the cleaning and unauthorized modification of test data and the like, the test data of the external merchant is unstable, and the automatic test stability of the local system is seriously affected.
In order to solve the above problem, the prior art provides a solution to solve the environmental problem by simulating the external return message using Mock, which generally means that when testing an object a, we construct some fake objects to simulate the interaction with a, and the behavior of the Mock objects is preset and expected.
However, in the prior art, one request corresponds to one Mock service interface, each Mock service interface corresponds to one Mock message, and one Mock message can only satisfy one test case, so that one request can only return one result, and the test efficiency is low.
Disclosure of Invention
The embodiment of the application provides a script testing method, device, equipment and medium based on Mock service, and the testing efficiency can be improved.
In a first aspect, an embodiment of the present application provides a method for testing a script based on a Mock service, which includes:
acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters;
determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data;
determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message;
determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message;
and respectively providing the target test data to the test script for script test to obtain a plurality of test results.
In a second aspect, an embodiment of the present application further provides a script testing apparatus based on Mock service, which includes:
the device comprises a first acquisition unit, a second acquisition unit and a control unit, wherein the first acquisition unit is used for acquiring a test request of a test script, and the test request comprises a service identifier and a plurality of request parameters;
a first determining unit, configured to determine, based on the test request, a target customized Mock message corresponding to the service identifier from a preset customized Mock message database, where the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message includes conventional data and multiple sets of customized data;
a second determining unit, configured to determine multiple sets of target customization data corresponding to the multiple request parameters from multiple sets of customization data of the target customization Mock packet;
a third determining unit, configured to determine multiple target test data according to the multiple sets of target customization data and the conventional data in the target customization Mock message;
and the test unit is used for respectively providing the target test data to the test script for script test to obtain a plurality of test results.
In a third aspect, an embodiment of the present application further provides a computer device, which includes a memory and a processor, where the memory stores a computer program, and the processor implements the above method when executing the computer program.
In a fourth aspect, the present application also provides a computer-readable storage medium, in which a computer program is stored, the computer program including program instructions, which when executed by a processor, implement the above method.
The embodiment of the application provides a script testing method, device, equipment and medium based on Mock service. Wherein the method comprises the following steps: acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters; then determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein a plurality of customized Mock messages are stored in the customized Mock message database, and each customized Mock message comprises conventional data and a plurality of groups of customized data; determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message; determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message; and finally, respectively providing the target test data to the test script for script test to obtain a plurality of test results. In the embodiment, one customized Mock message comprises a plurality of groups of customized data, and each group of customized data and conventional data can construct one test data, so that one customized Mock message in the scheme can correspond to a plurality of test cases, and one test request can return a plurality of test results, so that the scheme can improve the test efficiency of the script.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a Mock service-based script testing method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a Mock service-based script testing method according to an embodiment of the present application;
FIG. 3 is a schematic sub-flow chart of a script testing method based on Mock service according to an embodiment of the present application;
FIG. 4 is a schematic sub-flow chart of another method for testing a script based on a Mock service according to an embodiment of the present application;
FIG. 5 is a schematic block diagram of a Mock service-based script testing device provided by an embodiment of the present application;
FIG. 6 is a schematic block diagram of a Mock service based script test device according to another embodiment of the present application;
fig. 7 is a schematic block diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
The embodiment of the application provides a script testing method, device, equipment and medium based on Mock service.
The execution main body of the script testing method based on the Mock service can be the script testing device based on the Mock service provided by the embodiment of the application or the computer equipment integrated with the script testing device based on the Mock service, wherein the script testing device based on the Mock service can be realized in a hardware or software mode, the computer equipment can be a terminal or a server, and the terminal can be a tablet computer, a palm computer, a notebook computer or the like.
Referring to fig. 1, fig. 1 is a schematic view of an application scenario of a Mock service-based script testing method according to an embodiment of the present application. The script testing method based on the Mock service is applied to the computer equipment 10 in fig. 1, wherein the computer equipment 10 obtains a testing request of a testing script of a user, and the testing request comprises a service identifier and a plurality of request parameters; determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data; determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message; determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message; and respectively providing the target test data to the test script for script test to obtain a plurality of test results.
Fig. 2 is a schematic flowchart of a Mock service-based script testing method according to an embodiment of the present application. The following describes the present embodiment in detail by taking a Mock-based script test device (hereinafter referred to as a test device) as an execution subject, and as shown in fig. 2, the method includes the following steps S110 to S150.
S110, obtaining a test request of the test script, wherein the test request comprises a service identifier and a plurality of request parameters.
In this embodiment, when a user needs to test a test script, a test request of the test script needs to be sent to the test apparatus to obtain corresponding test data.
The user can input a test request in the test device when the test script needs to be tested, or can preset the test request and set a timer corresponding to the test request, and when a certain preset time (for example, 12 o' clock at night) is reached, the test device is automatically triggered to acquire the test request of the test script.
The service identifier may be a service code of the service or other identity identifiers that can uniquely and definitely represent the service type, and the request parameter may be a user number, a mobile phone number, a transaction amount, and the like.
Before performing step S110, the method further includes: and acquiring a Mock message blank template corresponding to the service identifier from a Mock platform, receiving filling data input by a user according to the Mock message blank template, generating a customized Mock message to be stored according to the blank template and the filling data, and storing the customized Mock message to be stored into the customized Mock message database.
In some embodiments, the blank template includes a regular data area and a customized data area corresponding to the service identifier, where the customized data area is an area to be filled, and a user may input filling data in the customized data area in the blank template of a Mock message, so as to generate a customized Mock message to be stored.
The step of storing the customized Mock message to be stored into the customized Mock message database specifically comprises the following steps: judging whether a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database; if the customized Mock message with the same service identifier as the customized Mock message to be stored does not exist in the customized Mock message database, adding the customized Mock message to be stored into the customized Mock message database;
if a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database, determining the customized Mock message as a target customized message; judging whether the target customized message has the same request parameters as those of the customized Mock message to be stored; and if the request parameters which are the same as the request parameters of the customized Mock message to be stored do not exist in the target customized message, adding the request parameters into the target customized message, and if the request parameters which are the same as the request parameters of the customized Mock message to be stored exist in the target customized message, not storing the customized Mock message to be stored.
And S120, determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data.
After receiving the test request, the target customized Mock message corresponding to the service identifier needs to be searched from the customized Mock message database.
In some embodiments, if a target customized Mock message corresponding to a service identifier is not found in a customized Mock message database, at this time, a target conventional Mock message corresponding to the service identifier needs to be determined from a preset conventional Mock message database; acquiring test parameters input by a user according to the target conventional Mock message; generating conventional test data according to the target conventional Mock message and the test parameters; and providing the conventional test data to the test script for script test.
The conventional Mock message database stores a plurality of conventional Mock messages, each service identifier corresponds to one conventional Mock message, each conventional Mock message comprises a request parameter part and a conventional parameter part, wherein the request parameter part can be empty or conventional parameters, and the parameter part can be modified in a specific modification mode that a corresponding target conventional Mock message is displayed to a user through a display screen, and then the user inputs test parameters in an input frame of the request parameter part, so that the test device generates conventional test data according to the test parameters and the parameters of the conventional parameter part, and performs script test of a test script by using the conventional test data.
In the embodiment, one service identifier corresponds to one method interface, each method interface corresponds to one customized Mock message, and the customized Mock message in the embodiment includes conventional data and multiple groups of customized data, and each group of customized data can be combined with the conventional data to form one piece of test data.
Referring to fig. 3, in some embodiments, specifically, step S120 includes:
and S121, acquiring the current environment configuration from the local environment configuration file.
Specifically, the current environment configuration of the test script is obtained from the env.
And S122, judging the environment type of the current environment according to the current environment configuration, if the environment type is a test environment, executing the step S123, and if the environment type is a production environment, executing the steps S124-S126.
And when the current environment of the test script is determined to be the test environment, the Mock service is called, and if the current environment of the test script is the production environment, an external message interface is called to acquire real test data in order to ensure the authenticity of the data.
S123, determining a target customized Mock message corresponding to the service identifier from the customized Mock message database.
When the current environment is determined to be the test environment, in order to avoid influencing the stability of the automatic test of the local system due to instability of test data in an external merchant, the embodiment preferentially selects to determine the test data from the customized Mock message database.
And S124, calling an external message interface according to the test request to acquire the encrypted message.
When the current environment is determined to be a production environment, at this time, in order to ensure the authenticity of data, a partner gateway needs to be called, so that an external message interface is called, and a message encrypted by an external merchant is obtained.
And S125, decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message.
The message decryption rule is a decryption rule negotiated with an external merchant, and the decryption rule corresponds to an encryption rule of the corresponding external merchant.
And S126, providing the decrypted message to the test script for script test.
Namely, the decrypted message is used as test data and is provided to a test script for script test.
S130, determining multiple groups of target customization data corresponding to the multiple request parameters from the multiple groups of customization data of the target customization Mock message.
Referring to fig. 4, in some embodiments, specifically, step S130 includes:
s131, judging whether the multiple groups of customized data in the target customized Mock message contain multiple groups of customized data corresponding to the multiple request parameters, if so, executing the step S132, and if not, executing the steps S133-S136.
In this embodiment, the target customized Mock message includes multiple sets of customized data, and in this step, it needs to be determined whether the multiple sets of customized data included in the target customized Mock message include customized data corresponding to each request parameter in the multiple request parameters in the test request, that is, whether each request parameter can find corresponding customized data in the multiple sets of customized data is determined.
S132, determining multiple sets of customization data corresponding to the multiple request parameters as multiple sets of target customization data.
And if the customized data of the target customized Mock message comprises the customized data corresponding to the request parameter, determining the customized data corresponding to the request parameter as the target customized data.
For example, if the request parameter in the test request is the user number a, it is necessary to search whether the customized data of the target customized Mock message includes the customized data of the user number a, and if so, the customized data of the user number a is determined as the target customized data.
In some embodiments, if the customized data of the target customized Mock message does not include the customized data corresponding to the request parameter, the following steps are performed:
s133, determining a target conventional Mock message corresponding to the service identifier from a preset conventional Mock message database.
In this embodiment, if the customized data of the target customized Mock message does not include the customized data corresponding to the request parameter, for example, the customized data of the target customized Mock message does not include the customized data corresponding to one or more request parameters, at this time, in order to ensure the correct operation of the test, the use of the full-automatic customized Mock message is abandoned, and the target conventional Mock message corresponding to the service identifier is determined from the preset conventional Mock message database by using the semi-manual test.
The conventional Mock message database stores a plurality of conventional Mock messages, and each service identifier corresponds to one conventional Mock message.
In some embodiments, if a target conventional Mock message corresponding to the service identifier does not exist in the conventional Mock message database, at this time, the external message interface needs to be called to obtain the test data.
And S134, acquiring the test parameters input by the user according to the target conventional Mock message.
Each conventional Mock message comprises a request parameter part and a conventional parameter part, wherein the request parameter part can be empty or conventional parameters, and the parameter part can be modified in a way that a corresponding target conventional Mock message is displayed to a user through a display screen, and then the user inputs test parameters in an input box of the request parameter part.
And S135, generating conventional test data according to the target conventional Mock message and the test parameters.
And when a user inputs test parameters and clicks to upload, generating conventional test data according to the target conventional Mock message and the test parameters.
And S136, providing the conventional test data to the test script for script test.
After the regular test data is generated, the regular test data is provided to a test script for script testing.
S140, determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message.
And when the target customization data is determined, combining the target customization data and the conventional data in the target customization Mock message into the currently required target test data.
S150, respectively providing the target test data to the test script for script test to obtain a plurality of test results.
After the target test data are determined, the target test data are respectively provided for the test script to perform script test, at this time, the test script can perform script test respectively according to the target test data to obtain a test result corresponding to each target test data, and one test data corresponds to one test result.
For example, the plurality of request parameters carried in the test request include a first request parameter and a second request parameter, and at this time, first target customization data corresponding to the first request parameter is determined from the target customization Mock message, and second target customization data corresponding to the second request parameter is determined from the target customization Mock message. And then determining first target test data according to the first target customization data and the conventional data in the target customization Mock message, and determining second target test data according to the second target customization data and the conventional data in the target customization Mock message.
If the first request parameter is 'user number is a', the second request parameter is 'user number is B', and the first target customization data is obtained by searching the customization data in the target customization Mock message: when the user number is a, a "success" result is returned, and the second target customization data is: when the user number is B, a "failure" result is returned. Therefore, different test cases can be generated according to different target customization data, and each test case can obtain a desired result.
It can be seen that, in this embodiment, one customized Mock message may support multiple test cases, and one test request may request to execute multiple test cases, so as to improve the efficiency of the automated test.
In some embodiments, the test script includes a plurality of test sub-scripts, and step S150 further specifically includes: determining the test sub-script corresponding to each target test data according to the corresponding relation between the preset test sub-script and the customized data; and respectively providing the target test data to the corresponding test sub-scripts for script test to obtain test results respectively corresponding to the test sub-scripts.
Therefore, the target test data can be provided for one test script to perform script test, in some embodiments, the target test data can be provided for a plurality of test scripts to perform script test, and test cases corresponding to the test scripts are generated for different test scripts.
The testing device in the embodiment sets a switchable switch for the Mock service, the Mock service is called when the switch of the Mock service is switched on, and otherwise, the external message interface is directly called.
To sum up, the present embodiment obtains a test request of a test script, where the test request includes a service identifier and a plurality of request parameters; then determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein a plurality of customized Mock messages are stored in the customized Mock message database, and each customized Mock message comprises conventional data and a plurality of groups of customized data; determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message; determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message; and finally, respectively providing the target test data to the test script for script test to obtain a plurality of test results. In the embodiment, one customized Mock message comprises a plurality of groups of customized data, and each group of customized data and conventional data can construct one test data, so that one customized Mock message in the scheme can correspond to a plurality of test cases, and one test request can return a plurality of test results, so that the scheme can improve the test efficiency of the script.
FIG. 5 is a schematic block diagram of a Mock service-based script testing device according to an embodiment of the present application. As shown in fig. 5, the present application also provides a script testing apparatus based on Mock service, corresponding to the above script testing method based on Mock service. The Mock service-based script testing device comprises a unit for executing the Mock service-based script testing method, and can be configured in a desktop computer, a tablet computer, a portable computer and other terminals. Specifically, referring to fig. 5, the Mock service based script testing apparatus includes a first obtaining unit 501, a first determining unit 502, a second determining unit 503, a third determining unit 504, and a testing unit 505.
A first obtaining unit 501, configured to obtain a test request of a test script, where the test request includes a service identifier and a plurality of request parameters;
a first determining unit 502, configured to determine, based on the test request, a target customized Mock message corresponding to the service identifier from a preset customized Mock message database, where the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message includes conventional data and multiple sets of customized data;
a second determining unit 503, configured to determine multiple sets of target customized data corresponding to multiple request parameters from multiple sets of customized data of the target customized Mock packet;
a third determining unit 504, configured to determine multiple target test data according to multiple sets of the target customized data and conventional data in the target customized Mock message;
the test unit 505 is configured to provide each target test data to the test script for performing a script test, so as to obtain a plurality of test results.
In some embodiments, the second determining unit 503 is specifically configured to:
judging whether a plurality of groups of customized data corresponding to the request parameters are contained in the plurality of groups of customized data in the target customized Mock message;
and if the multiple groups of customized data in the target customized Mock message comprise multiple groups of customized data corresponding to the multiple request parameters, determining the multiple groups of customized data corresponding to the multiple request parameters as the multiple groups of target customized data.
In some embodiments, after the step of determining whether multiple sets of customized data in the target customized Mock message include multiple sets of customized data corresponding to multiple request parameters, the second determining unit 503 is further configured to:
if the multiple groups of customized data in the target customized Mock message do not contain multiple groups of customized data corresponding to the multiple request parameters, determining a target conventional Mock message corresponding to the service identifier from a preset conventional Mock message database;
acquiring test parameters input by a user according to the target conventional Mock message;
generating conventional test data according to the target conventional Mock message and the test parameters;
and providing the conventional test data to the test script for script test.
In some embodiments, the first determining unit 502 is specifically configured to:
acquiring current environment configuration from a local environment configuration file;
judging the environment type of the current environment according to the current environment configuration;
and if the environment type is a test environment, determining a target customized Mock message corresponding to the service identifier from the customized Mock message database.
In some embodiments, after the step of determining the environment type of the current environment according to the current environment configuration, the first determining unit 502 is further configured to:
if the environment type is a production environment, calling an external message interface according to the test request to acquire an encrypted message;
decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;
and providing the decrypted message to the test script for script test.
In some embodiments, the test script includes a plurality of test sub-scripts, and the test unit 505 is specifically configured to:
determining the test sub-script corresponding to each target test data according to the corresponding relation between the preset test sub-script and the customized data;
and respectively providing the target test data to the corresponding test sub-scripts for script test to obtain test results respectively corresponding to the test sub-scripts.
FIG. 6 is a schematic block diagram of a Mock service-based script testing device according to another embodiment of the present application. As shown in fig. 6, the Mock service-based script testing apparatus of the present embodiment is the second acquiring unit 506, the receiving unit 507, the generating unit 508 and the storing unit 509 added to the above embodiment.
A second obtaining unit 506, configured to obtain a Mock message blank template corresponding to the service identifier from a Mock platform;
a receiving unit 507, configured to receive padding data input by a user according to the Mock message blank template;
a generating unit 508, configured to generate a customized Mock message to be stored according to the blank template and the padding data;
and a storing unit 509, configured to store the customized Mock message to be stored into the customized Mock message database.
In some embodiments, the logging unit 509 is specifically configured to:
judging whether a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database;
if the customized Mock message with the same service identifier as the customized Mock message to be stored does not exist in the customized Mock message database, adding the customized Mock message to be stored into the customized Mock message database;
if a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database, determining the customized Mock message as a target customized message;
judging whether the target customized message has the same request parameters as those of the customized Mock message to be stored;
and if the request parameters which are the same as the request parameters of the customized Mock message to be stored do not exist in the target customized message, adding the request parameters into the target customized message.
It should be noted that, as can be clearly understood by those skilled in the art, the above-mentioned Mock service-based script testing device and the specific implementation process of each unit may refer to the corresponding description in the foregoing method embodiment, and for convenience and brevity of description, no further description is provided herein.
The above-mentioned Mock service-based script test apparatus may be implemented in the form of a computer program that can be run on a computer device as shown in fig. 7.
Referring to fig. 7, fig. 7 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 700 may be a terminal or a server, where the terminal may be an electronic device with a communication function, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device. The server may be an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 7, the computer device 700 includes a processor 702, memory, and a network interface 705 coupled via a system bus 701, where the memory may include a non-volatile storage medium 703 and an internal memory 704.
The non-volatile storage medium 703 may store an operating system 7031 and a computer program 7032. The computer program 7032 comprises program instructions that, when executed, cause the processor 702 to perform a method for scripting test based on Mock services.
The processor 702 is configured to provide computing and control capabilities to support the operation of the overall computer device 700.
The internal memory 704 provides an environment for running a computer program 7032 on the non-volatile storage medium 703, and the computer program 7032, when executed by the processor 702, causes the processor 702 to execute a Mock service-based script test method.
The network interface 705 is used for network communication with other devices. Those skilled in the art will appreciate that the architecture shown in fig. 7 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing device 700 to which the disclosed aspects apply, as a particular computing device 700 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
Wherein the processor 702 is configured to run a computer program 7032 stored in the memory to perform the steps of:
acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters;
determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data;
determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message;
determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message;
and respectively providing the target test data to the test script for script test to obtain a plurality of test results.
In some embodiments, before implementing the step of determining multiple sets of target customized data corresponding to multiple request parameters from multiple sets of customized data of the target customized Mock message, the processor 702 further implements the following steps:
judging whether a plurality of groups of customized data corresponding to the request parameters are contained in the plurality of groups of customized data in the target customized Mock message;
if the multiple groups of customized data in the target customized Mock message comprise multiple groups of customized data corresponding to the multiple request parameters, the step of determining the multiple groups of target customized data corresponding to the multiple request parameters from the multiple groups of customized data in the target customized Mock message is executed;
if the multiple groups of customized data in the target customized Mock message do not contain multiple groups of customized data corresponding to the multiple request parameters, determining a target conventional Mock message corresponding to the service identifier from a preset conventional Mock message database;
acquiring test parameters input by a user according to the target conventional Mock message;
generating conventional test data according to the target conventional Mock message and the test parameters;
and providing the conventional test data to the test script for script test.
In some embodiments, when the step of determining the target customized Mock message corresponding to the service identifier from the preset customized Mock message database is implemented, the processor 702 specifically implements the following steps:
acquiring current environment configuration from a local environment configuration file;
judging the environment type of the current environment according to the current environment configuration;
and if the environment type is a test environment, determining a target customized Mock message corresponding to the service identifier from the customized Mock message database.
In some embodiments, after the step of determining the environment type of the current environment according to the current environment configuration is performed, the processor 702 further performs the following steps:
if the environment type is a production environment, calling an external message interface according to the test request to acquire an encrypted message;
decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;
and providing the decrypted message to the test script for script test.
In some embodiments, the test script includes a plurality of test sub-scripts, and when the step of providing each target test data to the test script for script testing to obtain a plurality of test results is implemented by the processor 702, the following steps are specifically implemented:
determining the test sub-script corresponding to each target test data according to the corresponding relation between the preset test sub-script and the customized data;
and respectively providing the target test data to the corresponding test sub-scripts for script test to obtain test results respectively corresponding to the test sub-scripts.
In some embodiments, the processor 702, before implementing the step of obtaining a test request of a test script, further implements the steps of:
acquiring a Mock message blank template corresponding to the service identifier from a Mock platform;
receiving filling data input by a user according to the Mock message blank template;
generating a customized Mock message to be stored according to the blank template and the filling data;
and storing the customized Mock message to be stored into the customized Mock message database.
In some embodiments, when the step of storing the customized Mock message to be stored in the customized Mock message database is implemented, the processor 702 specifically implements the following steps:
judging whether a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database;
if the customized Mock message with the same service identifier as the customized Mock message to be stored does not exist in the customized Mock message database, adding the customized Mock message to be stored into the customized Mock message database;
if a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database, determining the customized Mock message as a target customized message;
judging whether the target customized message has the same request parameters as those of the customized Mock message to be stored;
and if the request parameters which are the same as the request parameters of the customized Mock message to be stored do not exist in the target customized message, adding the request parameters into the target customized message.
It should be understood that, in the embodiment of the present Application, the Processor 702 may be a Central Processing Unit (CPU), and the Processor 702 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be understood by those skilled in the art that all or part of the flow of the method implementing the above embodiments may be implemented by a computer program instructing associated hardware. The computer program includes program instructions, and the computer program may be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the flow steps of the embodiments of the method described above.
Accordingly, the present application also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program comprises program instructions. The program instructions, when executed by the processor, cause the processor to perform the steps of:
acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters;
determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data;
determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message;
determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message;
and respectively providing the target test data to the test script for script test to obtain a plurality of test results.
In some embodiments, before executing the program instructions to implement the step of determining multiple sets of target customized data corresponding to multiple request parameters from multiple sets of customized data of the target customized Mock message, the processor further implements the following steps:
judging whether a plurality of groups of customized data corresponding to the request parameters are contained in the plurality of groups of customized data in the target customized Mock message;
if the multiple groups of customized data in the target customized Mock message comprise multiple groups of customized data corresponding to the multiple request parameters, the step of determining the multiple groups of target customized data corresponding to the multiple request parameters from the multiple groups of customized data in the target customized Mock message is executed;
if the multiple groups of customized data in the target customized Mock message do not contain multiple groups of customized data corresponding to the multiple request parameters, determining a target conventional Mock message corresponding to the service identifier from a preset conventional Mock message database;
acquiring test parameters input by a user according to the target conventional Mock message;
generating conventional test data according to the target conventional Mock message and the test parameters;
and providing the conventional test data to the test script for script test.
In some embodiments, when the processor executes the program instruction to determine the target customized Mock message corresponding to the service identifier from the preset customized Mock message database, the following steps are specifically implemented:
acquiring current environment configuration from a local environment configuration file;
judging the environment type of the current environment according to the current environment configuration;
and if the environment type is a test environment, determining a target customized Mock message corresponding to the service identifier from the customized Mock message database.
In some embodiments, after executing the program instructions to implement the determining a context type of the current context according to the current context configuration step, the processor further implements the following steps:
if the environment type is a production environment, calling an external message interface according to the test request to acquire an encrypted message;
decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;
and providing the decrypted message to the test script for script test.
In some embodiments, the test script includes a plurality of test sub-scripts, and when the processor executes the step of providing each of the target test data to the test script respectively for performing the script test to obtain a plurality of test results, the following steps are specifically implemented:
determining the test sub-script corresponding to each target test data according to the corresponding relation between the preset test sub-script and the customized data;
and respectively providing the target test data to the corresponding test sub-scripts for script test to obtain test results respectively corresponding to the test sub-scripts.
In some embodiments, the processor further performs the following steps before executing the program instructions to perform the step of obtaining a test request for a test script:
acquiring a Mock message blank template corresponding to the service identifier from a Mock platform;
receiving filling data input by a user according to the Mock message blank template;
generating a customized Mock message to be stored according to the blank template and the filling data;
and storing the customized Mock message to be stored into the customized Mock message database.
In some embodiments, when the processor executes the program instruction to store the customized Mock message to be stored in the customized Mock message database, the following steps are specifically implemented:
judging whether a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database;
if the customized Mock message with the same service identifier as the customized Mock message to be stored does not exist in the customized Mock message database, adding the customized Mock message to be stored into the customized Mock message database;
if a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database, determining the customized Mock message as a target customized message;
judging whether the target customized message has the same request parameters as those of the customized Mock message to be stored;
and if the request parameters which are the same as the request parameters of the customized Mock message to be stored do not exist in the target customized message, adding the request parameters into the target customized message.
The storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk, which can store various computer readable storage media.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, various elements or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented.
The steps in the method of the embodiment of the application can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the application can be combined, divided and deleted according to actual needs. In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present application may be substantially or partially implemented in the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application.
While the invention has been described with reference to specific embodiments, the scope of the invention is not limited thereto, and those skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the invention. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A script test method based on Mock service is characterized by comprising the following steps:
acquiring a test request of a test script, wherein the test request comprises a service identifier and a plurality of request parameters;
determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, wherein the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message comprises conventional data and a plurality of groups of customized data;
determining multiple groups of target customization data corresponding to the multiple request parameters from multiple groups of customization data of the target customization Mock message;
determining a plurality of target test data according to the plurality of groups of target customization data and the conventional data in the target customization Mock message;
and respectively providing the target test data to the test script for script test to obtain a plurality of test results.
2. The method according to claim 1, wherein before determining the plurality of sets of target customized data corresponding to the plurality of request parameters from the plurality of sets of customized data of the target customized Mock message, the method further comprises:
judging whether a plurality of groups of customized data corresponding to the request parameters are contained in the plurality of groups of customized data in the target customized Mock message;
if the multiple groups of customized data in the target customized Mock message comprise multiple groups of customized data corresponding to the multiple request parameters, the step of determining the multiple groups of target customized data corresponding to the multiple request parameters from the multiple groups of customized data in the target customized Mock message is executed;
if the multiple groups of customized data in the target customized Mock message do not contain multiple groups of customized data corresponding to the multiple request parameters, determining a target conventional Mock message corresponding to the service identifier from a preset conventional Mock message database;
acquiring test parameters input by a user according to the target conventional Mock message;
generating conventional test data according to the target conventional Mock message and the test parameters;
and providing the conventional test data to the test script for script test.
3. The method according to claim 1, wherein the determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database comprises:
acquiring current environment configuration from a local environment configuration file;
judging the environment type of the current environment according to the current environment configuration;
and if the environment type is a test environment, determining a target customized Mock message corresponding to the service identifier from the customized Mock message database.
4. The method of claim 3, wherein after determining the environment type of the current environment according to the current environment configuration, the method further comprises:
if the environment type is a production environment, calling an external message interface according to the test request to acquire an encrypted message;
decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;
and providing the decrypted message to the test script for script test.
5. The method of claim 1, wherein the test script comprises a plurality of test sub-scripts, and the providing each target test data to the test script for script testing to obtain a plurality of test results comprises:
determining the test sub-script corresponding to each target test data according to the corresponding relation between the preset test sub-script and the customized data;
and respectively providing the target test data to the corresponding test sub-scripts for script test to obtain test results respectively corresponding to the test sub-scripts.
6. The method of any of claims 1-5, wherein prior to obtaining the test request for the test script, the method further comprises:
acquiring a Mock message blank template corresponding to the service identifier from a Mock platform;
receiving filling data input by a user according to the Mock message blank template;
generating a customized Mock message to be stored according to the blank template and the filling data;
and storing the customized Mock message to be stored into the customized Mock message database.
7. The method according to claim 6, wherein the storing the customized Mock message to be stored into the customized Mock message database comprises:
judging whether a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database;
if the customized Mock message with the same service identifier as the customized Mock message to be stored does not exist in the customized Mock message database, adding the customized Mock message to be stored into the customized Mock message database;
if a customized Mock message with the same service identifier as the customized Mock message to be stored exists in the customized Mock message database, determining the customized Mock message as a target customized message;
judging whether the target customized message has the same request parameters as those of the customized Mock message to be stored;
and if the request parameters which are the same as the request parameters of the customized Mock message to be stored do not exist in the target customized message, adding the request parameters into the target customized message.
8. A script testing device based on Mock service is characterized by comprising:
the device comprises a first acquisition unit, a second acquisition unit and a control unit, wherein the first acquisition unit is used for acquiring a test request of a test script, and the test request comprises a service identifier and a plurality of request parameters;
a first determining unit, configured to determine, based on the test request, a target customized Mock message corresponding to the service identifier from a preset customized Mock message database, where the customized Mock message database stores a plurality of customized Mock messages, and each customized Mock message includes conventional data and multiple sets of customized data;
a second determining unit, configured to determine multiple sets of target customization data corresponding to the multiple request parameters from multiple sets of customization data of the target customization Mock packet;
a third determining unit, configured to determine multiple target test data according to the multiple sets of target customization data and the conventional data in the target customization Mock message;
and the test unit is used for respectively providing the target test data to the test script for script test to obtain a plurality of test results.
9. A computer arrangement, characterized in that the computer arrangement comprises a memory having stored thereon a computer program and a processor implementing the method according to any of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, characterized in that the storage medium stores a computer program comprising program instructions which, when executed by a processor, implement the method according to any one of claims 1-7.
CN202111443013.2A 2021-11-30 2021-11-30 Script testing method, device, equipment and medium based on Mock service Pending CN114003510A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111443013.2A CN114003510A (en) 2021-11-30 2021-11-30 Script testing method, device, equipment and medium based on Mock service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111443013.2A CN114003510A (en) 2021-11-30 2021-11-30 Script testing method, device, equipment and medium based on Mock service

Publications (1)

Publication Number Publication Date
CN114003510A true CN114003510A (en) 2022-02-01

Family

ID=79930877

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111443013.2A Pending CN114003510A (en) 2021-11-30 2021-11-30 Script testing method, device, equipment and medium based on Mock service

Country Status (1)

Country Link
CN (1) CN114003510A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114817068A (en) * 2022-05-25 2022-07-29 云账户技术(天津)有限公司 Interface testing method and device based on mock test and electronic equipment
CN114900569A (en) * 2022-05-17 2022-08-12 中国银行股份有限公司 Method and device for acquiring test script
CN114900569B (en) * 2022-05-17 2024-05-03 中国银行股份有限公司 Test script acquisition method and device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114900569A (en) * 2022-05-17 2022-08-12 中国银行股份有限公司 Method and device for acquiring test script
CN114900569B (en) * 2022-05-17 2024-05-03 中国银行股份有限公司 Test script acquisition method and device
CN114817068A (en) * 2022-05-25 2022-07-29 云账户技术(天津)有限公司 Interface testing method and device based on mock test and electronic equipment

Similar Documents

Publication Publication Date Title
US10387856B2 (en) Online payment method, system, and apparatus
US10656939B2 (en) Modeling lifetime of hybrid software application using application manifest
CN110474820B (en) Flow playback method and device and electronic equipment
CN114257551A (en) Distributed current limiting method and system and storage medium
CN112631686A (en) Data processing method, data processing device, computer equipment and storage medium
CN113157345A (en) Automatic starting method and device for front-end engineering
CN109428900B (en) Data processing method and device
CN114003510A (en) Script testing method, device, equipment and medium based on Mock service
CN110858242A (en) Page skipping method and device
CN110162322A (en) A kind of upgrade method and device
CN113158196A (en) Login verification method, device, equipment and medium
CN112650689A (en) Test method, test device, electronic equipment and storage medium
CN110278241B (en) Registration request processing method and device
CN111597093B (en) Exception handling method, device and equipment thereof
CN115390939B (en) Service processing method and system
CN114390105A (en) Enterprise user distribution method and device based on test
US11816714B2 (en) Service verification method and apparatus
CN112732547B (en) Service testing method and device, storage medium and electronic equipment
CN110381150B (en) Data processing method and device on block chain, electronic equipment and storage medium
CN109918300B (en) Test data preparation method, device, terminal and storage medium
CN110580200A (en) Data synchronization method and device
CN113050985A (en) Front-end engineering dependence automatic registration method and device
CN112650763A (en) Configuration method of product quota, related equipment and storage medium
CN106547626B (en) Method for balancing server in peer-to-peer architecture and server
CN110955464A (en) Service processing method and device, computer equipment and 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