Mock service-based script testing method, device, equipment and medium

By constructing multiple combinations of customized and regular data in the Mock service, the problem of low efficiency of a single Mock interface in the existing technology is solved, and efficient execution of multi-test cases is achieved, improving the stability and efficiency of automated testing.

CN114003510BActive Publication Date: 2026-01-23PING AN PAY ELECTRONIC PAYMENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111443013.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-30
Publication Date
2026-01-23
Estimated Expiration
2041-11-30

AI Technical Summary

Technical Problem

In existing technologies, since one request corresponds to one Mock service interface, and each Mock service interface can only return one result, the testing efficiency is low and it cannot meet the needs of multiple test cases.

Method used

By obtaining the business identifier and request parameters from the test request, the target customized Mock message is determined from the preset customized Mock message database. Multiple test data are constructed using the regular data and multiple sets of customized data in the message, so that one customized Mock message corresponds to multiple test cases.

Benefits of technology

It improves testing efficiency, saves storage space for Mock messages, and can handle multiple test cases simultaneously, thus improving the stability and efficiency of automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114003510B_ABST
    Figure CN114003510B_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a script testing method and device based on a Mock service, equipment and a medium. The method comprises the following steps: obtaining a test request of a test script, the test request comprising a business identifier and a plurality of request parameters; then determining a target customized Mock message corresponding to the business identifier from a preset customized Mock message database based on the test request, the customized Mock message database storing a plurality of customized Mock messages, each customized Mock message comprising regular data and a plurality of sets of customized data; determining a 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; determining a plurality of target test data according to the plurality of sets of target customized data and the regular data in the target customized Mock message; and finally providing each target test data to the test script for script testing to obtain a plurality of test results. The scheme can improve the testing efficiency of the script.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of automatic testing, in particular to a script testing method and device based on a Mock service, equipment and a medium. BACKGROUND

[0002] In the process of development and expansion of a financial enterprise, the local system usually needs to interact with multiple capital parties for information, for example, in the loan process, the system of external merchants such as banks and securities companies needs to be connected, at this time, the local system needs to support the test of external merchants to test whether the local system meets the requirements of external merchants, but due to the replacement of the connection address of the test environment of external merchants, the cleaning and unauthorized modification of test data, etc., the test data of external merchants is unstable, which seriously affects the stability of the automatic test of the local system.

[0003] In order to solve the above problems, the prior art provides a solution method, which uses Mock to simulate external return messages to solve the environment problem. Mock usually refers to constructing some fake objects to simulate the interaction with object A when testing object A, and the behavior of these Mock objects is set in advance and meets the expectation.

[0004] 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 meet one test case, so one request can only return one result, and the test efficiency is low. SUMMARY

[0005] The embodiments of the present application provide a script testing method and device based on a Mock service, equipment and a medium, which can improve the test efficiency.

[0006] In a first aspect, the embodiments of the present application provide a script testing method based on a Mock service, which includes:

[0007] Obtaining a test request of a test script, the test request including a business identifier and multiple request parameters;

[0008] Based on the test request, determining a target customized Mock message corresponding to the business identifier from a preset customized Mock message database, the customized Mock message database storing multiple customized Mock messages, each customized Mock message including regular data and multiple sets of customized data;

[0009] From the multiple sets of customized data of the target customized Mock message, determining multiple sets of target customized data corresponding to the multiple request parameters;

[0010] determine a plurality of target test data according to the plurality of groups of target customization data and the regular data in the target customization Mock message;

[0011] provide each of the target test data to the test script for script testing to obtain a plurality of test results.

[0012] In a second aspect, the embodiments of the present application further provide a script testing device based on a Mock service, which comprises:

[0013] a first obtaining unit, configured to obtain a test request of a test script, the test request comprising a service identifier and a plurality of request parameters;

[0014] a first determining unit, configured to determine a target customization Mock message corresponding to the service identifier from a preset customization Mock message database based on the test request, the customization Mock message database storing a plurality of customization Mock messages, each of the customization Mock messages comprising regular data and a plurality of groups of customization data;

[0015] a second determining unit, configured to determine a plurality of groups of target customization data corresponding to the plurality of request parameters from the plurality of groups of customization data of the target customization Mock message;

[0016] a third determining unit, configured to determine a plurality of target test data according to the plurality of groups of target customization data and the regular data in the target customization Mock message;

[0017] a testing unit, configured to provide each of the target test data to the test script for script testing to obtain a plurality of test results.

[0018] In a third aspect, the embodiments of the present application further provide a computer device, comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above method when executing the computer program.

[0019] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, the storage medium storing a computer program, the computer program comprising program instructions, and the program instructions being executable by a processor to implement the above method.

[0020] The embodiment of the application provides a script testing method, device and equipment based on a Mock service and a medium. The method comprises the following steps: obtaining a test request of a test script, wherein the test request comprises a business identifier and a plurality of request parameters; determining a target customized Mock message corresponding to the business 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 general data and a plurality of sets of customized data; determining a 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; determining a plurality of target test data according to the plurality of sets of target customized data and the general data in the target customized Mock message; and finally providing each target test data to the test script for script testing to obtain a plurality of test results. One customized Mock message in the embodiment contains a plurality of sets of customized data, each set of customized data can construct a test data with the general data, so one customized Mock message can correspond to a plurality of test cases in the scheme, one test request can return a plurality of test results, and therefore the script testing efficiency can be improved. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can also be obtained by those skilled in the art without any creative effort on the basis of these drawings.

