Data processing method and related device
By introducing service status and data type identification in the simulation return method, simulation data adapted to different scenarios is generated, which solves the problem of reuse of Mock interfaces in multiple scenarios, achieves resource saving and improves testing efficiency.
Patent Information
- Application Number
- CN202410132874.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-29
- Publication Date
- 2024-09-17
AI Technical Summary
In the existing simulation return method, the content returned by the Mock interface can only be applied to one scenario, resulting in frequent reconfiguration in different test scenarios, resulting in a waste of system and human resources.
By setting the service status identifier and data type identifier, simulation data for different scenarios is generated, enabling the same Mock interface to be reused in multiple scenarios and suitable for different test scenarios.
It saves system and human resources, reduces repetitive work, and improves testing efficiency.
Smart Images

Figure CN118656289A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method and related devices. Background Art
[0002] In the current mock return method, the content returned by the mock interface can only be applied to one scenario, for example, returning normal data scenarios. To achieve the purpose of returning different content, it is necessary to reconfigure the content before each mock interface is called, or set up a large number of mock interfaces to match different test scenarios. In this way, the return content constructed in advance cannot be reused, resulting in a huge waste of system and human resources. Summary of the invention
[0003] Based on this, it is necessary to provide a data processing method and related devices to address the above technical problems, which can return different content according to different service states and different random states and is suitable for different test scenarios.
[0004] In a first aspect, the present application provides a data processing method. The method comprises:
[0005] During the test, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined;
[0006] Determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed;
[0007] Generate simulation data according to the service status identifier and the data type identifier;
[0008] Return mock data for testing via mock interfaces.
[0009] In a second aspect, the present application also provides a data processing device. The device includes:
[0010] A determination module is used to determine the simulation interface pointed to by the return simulation data request if a return simulation data request is received during the test, and to determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed;
[0011] A generation module, used for generating simulation data according to a service status identifier and a data type identifier;
[0012] Return module, used to return mock data for testing through mock interfaces.
[0013] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0014] During the test, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined;
[0015] Determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed;
[0016] Generate simulation data according to the service status identifier and the data type identifier;
[0017] Return mock data for testing via mock interfaces.
[0018] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0019] During the test, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined;
[0020] Determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed;
[0021] Generate simulation data according to the service status identifier and the data type identifier;
[0022] Return mock data for testing via mock interfaces.
[0023] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0024] During the test, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined;
[0025] Determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed;
[0026] Generate simulation data according to the service status identifier and the data type identifier;
[0027] Return mock data for testing via mock interfaces.
[0028] The above data processing method and related device, during the test process, if a request for returning simulated data is received, then determine the simulated interface to which the request for returning simulated data points; determine the service status identifier and data type identifier that match the simulated interface; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; generate simulated data according to the service status identifier and the data type identifier; return the simulated data for testing through the simulated interface. Through the above method, different scenarios can be distinguished by the service status identifier and the data type identifier, that is, the scenarios of returning normal random data, returning normal fixed data, returning abnormal random data, and returning abnormal fixed data; can be applied to different test scenarios, and different simulated data can be returned according to different service states and different random states; by setting different service status identifiers and data type identifiers, the same mock interface can be reused in multiple scenarios, saving system resources, and no manual reconfiguration of the content is required before each mock interface is called, saving human resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 An application environment diagram of a data processing method in an embodiment;
[0030] Figure 2 is a flow chart of a data processing method in one embodiment;
[0031] Figure 3 is a flow chart of a data processing method in another embodiment;
[0032] Figure 4 is a flowchart of a data processing method in yet another embodiment;
[0033] Figure 5 It is a schematic diagram of a specific process in an example;
[0034] Figure 6 is a structural block diagram of a data processing device in one embodiment;
[0035] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0037] In the current mock return method, the content returned by the mock interface can only be applied to one scenario, for example, returning normal data scenarios. To achieve the purpose of returning different content, it is necessary to reconfigure the content before each mock interface is called, or set up a large number of mock interfaces to match different test scenarios. In this way, the return content constructed in advance cannot be reused, resulting in a huge waste of system and human resources.
[0038] In order to solve the above problems, the present application sets a service status identifier for characterizing whether the service is normal or abnormal, and a data type identifier for characterizing whether the simulated data is random or fixed. During the test process, if a request for returning simulated data is received, the simulated interface to which the return simulated data request points is determined, the service status identifier and data type identifier matching the simulated interface are determined, and simulated data is generated according to the service status identifier and data type identifier. The simulated data for testing is returned through the simulated interface. Different scenarios can be distinguished through the service status identifier and data type identifier, namely, scenarios of returning normal random data, returning normal fixed data, returning abnormal random data, and returning abnormal fixed data; different test scenarios can be applied, and different simulated data can be returned according to different service states and different random states; by setting different service status identifiers and data type identifiers, the same mock interface can be reused in multiple scenarios, saving system resources and eliminating the need to manually reconfigure the content before each mock interface is called, saving human resources.
[0039] Furthermore, the present application pre-configures first configuration data including a service status identifier, a data type identifier, a first data format, and first fixed data, and pre-configures second configuration data including a data type identifier, a second data format, second fixed data, and an effective status identifier, so that when simulation data is subsequently generated, simulation data corresponding to the scenario can be returned according to the configuration data of the interface, thereby saving system resources.
[0040] Furthermore, a configuration interface is designed in the present application to update the configuration data used to simulate the real interface, and the simulation data returned by the simulation interface can be controlled. There is no need to manually write a large amount of data before each test, thereby reducing repetitive work and saving human resources.
[0041] In order to better understand a data processing method, apparatus, computer device and storage medium provided in an embodiment of the present application, an application environment applicable to an embodiment of the present application is first described below.
[0042] See also Figure 1 , Figure 1A schematic diagram of an application environment of a data processing method provided by an embodiment of the present application is shown. Among them, n units 102 to be tested (unit 1, unit 2, ..., unit n) communicate with an interface 104, n is an integer greater than or equal to 1, and during the test process, the unit 102 sends a return simulation data request to the interface 104, and the interface 104 returns the corresponding data based on the return simulation data request. Among them, the interface 104 can be a mock interface, which simulates the data actually returned by the interface by returning simulation data, and the unit 102 can be an external system, an internal subsystem or an application to be tested. In one implementation, the interface 104 is connected to a database, and when receiving a return simulation data request sent by the unit 102, the simulation interface pointed to by the return simulation data request is determined, and pre-configured data matching the simulation interface is obtained from the database, and a pre-configured service status identifier and a data type identifier are determined, and simulation data is generated based on the service status identifier and the data type identifier, and the simulation data is returned to the unit 102 for the return simulation data request.
[0043] In one implementation, the data processing method of this embodiment is applied to interface testing or software testing. Interface testing is a testing method for testing interfaces between system components. It is mainly used to detect the interaction points between external systems and systems and between internal subsystems. The focus of the test is to check the data exchange, transmission and control management process, as well as the mutual logical dependencies between systems. Software testing is to edit and simulate various test scenarios through programs, scripts, and applications to automatically verify the software in normal and abnormal scenarios. The data processing method of this embodiment simulates the data actually returned by the interface to assist in verifying whether the interface has been called or whether the business logic of the system meets expectations.
[0044] In one embodiment, Figure 2 As shown, a data processing method is provided. This embodiment takes the method applied to a terminal as an example. It can be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0045] Step 202: During the test process, if a request for returning simulated data is received, determine the simulated interface to which the request for returning simulated data points.
[0046] In the process of interface testing, the request for returning simulated data is issued by an external system or an internal subsystem; in the process of software testing, the request for returning simulated data is issued by the application to be tested. The request for returning simulated data is used to request a mock interface to simulate a real interface, generate interface data, and return the generated interface data to the requester.
[0047] In one implementation, the returned simulation data request carries request data, which points to a simulation interface. The request data includes at least one of a URL, a request method, a request header, and a request parameter. For example, the simulation interface to which the request points is determined by matching the URL path in the request with the path defined by the Mock interface. For another example, the simulation interface to which the request points is determined by matching the request method (such as GET, POST, etc.) in the request with the method defined by the Mock interface.
[0048] Step 204, determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulation data is random or fixed.
[0049] Among them, the simulated interface pointed to by the request for returning simulated data corresponds to an interface identifier, and the configuration data for simulating the real interface is obtained from the database according to the interface identifier, and the service status identifier and data type identifier are read from the configuration data. The service status identifier refers to a mark or symbol used to describe the service status. The normal service status indicates that the simulated interface performs normally when processing the request and can return the correct result as expected, which can be used to verify whether the function of the object under test meets the requirements; the abnormal service status indicates that the simulated interface performs abnormally when processing the request and may not return the correct result, which can be used to verify whether the object under test can work normally under abnormal logic or pressure. The data type identifier refers to a mark or symbol used to describe the data type. The random simulated data means that the content of the simulated data is of random type and the simulated data is randomly generated. It can be used to test the performance of the object under test under different data in unknown scenarios, which helps to improve the coverage of the test and find more potential problems; the fixed simulated data means that the content of the simulated data is of fixed type and the simulated data will not change, which can be used to test the performance of the object under test under fixed data in known scenarios; the content of the simulated data refers to the specific data generated by the simulation.
[0050] Among them, the Mock interface in this embodiment, in the process of responding to the request to return the simulated data, gives priority to determining the service status identifier and the data type identifier, thereby determining the current simulation scenario. The scenarios applicable to the Mock interface of this embodiment include the scenario of returning normal random data, the scenario of returning normal fixed data, the scenario of returning abnormal random data, and the scenario of returning abnormal fixed data.
[0051] In one implementation, the configuration data corresponding to the Mock interface is obtained from the database, the configuration data is a table, and the service status identification field and the data type identification field in the table are read. When the value read under the service status identification field is "0", it indicates that the service is normal; when the value read under the service status identification field is "1", it indicates that the service is abnormal; when the value read under the data type identification field is "1", it indicates that the simulation data is random; when the value read under the data type identification field is "0", it indicates that the simulation data is fixed.
[0052] Step 206: Generate simulation data according to the service status identifier and the data type identifier.
[0053] Wherein, when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, normal random simulated data is generated; when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is fixed, normal fixed simulated data is generated; when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is random, abnormal random simulated data is generated; when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is fixed, abnormal fixed simulated data is generated. In this way, different simulated data are returned for different test scenarios.
[0054] Step 208: Return the simulation data for testing through the simulation interface.
[0055] The response returns the simulated data request, and returns the generated simulated data to the request sender through the simulated interface. The request sender completes the verification based on the simulated data according to the test task to implement interface testing or software testing. The request sender is an external system, an internal subsystem, or an application to be tested.
[0056] In the above data processing method, during the test process, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined; the service status identifier and data type identifier that match the simulated interface are determined; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; simulated data is generated according to the service status identifier and the data type identifier; and simulated data for testing is returned through the simulated interface. Through the above method, different scenarios can be distinguished by the service status identifier and the data type identifier, i.e., scenarios of returning normal random data, returning normal fixed data, returning abnormal random data, and returning abnormal fixed data; different test scenarios can be applied, and different simulated data can be returned according to different service states and different random states; by setting different service status identifiers and data type identifiers, the same mock interface can be reused in multiple scenarios, saving system resources, and no manual reconfiguration of the content is required before each mock interface is called, saving human resources.
[0057] In one embodiment, referring to Figure 3 , step 206, comprising:
[0058] Step 302: When the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, a preconfigured first data format is obtained.
[0059] The present embodiment is applied to the scenario of verifying the return of normal random data. The first data format is a data structure used to generate the return result when the pre-configured simulated real interface is in a normal state. For example, the first data format is:
[0060] "BASIC":{
[0061] "name":"java.lang.String",
[0062] "id_card":"java.lang.String",
[0063] "mobile"':"java.lang.String",
[0064] "code":"java.lang.String",
[0065] "message":"java.lang.String",
[0066] "serial_number":"java.lang.String",
[0067] "id_unqf":"java.lang.String",
[0068] "id_unqp":"java.lang.String",
[0069] "code_valid":"java.lang.String",
[0070] "time_inst":"java.lang.String"
[0071] }
[0072] The above data structure is only an example of the first data format, which can be expanded according to actual business. This embodiment does not limit the specific composition structure of the first data format.
[0073] Step 304: Generate first random data according to the first data format, and use the first random data as simulation data.
[0074] The field value of each field in the first data format is randomly generated, the generated field values are concatenated to obtain first random data, and the first random data is returned to the request sender as simulation data. In one implementation, for each field, a field value is generated in an arbitrary random manner.
[0075] In this embodiment, when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, the data structure of the real interface is simulated, and simulated data is randomly generated and returned, which is suitable for scenarios where normal random data is returned.
[0076] In one embodiment, the first data format includes field types and field attributes of M fields; generating first random data according to the first data format includes: for each field in the M fields, randomly generating a field value that is consistent with the field type of the field and matches the field attributes of the field; splicing the field values of the randomly generated M fields to obtain the first random data.
[0077] Wherein, M is an integer greater than or equal to 1. Field type refers to the data format stored in the field, including numeric type, string type, date and time type, etc. Field attribute refers to the attribute conditions satisfied by the data stored in the field, such as string length, numeric range, etc. The first data format is, for example:
[0078]
[0079] For each of the M fields, based on the field type and field attributes, a field value that meets the conditions (the field type is consistent and the field attributes match) is randomly generated, the field values of the randomly generated M fields are spliced to obtain the first random data, and the first random data is returned to the request sender as simulation data. For example, for a field whose field type is a string type and whose field attribute is a string length of 10, a string with a length of 10 is randomly generated. In one implementation, for each of the M fields, based on the field type and field attributes, a field value that meets the conditions (the field type is consistent and the field attributes match) is generated in an arbitrary random manner.
[0080] In one implementation, the first data format also includes key identifiers of M fields, and the key identifier is used to characterize whether the field is a keyword or a non-keyword. The key identifier of the keyword is also used to point to different random generation strategies. In the process of generating field values, for the field whose key identifier represents a non-keyword, the field type and field attributes of the field are used as conditions, and a field value that meets the conditions (the field type is consistent and the field attributes match) is generated in an arbitrary random manner; for the field whose key identifier represents a keyword, the random generation strategy corresponding to the key identifier is obtained, and the field type and field attributes of the field are used as conditions, and the obtained random generation strategy is used to generate a field value that meets the conditions (the field type is consistent and the field attributes match). The random generation strategy of the keyword is set in advance according to the business rules. For example, for the field "mobile phone number", the random method of the first three digits can be set according to the operator to which the business belongs, the random method of the middle four digits can be set according to the region targeted by the business, and the last four digits can be set to use an arbitrary random method. This method is used to improve the rationality of randomly generated data and provide more accurate test data for interface testing or software testing.
[0081] In one embodiment, step 206 includes: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured first fixed data; and using the first fixed data as the simulation data.
[0082] When the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, the pre-configured first fixed data is returned to the request sender as simulation data, which is suitable for the scenario of returning normal fixed data.
[0083] In one embodiment, step 204 includes: acquiring first configuration data matching the analog interface; reading a service status identifier in the first configuration data; and when the service status identifier indicates that the service is normal, reading a data type identifier in the first configuration data.
[0084] The first configuration data is pre-set configuration data for simulating a real interface in a normal state. The first configuration data of this embodiment may include: a service state identifier, a data type identifier, a first data format, and first fixed data. When the data type identifier indicates that the simulated data is random, the first data format in the first configuration data is read; when the data type identifier indicates that the simulated data is fixed, the first fixed data in the first configuration data is read.
[0085] Referring to Table 1, Table 1 shows a first configuration data.
[0086] Table 1:
[0087] Table entries meaning Return Code Normal return code, for example: 200 First fixed data Fixed content returned normally Service status indicator 0: Normal, 1: Abnormal Data type identification 0: Do not use random, 1: Use random First data format Returns a data structure of normal random data
[0088] In the specific implementation, Table 1 is stored in the database. When the Mock interface is called, Table 1 is read from the database to determine the service status identifier and the data type identifier. When the service status identifier is "0" and the data type identifier is "1", the first data format in Table 1 is continued to be read, and simulation data is randomly generated according to the first data format. When the service status identifier is "0" and the data type identifier is "0", the first fixed data in Table 1 is continued to be read, and the first fixed data is returned as simulation data to the request sender. The first configuration data also includes a return code. When returning the simulation data, the corresponding code is returned at the same time, for example: 200.
[0089] In this way, configuration data including a service status identifier, a data type identifier, a first data format, and first fixed data are pre-configured, so that when simulation data is subsequently generated, simulation data corresponding to the scenario can be returned according to the configuration data of the interface, thereby saving system resources.
[0090] In one embodiment, referring to Figure 4 , step 206, comprising:
[0091] Step 402: When the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is random, a preconfigured second data format is obtained.
[0092] Among them, this embodiment is applied to verify the scenario of returning abnormal random data. The second data format is a data structure used to generate a return result when the pre-configured simulated real interface is in an abnormal state. The data structure of the second data format refers to the first data format mentioned above, and the data structure of the second data format can also be expanded according to actual business. This embodiment does not limit the specific composition structure of the second data format.
[0093] Step 404: Generate second random data according to the second data format, and use the second random data as simulation data.
[0094] The field value of each field in the second data format is randomly generated, the generated field values are concatenated to obtain second random data, and the second random data is returned to the request sender as simulation data. In one implementation, for each field, a field value is generated in an arbitrary random manner.
[0095] In one implementation, the second data format includes field types and field attributes of K fields; generating second random data according to the second data format includes: for each of the K fields, randomly generating a field value that is consistent with the field type of the field and matches the field attributes of the field; and concatenating the field values of the randomly generated K fields to obtain second random data.
[0096] Wherein, K is an integer greater than or equal to 1. Field type refers to the data format stored in the field, including numeric type, string type, date and time type, etc. Field attributes refer to the attribute conditions satisfied by the data stored in the field, such as string length, numeric range, etc.
[0097] For each of the K fields, based on the field type and field attributes, a field value that meets the conditions (the field type is consistent and the field attributes match) is randomly generated, the field values of the randomly generated K fields are spliced to obtain second random data, and the second random data is returned to the request sender as simulation data. For example, for a field whose field type is a string type and whose field attribute is a string length of 10, a string with a length of 10 is randomly generated. In one implementation, for each of the K fields, based on the field type and field attributes, a field value that meets the conditions (the field type is consistent and the field attributes match) is generated in an arbitrary random manner.
[0098] In one implementation, the second data format also includes key identifiers of K fields, and the key identifiers are used to characterize whether the field is a keyword or a non-keyword. The key identifiers of keywords are also used to point to different random generation strategies. In the process of generating field values, for the fields whose key identifiers characterize non-keywords, the field type and field attributes of the field are used as conditions, and a field value that meets the conditions (the field type is consistent and the field attributes match) is generated in an arbitrary random manner; for the fields whose key identifiers characterize keywords, the random generation strategy corresponding to the key identifier is obtained, and the field type and field attributes of the field are used as conditions, and the obtained random generation strategy is used to generate a field value that meets the conditions (the field type is consistent and the field attributes match). The random generation strategy of keywords is set in advance according to business rules. For example, for the field "mobile phone number", the random method of the first three digits can be set according to the operator to which the business belongs, the random method of the middle four digits can be set according to the region targeted by the business, and the last four digits can be set to use an arbitrary random method. This method is used to improve the rationality of randomly generated data and provide more accurate test data for interface testing or software testing.
[0099] In this embodiment, when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is random, the data structure of the real interface is simulated, and simulated data is randomly generated and returned, which is suitable for scenarios where abnormal random data is returned.
[0100] In one embodiment, step 206 includes: when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured second fixed data; and using the second fixed data as the simulation data.
[0101] Among them, when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is fixed, the pre-configured second fixed data is returned to the request sender as simulated data, which is suitable for the scenario of returning abnormal fixed data.
[0102] In one implementation, the first configuration data includes: a service status identifier, a data type identifier, a first data format, a first fixed data, a second data format, and a second fixed data. When the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is random, the second data format in the first configuration data is read; when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is fixed, the second fixed data in the first configuration data is read.
[0103] In one embodiment, step 204 includes: obtaining first configuration data that matches the analog interface; reading a service status identifier in the first configuration data; when the service status identifier indicates a service abnormality, obtaining second configuration data associated with the first configuration data; and reading a data type identifier in the second configuration data.
[0104] The second configuration data is pre-set configuration data for simulating a real interface in an abnormal state. The second configuration data of this embodiment may include: a data type identifier, a second data format, and second fixed data. When the data type identifier indicates that the simulated data is random, the second data format in the second configuration data is read; when the data type identifier indicates that the simulated data is fixed, the second fixed data in the second configuration data is read.
[0105] Referring to Table 2, Table 2 shows a second configuration data.
[0106] Table 2:
[0107] Table entries meaning Error Code Exception return code, for example: 201 Second fixed data Fixed content returned by exception Effective status indicator 0: Invalid, 1: Valid Data type identification 0: Do not use random, 1: Use random Second data format A data structure that returns anomalous random data
[0108] In the specific implementation, the database stores associated Table 1 and Table 2. When the Mock interface is called, Table 1 is read from the database. When the service status of Table 1 is marked as "1", the associated Table 2 is obtained from the database. When the data type of Table 2 is marked as "1", the second data format in Table 2 is continued to be read, and simulation data is randomly generated according to the second data format. When the data type of Table 2 is marked as "0", the second fixed data in Table 2 is continued to be read, and the second fixed data is returned to the request sender as simulation data. The second configuration data also includes an error code. When returning the simulation data, the corresponding code is returned at the same time, for example: 201.
[0109] In one embodiment, the second configuration data also includes an effective status identifier; obtaining the second configuration data associated with the first configuration data includes: obtaining N second configuration data corresponding to the first configuration data; and determining the second configuration data whose effective status is identified as the effective identifier among the N second configuration data as the second configuration data associated with the first configuration data.
[0110] Wherein, referring to Table 2, the second configuration data also includes an effective status identifier, and the effective status identifier includes an effective identifier "1" and an ineffective identifier "0". The effective status identifier "1" indicates that the configuration data is effective, and the effective status identifier "0" indicates that the configuration data is ineffective. N is an integer greater than or equal to 1. The first configuration data is associated with the N second configuration data in advance through a unique identification code. For example, association fields are set in Table 1 and Table 2 under the same business scenario, and the same unique identification code related to the business scenario is used. In one implementation method, the unique identification code is the ID of the first configuration data, and the second configuration data is configured with data_id, and N second configuration data whose data_id is consistent with the ID of the first configuration data are searched. Among the N second configuration data corresponding to the same unique identification code, only one second configuration data has an effective status identifier configured as "1", and the effective status identifiers of the other second configuration data are configured as "0".
[0111] The error codes of the N second configuration data corresponding to the same unique identification code are all different. For example, the simulated real interface is a query interface, and the normal return code 200 indicates that the data is queried; error code 201 indicates that the data is not queried; error code 101 indicates that an internal system exception occurs in the query, and error code 102 indicates that the query condition is used incorrectly. When the service status in the first configuration data is identified as "1", multiple second configuration data with different error codes can be queried according to the unique identification code of the first configuration data, of which only one second configuration data has an effective status identified as "1". In this way, multiple abnormal modes can be simulated, and it is suitable for simulating the abnormal modes required by the test scenario.
[0112] In one embodiment, the method further includes: during the test process, receiving parameter values transmitted by the configuration interface; updating the configuration data according to the parameter values; the configuration data is used to determine the service status identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
[0113] Among them, a configuration interface is designed for configuring parameters in the first configuration data and the second configuration data, and according to the parameter value transmitted by the configuration interface, at least one of the service status identifier, data type identifier, first data format and first fixed data in the first configuration data is updated, and / or at least one of the data type identifier, second data format, second fixed data and effective status identifier in the second configuration data is updated. In one implementation, a configuration interface is designed for each parameter, the parameter value transmitted by the configuration interface is received, and the data corresponding to the configuration interface in the first configuration data or the second configuration data is updated. For example, a configuration interface corresponding to the service status identifier in the first configuration data is designed, and when the parameter value is received through the interface, the service status identifier in the first configuration data is updated.
[0114] In this way, the configuration data used to simulate the real interface can be updated, and the simulated data returned by the simulated interface can be controlled. There is no need to manually write a large amount of data before each test, thereby reducing repetitive work and saving human resources.
[0115] Reference Figure 5 In one example, when a request for Mock data (carrying a mock address) is received, the Mock platform obtains the data table corresponding to the mock address and determines whether the service status identifier in the data table indicates that the service is normal or abnormal. When the service is normal, the data type identifier in the data table is used to determine whether random data is used. When the service is normal and random data is used, random data is assembled according to the data format in the data table and returned. When the service is normal and random data is not used, fixed data in the data table is taken and returned. When the service is abnormal, the error_data table corresponding to the data table is obtained, and whether random data is used is determined according to the data type identifier in the error_data table. When the service is abnormal and random data is used, random data is assembled according to the data format in the error_data table and returned. When the service is abnormal and random data is not used, fixed data in the error_data table is taken and returned.
[0116] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0117] Based on the same inventive concept, the embodiment of the present application also provides a data processing device for implementing the data processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more data processing device embodiments provided below can refer to the limitations on the data processing method above, and will not be repeated here.
[0118] In one embodiment, Figure 6 As shown, a data processing device is provided, comprising:
[0119] Determination module 10 is used to determine the simulation interface to which the return simulation data request points if a return simulation data request is received during the test process, and to determine the service status identifier and data type identifier that match the simulation interface; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize whether the simulation data is random or fixed.
[0120] The generating module 20 is used to generate simulation data according to the service status identifier and the data type identifier.
[0121] The return module 30 is used to return the simulation data for testing through the simulation interface.
[0122] In the above data processing device, during the test process, if a request for returning simulated data is received, the simulated interface to which the request for returning simulated data points is determined; the service status identifier and data type identifier that match the simulated interface are determined; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; simulated data is generated according to the service status identifier and the data type identifier; and simulated data for testing is returned through the simulated interface. Through the above method, different scenarios can be distinguished by the service status identifier and the data type identifier, i.e., scenarios of returning normal random data, returning normal fixed data, returning abnormal random data, and returning abnormal fixed data; different test scenarios can be applied, and different simulated data can be returned according to different service states and different random states; by setting different service status identifiers and data type identifiers, the same mock interface can be reused in multiple scenarios, saving system resources, and no manual reconfiguration of the content is required before each mock interface is called, saving human resources.
[0123] In one embodiment, the generation module 20 is also used to obtain a pre-configured first data format when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random; generate first random data according to the first data format, and use the first random data as the simulated data.
[0124] In one embodiment, the first data format includes field types and field attributes of M fields; the generation module 20 is also used to randomly generate a field value that is consistent with the field type of the field and matches the field attributes of the field for each of the M fields; and the field values of the randomly generated M fields are spliced to obtain the first random data.
[0125] In one embodiment, the generating module 20 is further configured to obtain pre-configured first fixed data when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed; and use the first fixed data as the simulation data.
[0126] In one embodiment, the determination module 10 is further used to obtain first configuration data matching the analog interface; read the service status identifier in the first configuration data; and read the data type identifier in the first configuration data when the service status identifier indicates that the service is normal.
[0127] In one embodiment, the generation module 20 is also used to obtain a pre-configured second data format when the service status identifier indicates a service abnormality and the data type identifier indicates that the simulated data is random; generate second random data according to the second data format, and use the second random data as the simulated data.
[0128] In one embodiment, the generating module 20 is further configured to obtain pre-configured second fixed data when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed; and use the second fixed data as the simulation data.
[0129] In one embodiment, the determination module 10 is also used to obtain first configuration data matching the simulation interface; read the service status identifier in the first configuration data; when the service status identifier indicates a service abnormality, obtain second configuration data associated with the first configuration data; and read the data type identifier in the second configuration data.
[0130] In one embodiment, the second configuration data also includes an effective status identifier; the determination module 10 is also used to obtain N second configuration data corresponding to the first configuration data; and the second configuration data whose effective status is identified as the effective identifier among the N second configuration data is determined as the second configuration data associated with the first configuration data.
[0131] In one embodiment, the data processing apparatus further comprises a configuration module;
[0132] The configuration module is used to receive parameter values transmitted by the configuration interface during the test; update the configuration data according to the parameter values; the configuration data is used to determine the service status identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
[0133] Each module in the above data processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0134] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store configuration data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data processing method is implemented.
[0135] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0136] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the following steps when executing the computer program: during a test process, if a request for returning simulated data is received, determining a simulated interface to which the request for returning simulated data points; determining a service status identifier and a data type identifier that match the simulated interface; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; generating simulated data according to the service status identifier and the data type identifier; and returning simulated data for testing through the simulated interface.
[0137] In one embodiment, when the processor executes the computer program, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, a pre-configured first data format is obtained; first random data is generated according to the first data format, and the first random data is used as the simulated data.
[0138] In one embodiment, when the processor executes the computer program, it also implements the following steps: for each of the M fields, randomly generate a field value that is consistent with the field type of the field and matches the field attributes of the field; and splice the randomly generated field values of the M fields to obtain the first random data.
[0139] In one embodiment, when the processor executes the computer program, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured first fixed data; and using the first fixed data as simulation data.
[0140] In one embodiment, when the processor executes the computer program, the following steps are also implemented: obtaining first configuration data matching the analog interface; reading a service status identifier in the first configuration data; and when the service status identifier indicates that the service is normal, reading a data type identifier in the first configuration data.
[0141] In one embodiment, when the processor executes the computer program, the following steps are also implemented: when the service status identifier indicates a service abnormality and the data type identifier indicates that the simulated data is random, a pre-configured second data format is obtained; second random data is generated according to the second data format, and the second random data is used as the simulated data.
[0142] In one embodiment, when the processor executes the computer program, the following steps are also implemented: when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured second fixed data; and using the second fixed data as simulation data.
[0143] In one embodiment, when the processor executes the computer program, the following steps are also implemented: obtaining first configuration data matching the analog interface; reading a service status identifier in the first configuration data; when the service status identifier indicates a service abnormality, obtaining second configuration data associated with the first configuration data; and reading a data type identifier in the second configuration data.
[0144] In one embodiment, when the processor executes the computer program, the following steps are also implemented: obtaining N second configuration data corresponding to the first configuration data; and determining the second configuration data whose effective status is marked as the effective mark among the N second configuration data as the second configuration data associated with the first configuration data.
[0145] In one embodiment, when the processor executes the computer program, the following steps are also implemented: during the test process, parameter values transmitted by the configuration interface are received; configuration data is updated according to the parameter values; the configuration data is used to determine the service status identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
[0146] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented: during a test process, if a request for returning simulated data is received, a simulated interface to which the request for returning simulated data points is determined; a service status identifier and a data type identifier that match the simulated interface are determined; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; simulated data is generated according to the service status identifier and the data type identifier; and simulated data for testing is returned through the simulated interface.
[0147] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, a pre-configured first data format is obtained; first random data is generated according to the first data format, and the first random data is used as the simulated data.
[0148] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: for each of the M fields, a field value that is consistent with the field type of the field and matches the field attributes of the field is randomly generated; and the field values of the M randomly generated fields are concatenated to obtain the first random data.
[0149] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured first fixed data; and using the first fixed data as simulation data.
[0150] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining first configuration data matching the analog interface; reading a service status identifier in the first configuration data; and when the service status identifier indicates that the service is normal, reading a data type identifier in the first configuration data.
[0151] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: when the service status identifier indicates a service abnormality and the data type identifier indicates that the simulated data is random, a pre-configured second data format is obtained; second random data is generated according to the second data format, and the second random data is used as the simulated data.
[0152] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured second fixed data; and using the second fixed data as simulation data.
[0153] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: obtaining first configuration data that matches the analog interface; reading a service status identifier in the first configuration data; when the service status identifier indicates a service abnormality, obtaining second configuration data associated with the first configuration data; and reading a data type identifier in the second configuration data.
[0154] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining N second configuration data corresponding to the first configuration data; and determining the second configuration data whose effective status is marked as the effective mark among the N second configuration data as the second configuration data associated with the first configuration data.
[0155] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: during the test process, parameter values transmitted by the configuration interface are received; configuration data is updated according to the parameter values; the configuration data is used to determine the service status identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
[0156] In one embodiment, a computer program product is provided, including a computer program, which implements the following steps when executed by a processor: during a test process, if a request for returning simulated data is received, determining a simulated interface to which the request for returning simulated data points; determining a service status identifier and a data type identifier that match the simulated interface; the service status identifier is used to characterize normal service or abnormal service, and the data type identifier is used to characterize random simulated data or fixed simulated data; generating simulated data according to the service status identifier and the data type identifier; and returning simulated data for testing through the simulated interface.
[0157] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, a pre-configured first data format is obtained; first random data is generated according to the first data format, and the first random data is used as the simulated data.
[0158] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: for each of the M fields, a field value that is consistent with the field type of the field and matches the field attributes of the field is randomly generated; and the field values of the M randomly generated fields are concatenated to obtain the first random data.
[0159] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured first fixed data; and using the first fixed data as simulation data.
[0160] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining first configuration data matching the analog interface; reading a service status identifier in the first configuration data; and when the service status identifier indicates that the service is normal, reading a data type identifier in the first configuration data.
[0161] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: when the service status identifier indicates a service abnormality and the data type identifier indicates that the simulated data is random, a pre-configured second data format is obtained; second random data is generated according to the second data format, and the second random data is used as the simulated data.
[0162] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured second fixed data; and using the second fixed data as simulation data.
[0163] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: obtaining first configuration data that matches the analog interface; reading a service status identifier in the first configuration data; when the service status identifier indicates a service abnormality, obtaining second configuration data associated with the first configuration data; and reading a data type identifier in the second configuration data.
[0164] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: obtaining N second configuration data corresponding to the first configuration data; and determining the second configuration data whose effective status is marked as the effective mark among the N second configuration data as the second configuration data associated with the first configuration data.
[0165] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: during the test process, parameter values transmitted by the configuration interface are received; configuration data is updated according to the parameter values; the configuration data is used to determine the service status identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
[0166] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0167] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0168] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0169] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A data processing method, characterized in that: The method comprises: During the test, if a request for returning simulated data is received, determining the simulated interface to which the request for returning simulated data points; Determine a service status identifier and a data type identifier that match the simulation interface; the data type identifier is used to indicate that the simulation data is random or the simulation data is fixed; Generate simulation data according to the service status identifier and the data type identifier; The simulation data for testing is returned through the simulation interface.
2. The method according to claim 1, characterized in that The generating simulation data according to the service status identifier and the data type identifier includes: When the service status identifier indicates that the service is normal and the data type identifier indicates that the simulated data is random, obtaining a preconfigured first data format; First random data is generated according to the first data format, and the first random data is used as simulation data.
3. The method according to claim 2, characterized in that The first data format includes field types and field attributes of M fields; and generating first random data according to the first data format includes: For each of the M fields, randomly generate a field value that is consistent with the field type of the field and matches the field attribute of the field; The field values of the randomly generated M fields are concatenated to obtain first random data.
4. The method according to claim 1, characterized in that The generating simulation data according to the service status identifier and the data type identifier includes: When the service status identifier indicates that the service is normal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured first fixed data; The first fixed data is used as simulation data.
5. The method according to any one of claims 2 to 4, characterized in that The determining of the service status identifier and the data type identifier that match the simulated interface includes: Acquire first configuration data matching the analog interface; Reading the service status identifier in the first configuration data; When the service status identifier indicates that the service is normal, the data type identifier in the first configuration data is read.
6. The method according to claim 1, characterized in that The generating simulation data according to the service status identifier and the data type identifier includes: When the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulated data is random, obtaining a preconfigured second data format; Second random data is generated according to the second data format, and the second random data is used as simulation data.
7. The method according to claim 1, characterized in that The generating simulation data according to the service status identifier and the data type identifier includes: When the service status identifier indicates that the service is abnormal and the data type identifier indicates that the simulation data is fixed, obtaining pre-configured second fixed data; The second fixed data is used as simulation data.
8. The method according to claim 6 or 7, characterized in that: The determining of the service status identifier and the data type identifier that match the simulated interface includes: Acquire first configuration data matching the analog interface; Reading the service status identifier in the first configuration data; When the service status identifier indicates that the service is abnormal, obtaining second configuration data associated with the first configuration data; Read the data type identifier in the second configuration data.
9. The method according to claim 8, characterized in that The second configuration data also includes a validity status identifier; and the acquiring the second configuration data associated with the first configuration data includes: Obtaining N second configuration data corresponding to the first configuration data; Among the N second configuration data, the second configuration data whose effectiveness status is identified as the effectiveness identification is determined as the second configuration data associated with the first configuration data.
10. The method according to claim 1, characterized in that The method further comprises: During the test, receive parameter values transmitted by the configuration interface; The configuration data is updated according to the parameter value; the configuration data is used to determine the service state identifier and the data type identifier; the configuration data includes at least one of the first configuration data and the second configuration data.
11. A data processing device, characterized in that: The device comprises: A determination module, used to, during the test process, if a request for returning simulated data is received, determine the simulated interface to which the request for returning simulated data points, and determine the service status identifier and data type identifier that match the simulated interface; the service status identifier is used to indicate that the service is normal or abnormal, and the data type identifier is used to indicate that the simulated data is random or fixed; A generating module, used for generating simulation data according to the service status identifier and the data type identifier; The return module is used to return the simulation data for testing through the simulation interface.
12. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