[0022] Figure 1 The application scenario of the script testing method based on the Mock service provided by the embodiment of the application is shown in the figure.

[0023] Figure 2 The flowchart of the script testing method based on the Mock service provided by the embodiment of the application is shown in the figure.

[0024] Figure 3 The sub-flowchart of the script testing method based on the Mock service provided by the embodiment of the application is shown in the figure.

[0025] Figure 4 The sub-flowchart of the script testing method based on the Mock service provided by the embodiment of the application is shown in the figure.

[0026] Figure 5 The schematic block diagram of the script testing device based on the Mock service provided by the embodiment of the application is shown in the figure.

[0027] Figure 6A schematic block diagram of a script testing device based on a Mock service according to another embodiment of the present application is provided.

[0028] Figure 7 A schematic block diagram of a computer device according to an embodiment of the present application is provided. DETAILED DESCRIPTION

[0029] 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. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.

[0030] It should be understood that, when used in the specification and the appended claims, the terms "comprise" and "include" indicate the presence of the described features, integers, steps, operations, elements, and / or components, but do not exclude one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0031] It should also be understood that the terms used in the specification of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and the appended claims of the present application, the singular forms "a", "an" and "the" are intended to include the plural forms unless the context clearly indicates otherwise.

[0032] It should be further understood that the term "and / or" used in the specification and the appended claims of the present application means any combination of one or more of the associated listed items and all possible combinations thereof, and includes these combinations.

[0033] The embodiments of the present application provide a script testing method, device, equipment and medium based on a Mock service.

[0034] The execution subject of the script testing method based on a Mock service can be a script testing device based on a Mock service according to an embodiment of the present application, or a computer device integrated with the script testing device based on a Mock service. The script testing device based on a Mock service can be implemented in a hardware or software manner, and the computer device can be a terminal or a server. The terminal can be a tablet computer, a palm computer, or a notebook computer, etc.

[0035] Please refer to Figure 1 , Figure 1 An application scenario diagram of a script testing method based on a Mock service according to an embodiment of the present application is provided. The script testing method based on a Mock service is applied toFigure 1 In the computer device 10 in the computer device 10, the computer device 10 obtains a test request of a test script of a user, the test request includes a business identity and a plurality of request parameters; based on the test request, a target customized Mock message corresponding to the business identity is determined from a preset customized Mock message database, the customized Mock message database stores a plurality of customized Mock messages, each of the customized Mock messages includes regular data and a plurality of groups of customized data; a plurality of groups of target customized data corresponding to the plurality of request parameters is determined from the plurality of groups of customized data of the target customized Mock message; a plurality of target test data is determined according to the plurality of groups of target customized data and the regular data in the target customized Mock message; each of the target test data is provided to the test script for script testing, and a plurality of test results is obtained.

[0036] Figure 2 It is a flowchart of a script testing method based on a Mock service provided by the embodiment of the application. The following takes a script testing device based on a Mock service (hereinafter referred to as a testing device) as an execution subject to illustrate the scheme in detail, as shown in FIG. 1, the method includes the following steps S110-S150. Figure 2

[0037] S110, obtaining a test request of a test script, the test request including a business identity and a plurality of request parameters.

[0038] In the embodiment, when a user needs to test a test script, the user needs to send a test request of the test script to the testing device to obtain corresponding test data.

[0039] The user can input a test request in the testing device when the user needs to test a test script, or the user can preset a test request and set a timer corresponding to the test request, and when a preset time (for example, 12 o'clock at night) is reached, the testing device automatically obtains a test request of a test script.

[0040] The business identity can be a service code of a business, or other identity that can uniquely represent a business type, and the request parameter can be a user number, a mobile phone number, and a transaction amount.

[0041] Before step S110 is executed, the method further includes: obtaining a Mock message blank template corresponding to the business identity from a Mock platform, then receiving filling data input by a user according to the Mock message blank template, generating a to-be-stored customized Mock message according to the blank template and the filling data, and storing the to-be-stored customized Mock message in the customized Mock message database.

[0042] ​In some embodiments, the blank template includes a regular data area corresponding to the service identifier and a customized data area, wherein the customized data area is a to-be-filled area, and a user can input filling data in the customized data area in the Mock message blank template, thereby generating a to-be-stored customized Mock message.

[0043] The step of storing the to-be-stored customized Mock message in the customized Mock message database specifically includes: judging whether there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database; if there is no customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, the to-be-stored customized Mock message is added to the customized Mock message database;

[0044] If there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, the customized Mock message is determined as a target customized message; it is judged whether there is a request parameter same as the request parameter of the to-be-stored customized Mock message in the target customized message; if there is no request parameter same as the request parameter of the to-be-stored customized Mock message in the target customized message, the request parameter is added to the target customized message; if there is a request parameter same as the request parameter of the to-be-stored customized Mock message in the target customized message, the to-be-stored customized Mock message is not stored at this time.

[0045] S120, based on the test request, determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database, the customized Mock message database storing a plurality of customized Mock messages, each of the customized Mock messages including regular data and a plurality of groups of customized data.

[0046] After receiving the test request, a target customized Mock message corresponding to the service identifier needs to be found from the customized Mock message database first.

[0047] In some embodiments, if a target customized Mock message corresponding to the service identifier is not found in the customized Mock message database, a target regular Mock message corresponding to the service identifier needs to be determined from a preset regular Mock message database at this time; test parameters input by a user according to the target regular Mock message are acquired; regular test data is generated according to the target regular Mock message and the test parameters; and the regular test data is provided to the test script for script testing.

[0048] The conventional Mock message database stores a plurality of conventional Mock messages, each business identifier corresponds to a conventional Mock message, and each conventional Mock message includes a request parameter part and a conventional parameter part. The request parameter part can be empty or a conventional parameter. The parameter part can be modified. The specific modification method is to display the corresponding target conventional Mock message to the user through the display screen, and then the user inputs the test parameter in the input box of the request parameter part. The test device generates conventional test data according to the test parameter and the parameters in the conventional parameter part, and performs script testing of the test script using the conventional test data.

[0049] Each business identifier corresponds to a method interface, and each method interface corresponds to a customized Mock message. Since the customized Mock message in this embodiment includes conventional data and a plurality of sets of customized data, each set of customized data can be combined with the conventional data to form a test data. Therefore, one customized Mock message in this embodiment can correspond to a plurality of test cases. It is not necessary to construct a Mock message for each test case. Therefore, the present scheme can save the storage space of the Mock message, thereby saving the memory of the local system.

[0050] Please refer to Figure 3 In some embodiments, specifically, step S120 includes:

[0051] S121, obtaining the current environment configuration from the local environment configuration file.

[0052] Specifically, the current environment configuration of the test script is obtained from the env.prop configuration file.

[0053] S122, determining the environment type of the current environment according to the current environment configuration. If the environment type is a test environment, step S123 is performed. If the environment type is a production environment, steps S124-S126 are performed.

[0054] When it is determined that the test script currently resides in a test environment, the Mock service is called. If the test script currently resides in a production environment, the external message interface is called to obtain real test data in order to ensure the authenticity of the data.

[0055] S123, determining the target customized Mock message corresponding to the business identifier from the customized Mock message database.

[0056] When it is determined that the current environment is a test environment, in order to avoid the influence of the stability of the local system automatic test caused by the unstable test data in the external merchant, the test data is preferentially selected from the customized Mock message database.

[0057] S124, calling an external message interface according to the test request to obtain an encrypted message.

[0058] When it is determined that the current environment is a production environment, at this time, in order to ensure the authenticity of the data, a cooperative merchant gateway needs to be called to obtain a message encrypted by an external merchant through the external message interface.

[0059] S125, decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message.

[0060] The message decryption rule is a decryption rule agreed with the external merchant, and the decryption rule corresponds to the encryption rule of the corresponding external merchant.

[0061] S126, providing the decrypted message to the test script for script testing.

[0062] That is, the decrypted message is provided as test data to the test script for script testing.

[0063] S130, determining a plurality of sets of target customization data corresponding to a plurality of request parameters from a plurality of sets of customization data of the target customized Mock message.

[0064] Please refer to Figure 4 In some embodiments, specifically, step S130 includes:

[0065] S131, judging whether a plurality of sets of customization data corresponding to a plurality of request parameters are contained in a plurality of sets of customization data in the target customized Mock message, if yes, executing step S132, and if no, executing steps S133-S136.

[0066] In this embodiment, the target customized Mock message contains a plurality of sets of customization data, and this step needs to judge whether the plurality of sets of customization data contained in the target customized Mock message contain customization data corresponding to each request parameter in the plurality of request parameters in the test request, that is, whether each request parameter can find corresponding customization data in the plurality of sets of customization data.

[0067] S132, determining a plurality of sets of customization data corresponding to a plurality of request parameters as a plurality of sets of target customization data.

[0068] If the customization data corresponding to the request parameter is contained in the customization data of the target customized Mock message, at this time, the customization data corresponding to the request parameter is determined as the target customization data.

[0069] For example, if the request parameter in the test request is user number = A, it is needed to check whether the custom data of the target customized Mock message contains the custom data of user number = A. If yes, the custom data of user number = A is determined as the target custom data.

[0070] In some embodiments, if the custom data corresponding to the request parameter is not contained in the custom data of the target customized Mock message, the following steps are performed:

[0071] S133, determining a target general Mock message corresponding to the service identifier from a preset general Mock message database.

[0072] In the embodiment, if the custom data corresponding to the request parameter is not contained in the custom data of the target customized Mock message, for example, one or more request parameters are not contained in the custom data of the target customized Mock message, in order to ensure the correct operation of the test, the fully automatic customized Mock message is abandoned, and a semi-automatic test is used to determine a target general Mock message corresponding to the service identifier from a preset general Mock message database.

[0073] The general Mock message database stores a plurality of general Mock messages, and each service identifier corresponds to a general Mock message.

[0074] In some embodiments, if the target general Mock message corresponding to the service identifier does not exist in the general Mock message database, it is needed to obtain the test data by calling an external message interface.

[0075] S134, obtaining test parameters input by a user according to the target general Mock message.

[0076] Each general Mock message includes a request parameter part and a general parameter part. The request parameter part can be empty or a general parameter. The parameter part can be modified. Specifically, the corresponding target general Mock message is displayed to the user through a display screen, and then the user inputs test parameters in the input box of the request parameter part.

[0077] S135, generating general test data according to the target general Mock message and the test parameters.

[0078] When the user inputs the test parameters and clicks upload, the general test data is generated according to the target general Mock message and the test parameters.

[0079] S136, providing the general test data to the test script for script testing.

[0080] After the regular test data is generated, the regular test data is provided to the test script for script testing.

[0081] S140, a plurality of target test data is determined according to a plurality of sets of the target customization data and the regular data in the target customization Mock message.

[0082] After the target customization data is determined, the target test data currently required can be combined according to the target customization data and the regular data in the target customization Mock message.

[0083] S150, each of the target test data is provided to the test script for script testing, and a plurality of test results is obtained.

[0084] After the plurality of target test data is determined, each of the target test data is provided to the test script for script testing. At this time, the test script can perform script testing according to each of the target test data, and a test result corresponding to each of the target test data is obtained, that is, one test data corresponds to one test result.

[0085] For example, the plurality of request parameters carried in the test request includes a first request parameter and a second request parameter. At this time, the first target customization data corresponding to the first request parameter is determined from the target customization Mock message, and the second target customization data corresponding to the second request parameter is determined from the target customization Mock message. Then, the first target test data is determined according to the first target customization data and the regular data in the target customization Mock message, and the second target test data is determined according to the second target customization data and the regular data in the target customization Mock message.

[0086] If the first request parameter is “user number = A” and the second request parameter is “user number = B”, it can be known from the customization data in the target customization Mock message that the first target customization data is that when the user number = A, a “success” result is returned, and the second target customization data is that when the user number = B, a “failure” result is returned. In this way, different test cases can be generated according to different target customization data, and a desired result can be obtained for each test case.

[0087] It can be seen that one customization Mock message can support a plurality of test cases in the embodiment, one test request can request to execute a plurality of test cases, thereby improving the efficiency of automatic testing, and one customization Mock message can correspond to a plurality of test cases in the embodiment, so it is not necessary to construct a Mock message for each test case, and therefore the embodiment can also save the memory for storing the Mock message.

[0088] In some embodiments, the test script includes a plurality of test subscripts, and step S150 further includes: determining, according to a preset correspondence between the test subscripts and the customized data, the test subscripts to which the target test data correspond respectively; and providing the target test data to the test subscripts respectively for script testing, to obtain test results corresponding to the test subscripts respectively.

[0089] It can be seen that the target test data in the present application can be provided to one test script for script testing, and in some embodiments, can also be provided to a plurality of test scripts respectively for script testing, test cases corresponding to different test scripts are generated, and the plurality of test scripts can simultaneously perform script testing on the test data, thereby improving the test efficiency of script testing.

[0090] In the embodiment, the test device is switchable for the Mock service, and the Mock service is called when the switch of the Mock service is turned on, otherwise, the external message interface is called directly.

[0091] In summary, the test request of the test script is obtained in the embodiment, the test request includes a business identifier and a plurality of request parameters; then, based on the test request, a target customized Mock message corresponding to the business identifier is determined from a preset customized Mock message database, the customized Mock message database stores a plurality of customized Mock messages, each customized Mock message includes regular data and a plurality of sets of customized data; a plurality of sets of target customized data corresponding to the plurality of request parameters are determined from the plurality of sets of customized data of the target customized Mock message; a plurality of target test data are determined according to the plurality of sets of target customized data and the regular data in the target customized Mock message; finally, the target test data are provided to the test script respectively for script testing, to obtain a plurality of test results. In the embodiment, one customized Mock message includes a plurality of sets of customized data, each set of customized data can construct a test data with the regular data, so one customized Mock message can correspond to a plurality of test cases in the present solution, one test request can return a plurality of test results, and therefore the test efficiency of the script can be improved.

[0092] Figure 5 is a schematic block diagram of a script testing device based on a Mock service provided by an embodiment of the present application. As shown in Figure 5 Corresponding to the above script testing method based on a Mock service, the present application also provides a script testing device based on a Mock service. The script testing device based on a Mock service includes units for executing the above script testing method based on a Mock service, and the device can be configured in a desktop computer, a tablet computer, a laptop computer, and the like. Specifically, please refer toFigure 5 The Mock service-based script testing apparatus includes a first acquisition unit 501, a first determination unit 502, a second determination unit 503, a third determination unit 504, and a testing unit 505.

[0093] The first acquisition unit 501 is configured to acquire a test request of a test script, the test request including a service identifier and a plurality of request parameters.

[0094] The first determination unit 502 is 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, the customized Mock message database storing a plurality of customized Mock messages, each of the customized Mock messages including regular data and a plurality of sets of customized data.

[0095] The second determination unit 503 is configured to determine, from the plurality of sets of customized data of the target customized Mock message, a plurality of sets of target customized data corresponding to the plurality of request parameters.

[0096] The third determination unit 504 is configured to determine, according to the plurality of sets of target customized data and the regular data in the target customized Mock message, a plurality of target test data.

[0097] The testing unit 505 is configured to provide each of the target test data to the test script for script testing, to obtain a plurality of test results.

[0098] In some embodiments, the second determination unit 503 is specifically configured to:

[0099] determine whether the plurality of sets of customized data in the target customized Mock message include a plurality of sets of customized data corresponding to the plurality of request parameters.

[0100] If the plurality of sets of customized data in the target customized Mock message include a plurality of sets of customized data corresponding to the plurality of request parameters, the plurality of sets of customized data corresponding to the plurality of request parameters are determined as the plurality of sets of target customized data.

[0101] In some embodiments, after performing the step of determining whether the plurality of sets of customized data in the target customized Mock message include a plurality of sets of customized data corresponding to the plurality of request parameters, the second determination unit 503 is further configured to:

[0102] If the plurality of sets of customized data in the target customized Mock message do not include a plurality of sets of customized data corresponding to the plurality of request parameters, a target regular Mock message corresponding to the service identifier is determined from a preset regular Mock message database.

[0103] obtaining a test parameter input by the user according to the target regular Mock message;

[0104] generating regular test data according to the target regular Mock message and the test parameter;

[0105] providing the regular test data to the test script for script testing.

[0106] In some embodiments, the first determining unit 502 is specifically configured to:

[0107] obtaining a current environment configuration from a local environment configuration file;

[0108] judging an environment type of a current environment according to the current environment configuration;

[0109] 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.

[0110] In some embodiments, after performing the step of judging the environment type of the current environment according to the current environment configuration, the first determining unit 502 is further configured to:

[0111] if the environment type is a production environment, calling an external message interface according to the test request to obtain an encrypted message;

[0112] decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;

[0113] providing the decrypted message to the test script for script testing.

[0114] In some embodiments, the test script includes a plurality of test subscripts, and the test unit 505 is specifically configured to:

[0115] determining the test subscripts corresponding to the target test data according to a preset correspondence between the test subscripts and the customized data;

[0116] providing the target test data to the corresponding test subscripts for script testing to obtain test results corresponding to the test subscripts respectively.

[0117] Figure 6 is a schematic block diagram of a script testing device based on a Mock service provided by another embodiment of the present application. As shown in the figure, Figure 6 the script testing device based on the Mock service of the present embodiment is based on the above-mentioned embodiments and additionally includes a second obtaining unit 506, a receiving unit 507, a generating unit 508 and a storing unit 509.

[0118] The second obtaining unit 506 is configured to obtain a Mock message blank template corresponding to the service identifier from the Mock platform.

[0119] The receiving unit 507 is configured to receive filling data input by a user according to the Mock message blank template.

[0120] The generating unit 508 is configured to generate a to-be-stored customized Mock message according to the blank template and the filling data.

[0121] The storing unit 509 is configured to store the to-be-stored customized Mock message in the customized Mock message database.

[0122] In some embodiments, the storing unit 509 is specifically configured to:

[0123] determine whether there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database;

[0124] if there is no customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, add the to-be-stored customized Mock message to the customized Mock message database;

[0125] if there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, determine the customized Mock message as a target customized message;

[0126] determine whether there is a request parameter same as a request parameter of the to-be-stored customized Mock message in the target customized message;

[0127] if there is no request parameter same as the request parameter of the to-be-stored customized Mock message in the target customized message, add the request parameter to the target customized message.

[0128] It should be noted that the specific implementation process of the above-mentioned Mock service-based script test device and each unit can be clearly understood by those skilled in the art, which can be referred to the corresponding description in the foregoing method embodiments. For the convenience and brevity of description, it will not be repeated here.

[0129] The above-mentioned Mock service-based script test device can be realized in the form of a computer program, which can run on a computer device as shown in Figure 7 .

[0130] Please refer to Figure 7 , Figure 7is a schematic block diagram of a computer device provided by an embodiment of the present application. The computer device 700 can be a terminal or a server, wherein the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, a wearable device, or the like electronic device having a communication function. The server can be a standalone server or a server cluster composed of multiple servers.

[0131] Referring to Figure 7 The computer device 700 includes a processor 702, a memory, and a network interface 705 connected through a system bus 701, wherein the memory can include a non-volatile storage medium 703 and an internal memory 704.

[0132] The non-volatile storage medium 703 can store an operating system 7031 and a computer program 7032. The computer program 7032 includes program instructions which, when executed, can cause the processor 702 to perform a script testing method based on a Mock service.

[0133] The processor 702 is configured to provide computing and control capabilities to support the operation of the entire computer device 700.

[0134] The internal memory 704 provides an environment for the execution of the computer program 7032 in the non-volatile storage medium 703, which, when executed by the processor 702, can cause the processor 702 to perform a script testing method based on a Mock service.

[0135] The network interface 705 is configured to perform network communication with other devices. Those skilled in the art can understand that Figure 7 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device 700 to which the scheme of the present application is applied. The specific computer device 700 can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0136] The processor 702 is configured to run the computer program 7032 stored in the memory to implement the following steps:

[0137] Obtain a test request of a test script, the test request including a service identifier and a plurality of request parameters;

[0138] Based on the test request, determine a target customized Mock message corresponding to the service identifier from a preset customized Mock message database, the customized Mock message database storing a plurality of customized Mock messages, each customized Mock message including regular data and a plurality of sets of customized data;

[0139] determining a plurality of sets of target customization data corresponding to the plurality of request parameters from a plurality of sets of customization data of the target customization Mock message;

[0140] determining a plurality of target test data according to the plurality of sets of target customization data and general data in the target customization Mock message;

[0141] providing each of the target test data to the test script for script testing to obtain a plurality of test results.

[0142] In some embodiments, the processor 702, before implementing the step of determining a plurality of sets of target customization data corresponding to the plurality of request parameters from a plurality of sets of customization data of the target customization Mock message, further implements the following steps:

[0143] determining whether a plurality of sets of customization data corresponding to the plurality of request parameters are contained in the plurality of sets of customization data in the target customization Mock message;

[0144] if the plurality of sets of customization data corresponding to the plurality of request parameters are contained in the plurality of sets of customization data in the target customization Mock message, then implementing the step of determining a plurality of sets of target customization data corresponding to the plurality of request parameters from a plurality of sets of customization data of the target customization Mock message;

[0145] if the plurality of sets of customization data corresponding to the plurality of request parameters are not contained in the plurality of sets of customization data in the target customization Mock message, then determining a target general Mock message corresponding to the business identifier from a preset general Mock message database;

[0146] obtaining test parameters input by a user according to the target general Mock message;

[0147] generating general test data according to the target general Mock message and the test parameters;

[0148] providing the general test data to the test script for script testing.

[0149] In some embodiments, the processor 702, when implementing the step of determining a target customization Mock message corresponding to the business identifier from a preset customization Mock message database, specifically implements the following steps:

[0150] obtaining a current environment configuration from a local environment configuration file;

[0151] determining an environment type of a current environment according to the current environment configuration;

[0152] If the environment type is a test environment, a target customized Mock message corresponding to the service identifier is determined from the customized Mock message database.

[0153] In some embodiments, the processor 702, after implementing the step of determining the environment type of the current environment according to the current environment configuration, further implements the following steps:

[0154] If the environment type is a production environment, an external message interface is invoked according to the test request to obtain an encrypted message;

[0155] The encrypted message is decrypted according to a preset message decryption rule to obtain a decrypted message;

[0156] The decrypted message is provided to the test script for script testing.

[0157] In some embodiments, the test script includes a plurality of test subscripts, and the processor 702, when implementing the step of providing each target test data to the test script for script testing to obtain a plurality of test results, specifically implements the following steps:

[0158] According to a preset correspondence between test subscripts and customized data, it is determined that each target test data corresponds to the test subscripts;

[0159] Each target test data is provided to the corresponding test subscripts for script testing to obtain the test results corresponding to each test subscript respectively.

[0160] In some embodiments, the processor 702, before implementing the step of obtaining the test request of the test script, further implements the following steps:

[0161] A Mock message blank template corresponding to the service identifier is obtained from the Mock platform;

[0162] The filling data input by the user according to the Mock message blank template is received;

[0163] The to-be-stored customized Mock message is generated according to the blank template and the filling data;

[0164] The to-be-stored customized Mock message is stored in the customized Mock message database.

[0165] In some embodiments, the processor 702, when implementing the step of storing the to-be-stored customized Mock message in the customized Mock message database, specifically implements the following steps:

[0166] determining whether the custom Mock message database contains a custom Mock message with the same service identifier as the custom Mock message to be stored;

[0167] If the custom Mock message database does not contain a custom Mock message with the same service identifier as the custom Mock message to be stored, the custom Mock message to be stored is added to the custom Mock message database.

[0168] If the custom Mock message database contains a custom Mock message with the same service identifier as the custom Mock message to be stored, the custom Mock message is determined as a target custom message.

[0169] determining whether the target custom message contains a request parameter identical to a request parameter of the custom Mock message to be stored;

[0170] If the target custom message does not contain a request parameter identical to a request parameter of the custom Mock message to be stored, the request parameter is added to the target custom message.

[0171] It should be understood that, in the embodiments of the present application, the processor 702 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or can also be any conventional processor.

[0172] It can be understood by those skilled in the art that all or part of the processes in the method of the above-mentioned embodiments can be completed by a computer program instructing related hardware. The computer program includes program instructions, and the computer program can 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 process steps of the above-mentioned method embodiments.

[0173] Therefore, the present application also provides a storage medium. The storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. The program instructions are executed by a processor to make the processor perform the following steps:

[0174] obtaining a test request of a test script, the test request comprising a service identifier and a plurality of request parameters;

[0175] determining a target customized Mock message corresponding to the service identifier from a preset customized Mock message database based on the test request, the customized Mock message database storing a plurality of customized Mock messages, each of the customized Mock messages comprising regular data and a plurality of sets of customized data;

[0176] determining a 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;

[0177] determining a plurality of target test data according to the plurality of sets of target customized data and the regular data in the target customized Mock message;

[0178] providing each of the target test data to the test script for script testing to obtain a plurality of test results.

[0179] In some embodiments, before the processor performs the program instructions to implement the step of determining a 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 processor further implements the following steps:

[0180] determining whether the plurality of sets of customized data in the target customized Mock message comprises a plurality of sets of customized data corresponding to the plurality of request parameters;

[0181] if the plurality of sets of customized data in the target customized Mock message comprises a plurality of sets of customized data corresponding to the plurality of request parameters, performing the step of determining a 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;

[0182] if the plurality of sets of customized data in the target customized Mock message does not comprise a plurality of sets of customized data corresponding to the plurality of request parameters, determining a target regular Mock message corresponding to the service identifier from a preset regular Mock message database;

[0183] obtaining test parameters input by a user according to the target regular Mock message;

[0184] generating regular test data according to the target regular Mock message and the test parameters;

[0185] providing the regular test data to the test script for script testing.

[0186] In some embodiments, the processor, when executing the program instructions to implement the step of determining the target customized Mock message corresponding to the service identifier from the preset customized Mock message database, implements the following steps:

[0187] Obtaining the current environment configuration from a local environment configuration file;

[0188] Determining the environment type of the current environment according to the current environment configuration;

[0189] If the environment type is a test environment, determining the target customized Mock message corresponding to the service identifier from the customized Mock message database.

[0190] In some embodiments, after the processor executes the program instructions to implement the step of determining the environment type of the current environment according to the current environment configuration, the processor further implements the following steps:

[0191] If the environment type is a production environment, calling an external message interface according to the test request to obtain an encrypted message;

[0192] Decrypting the encrypted message according to a preset message decryption rule to obtain a decrypted message;

[0193] Providing the decrypted message to the test script for script testing.

[0194] In some embodiments, the test script includes a plurality of test subscripts, and the processor, when executing the step of providing each target test data to the test script for script testing to obtain a plurality of test results, implements the following steps:

[0195] Determining the test subscripts corresponding to each target test data according to a preset correspondence between test subscripts and customized data;

[0196] Providing each target test data to the corresponding test subscripts for script testing to obtain test results corresponding to each test subscript.

[0197] In some embodiments, before the processor executes the program instructions to implement the step of obtaining the test request of the test script, the processor further implements the following steps:

[0198] Obtaining a Mock message blank template corresponding to the service identifier from a Mock platform;

[0199] Receiving filling data input by a user according to the Mock message blank template;

[0200] generating a to-be-stored customized Mock message according to the blank template and the filling data;

[0201] storing the to-be-stored customized Mock message into the customized Mock message database.

[0202] In some embodiments, when the processor implements the step of storing the to-be-stored customized Mock message into the customized Mock message database by executing the program instructions, the processor specifically implements the following steps:

[0203] determining whether there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database;

[0204] if there is no customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, adding the to-be-stored customized Mock message into the customized Mock message database;

[0205] if there is a customized Mock message with the same service identifier as the to-be-stored customized Mock message in the customized Mock message database, determining the customized Mock message as a target customized message;

[0206] determining whether there is a request parameter in the target customized message that is the same as a request parameter of the to-be-stored customized Mock message;

[0207] if there is no request parameter in the target customized message that is the same as the request parameter of the to-be-stored customized Mock message, adding the request parameter into the target customized message.

[0208] The storage medium can be a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various computer readable storage media that can store program codes.

[0209] Those skilled in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general terms in the above description. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0210] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other manners. For example, the embodiments of the apparatus described above are merely schematic. For example, the division of the units is only a logical function division. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In a possible implementation process, the steps of the method disclosed in the present application can be implemented by using a program. The program can be stored in a computer readable storage medium, for example, a computer disk, a compact disk, a USB flash disk, a memory card, a ROM, a RAM, a programmable logic device, a programmable logic array, a field programmable gate array, an erasable programmable logic device, an EEPROM, an EEPROM, an optical disk, a hard disk, a floppy disk, a magnetic tape, a computer memory, or the like.

[0211] The steps in the method embodiments of the present application can be adjusted, combined and deleted according to actual needs. The units in the device embodiments of the present application can be combined, divided and deleted according to actual needs. In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.

[0212] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a storage medium. Based on such understanding, the technical solutions of the present application essentially or say the part of the prior art that makes a contribution, or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application.

[0213] The above description is merely a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A script testing method based on Mock services, characterized in that, include: Obtain the test request for the test script, the test request including a business identifier and multiple request parameters; Based on the test request, a target customized Mock message corresponding to the service identifier is determined from a preset customized Mock message database. The customized Mock message database stores multiple customized Mock messages, and each customized Mock message includes regular data and multiple sets of customized data. Determine multiple sets of target customized data corresponding to multiple request parameters from multiple sets of customized data in the target customized Mock message; Multiple target test data are determined based on multiple sets of target-customized data and regular data in the target-customized Mock messages; Each of the target test data is provided to the test script for script testing, resulting in multiple test results; Before determining the multiple sets of target customized data corresponding to the multiple request parameters from the multiple sets of customized data in the target customized Mock message, the method further includes: Determine whether the multiple sets of customized data in the target customized Mock message contain multiple sets of customized data corresponding to the multiple request parameters; If the multiple sets of customized data in the target customized Mock message contain multiple sets of customized data corresponding to multiple request parameters, then the step of determining the multiple sets of target customized data corresponding to multiple request parameters from the multiple sets of customized data in the target customized Mock message is executed; If the multiple sets of customized data in the target customized Mock message do not contain multiple sets of customized data corresponding to the multiple request parameters, then the target regular Mock message corresponding to the service identifier is determined from the preset regular Mock message database. The regular Mock message database includes multiple regular Mock messages, and each regular Mock message includes a request parameter part and a regular parameter part. Obtain the test parameters input by the user based on the target's regular Mock message; Generate regular test data based on the target regular Mock message and the test parameters; The standard test data is provided to the test script for script testing; The step of determining the target customized Mock message corresponding to the service identifier from a preset customized Mock message database includes: Retrieve the current environment configuration from the local environment configuration file; Determine the environment type of the current environment based on the current environment configuration; If the environment type is a test environment, then the target customized Mock message corresponding to the service identifier is determined from the customized Mock message database.

2. The method according to claim 1, characterized in that, After determining the environment type of the current environment based on the current environment configuration, the method further includes: If the environment type is a production environment, then the external message interface is called according to the test request to obtain the encrypted message; The encrypted message is decrypted according to the preset message decryption rules to obtain the decrypted message; The decrypted message is provided to the test script for script testing.

3. The method according to claim 1, characterized in that, The test script includes multiple test sub-scripts. The target test data is provided to each test script for script testing, resulting in multiple test results, including: Based on the pre-defined correspondence between test sub-scripts and customized data, determine the test sub-scripts corresponding to each of the target test data; Each of the target test data is provided to the corresponding test sub-script for script testing, and the test results corresponding to each test sub-script are obtained.

4. The method according to any one of claims 1 to 3, characterized in that, Before obtaining the test request for the test script, the method further includes: Obtain the blank Mock message template corresponding to the service identifier from the Mock platform; Receive the fill data input by the user based on the blank template of the Mock message; Generate a custom Mock message to be saved based on the blank template and the fill data; The custom Mock message to be saved is stored in the custom Mock message database.

5. The method according to claim 4, characterized in that, The step of storing the custom Mock message to be stored into the custom Mock message database includes: Determine whether a custom Mock message with the same service identifier as the custom Mock message to be stored exists in the custom Mock message database; If there is no custom Mock message in the custom Mock message database that has the same service identifier as the custom Mock message to be stored, then the custom Mock message to be stored is added to the custom 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, then the customized Mock message is identified as the target customized message. Determine whether the target customized message contains request parameters that are identical to the request parameters of the customized Mock message to be stored; If the target customized message does not contain any request parameters that are identical to the request parameters of the custom Mock message to be saved, then the request parameters are added to the target customized message.

6. A script testing device based on Mock services, characterized in that, include: The first acquisition unit is used to acquire the test request of the test script, wherein the test request includes a business identifier and multiple request parameters; The first determining unit is used to determine, based on the test request, a target customized Mock message corresponding to the service identifier from a preset customized Mock message database. The customized Mock message database stores multiple customized Mock messages, and each customized Mock message includes regular data and multiple sets of customized data. The second determining unit is used to determine multiple sets of target customized data corresponding to multiple request parameters from multiple sets of customized data in the target customized Mock message; The third determining unit is used to determine multiple target test data based on multiple sets of target customized data and regular data in the target customized Mock message; The testing unit is used to provide the target test data to the test script for script testing and obtain multiple test results. The second determining unit is further configured to: Determine whether the multiple sets of customized data in the target customized Mock message contain multiple sets of customized data corresponding to the multiple request parameters; If the multiple sets of customized data in the target customized Mock message contain multiple sets of customized data corresponding to multiple request parameters, then the step of determining the multiple sets of target customized data corresponding to multiple request parameters from the multiple sets of customized data in the target customized Mock message is executed; If the multiple sets of customized data in the target customized Mock message do not include multiple sets of customized data corresponding to the multiple request parameters, then a target regular Mock message corresponding to the service identifier is determined from a preset regular Mock message database. The regular Mock message database includes multiple regular Mock messages, each of which includes a request parameter part and a regular parameter part. The test parameters input by the user based on the target regular Mock message are obtained; regular test data is generated based on the target regular Mock message and the test parameters; and the regular test data is provided to the test script for script testing. The first determining unit is specifically used for: Retrieve the current environment configuration from the local environment configuration file; Determine the environment type of the current environment based on the current environment configuration; If the environment type is a test environment, then the target customized Mock message corresponding to the service identifier is determined from the customized Mock message database.

7. A computer device, characterized in that, The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which includes program instructions that, when executed by a processor, can implement the method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • A data testing method and related equipment

    CN109743222A

  • Plug-in type remote procedure calling method and system

    CN111240854A