A method, device, equipment and storage medium for generating mock data
By automatically obtaining the client's running environment and basic information and generating Mock data structures and data, the problem of strong invasiveness of the JSF service layer Mock service code is solved, and the automatic generation of Mock data without additional configuration is realized, simplifying the configuration process.
Patent Information
- Application Number
- CN202010929149.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-07
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2040-09-07
AI Technical Summary
In the prior art, when providing Mock services to the JSF service layer, the project code is highly invasive, manual adjustment of code and configuration is required, and interface declarations require annotation or additional method configuration.
通过检测客户端接入时获取运行环境信息,根据设定条件自动收集客户端基础信息,生成目标Mock数据结构和Mock数据,实现无需其他客户端配置即可自动生成Mock数据。
It solves the problem of strong intrusion in the JSF service layer Mock service code, realizes automatic generation of Mock data without additional client configuration, and simplifies the project code and configuration process.
Smart Images

Figure CN113760703B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a method, device, equipment and storage medium for generating mock data. Background Art
[0002] Mock testing is a testing method that uses a virtual object to create a test for some objects that are not easy to construct or obtain during the test process. The virtual object is the Mock object. With the widespread application of the JavaServer Faces (JSF) framework, the demand for providing Mock services for the JSF service layer is increasing.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following technical problems in the prior art: There are two disadvantages in the current implementation method of providing Mock services for the JSF service layer: First, most of the current technical solutions are implemented for the http protocol and cannot provide Mock services for the JSF service layer. Even if the JSF layer can be supported to provide Mock services, there will be technical problems such as the access project code is more invasive and the code needs to be manually adjusted to adapt to different environments, and the access configuration is more complicated and requires annotations to the interface declaration or additional method configuration. Summary of the invention
[0004] The embodiments of the present invention provide a method, apparatus, device and storage medium for generating Mock data, which solve the technical problem of strong intrusiveness of project code when providing Mock services for the JSF service layer in the prior art, and realize automatic generation of Mock data without other client configuration.
[0005] In a first aspect, an embodiment of the present invention provides a method for generating Mock data, comprising:
[0006] When a client access is detected, the operating environment information of the access client is obtained based on the package dependency;
[0007] When the operating environment information meets the set Mock conditions, obtain the basic client information of the access client;
[0008] Generate the target data structure of the target Mock data based on the basic information of the client;
[0009] Generate target Mock data based on the target data structure.
[0010] In a second aspect, an embodiment of the present invention further provides a device for generating Mock data, including:
[0011] The operating environment acquisition module is used to acquire the operating environment information of the access client based on the package dependency when the client access is detected;
[0012] The basic information acquisition module is used to obtain the basic information of the client accessing the client when the operating environment information meets the set Mock conditions;
[0013] The data structure generation module is used to generate the target data structure of the target Mock data according to the basic information of the client;
[0014] The mock data generation module is used to generate target mock data according to the target data structure.
[0015] In a third aspect, an embodiment of the present invention further provides a computer device, the device comprising:
[0016] one or more processors;
[0017] A storage device for storing one or more programs;
[0018] When one or more programs are executed by one or more processors, the one or more processors implement the method for generating Mock data provided by any embodiment of the present invention.
[0019] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for generating Mock data as provided in any embodiment of the present invention.
[0020] The embodiment of the present invention obtains the operating environment information of the access client when the client access is detected; when the operating environment information meets the set Mock condition, obtains the client basic information of the access client based on the package dependency; generates the target data structure of the target Mock data according to the client basic information; generates the target Mock data according to the target data structure, automatically collects the client basic information of the access client based on the package dependency when the Mock condition set by the operating environment load of the access client, and automatically generates the target Mock data of the access client based on the client basic information, thereby solving the technical problem of strong intrusiveness of project code when providing Mock service for JSF service layer in the prior art, and realizes the automatic generation of Mock data without other client configuration. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1a This is a flow chart of a method for generating Mock data provided by Embodiment 1 of the present invention;
[0022] Figure 1b This is a schematic diagram of the architecture of a Mock service provided by the first embodiment of the present invention;
[0023] Figure 2 is a flow chart of a method for generating Mock data provided by Embodiment 2 of the present invention;
[0024] Figure 3a is a flow chart of a method for generating Mock data provided by Embodiment 3 of the present invention;
[0025] Figure 3b This is a control schematic diagram of a Mock-sever end provided in Embodiment 3 of the present invention;
[0026] Figure 3c This is a schematic diagram of an interface survival analysis provided by Embodiment 3 of the present invention;
[0027] Figure 3d This is a schematic diagram of automatic generation of Mock data provided by Embodiment 3 of the present invention;
[0028] Figure 3e This is a schematic diagram of data source control provided by Embodiment 3 of the present invention;
[0029] Figure 3f This is another schematic diagram of Mock data generation provided by the third embodiment of the present invention;
[0030] Figure 4 It is a structural schematic diagram of a device for generating Mock data provided by a fourth embodiment of the present invention;
[0031] Figure 5 It is a structural diagram of a computer device provided in Embodiment 5 of the present invention. DETAILED DESCRIPTION
[0032] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0033] Embodiment 1
[0034] Figure 1a 1 is a flowchart of a method for generating Mock data provided by the first embodiment of the present invention. This embodiment is applicable to the case of generating Mock data. The method can be executed by a device for generating Mock data, and the device for generating Mock data can be implemented in software and / or hardware. For example, the device for generating Mock data can be configured in a computer device. Figure 1a As shown, the method includes:
[0035] S110: When a client access is detected, the operating environment information of the access client is obtained based on the package dependency.
[0036] In this embodiment, the generation of Mock data is achieved through the Mock service. Figure 1b This is a schematic diagram of the architecture of a Mock service provided by the first embodiment of the present invention. Figure 1b As shown, the Mock service is located on the server side, including Mock-client and Mock-sever. Among them, Mock-client is accessed on the client side, and is a JAVA class set developed in JAVA that collects client code. It is used to obtain the basic information of the client accessing the client, and can process the client package information, class information, network isolation, and connection to mock-server; mock-server is a proxy server, which is used to implement various mock operations on the interface. It is mainly used to receive requests initiated by mock-client, and sort out and store the received information in the database, and respond to the return value of Mock to Mock-client in combination with the return strategy provided by the Mock platform. Optionally, the basic information of the client may include user information, application name, method declaration, package information, etc. of the access client.
[0037] In this embodiment, zero configuration of the Mock-client side and zero intrusion on the client code can be achieved through package dependencies. In one embodiment of the present invention, before obtaining the operating environment information of the access client based on the package dependency, it also includes: obtaining a software development kit generated based on the client information acquisition logic, and introducing the software development kit into the Maven dependency. Maven is a tool for managing dependencies. Maven is often used in projects to manage jar packages, and can manage the dependencies of jar packages. Optionally, a software development kit for obtaining basic client information can be generated based on the client information acquisition logic, and the generated software development kit can be introduced into the Maven dependency. When a client is connected, the information of the access client can be automatically obtained without other configurations of the client.
[0038] In this embodiment, in order to ensure the security of the client, the basic client information of the access client is not directly obtained when the client accesses, but before obtaining the basic client information, it is determined whether the operating environment of the access client meets the set Mock conditions. That is, when a client access is detected, the operating environment information of the access client is obtained based on the pre-introduced package dependency to determine whether the operating environment of the access client is suitable for obtaining Mock data. Exemplarily, the operating environment information of the access client can be a production environment, a test environment, etc.
[0039] S120: When the operating environment meets the set Mock conditions, basic client information of the access client is obtained.
[0040] Optionally, a verification mechanism can be added to the software development kit to obtain and verify whether the operating environment of the access client meets the Mock conditions, and when the operating environment of the access client does not meet the Mock conditions, the operation of obtaining the basic client information of the access client is turned off to avoid performance loss and security risks. When the operating environment of the access client does not meet the Mock conditions, the basic client information of the access client is obtained. Optionally, whether the operating environment of the access client meets the Mock conditions can be set according to actual needs. Exemplarily, when the application environment of the access client is a production machine environment, it can be determined that the application environment of the access client does not meet the Mock conditions, and the information acquisition switch is turned off to isolate the local from the online network.
[0041] S130: Generate a target data structure of target Mock data according to the basic information of the client.
[0042] In this embodiment, the target data structure of the target Mock data required by the access client can be generated according to the client basic information. Optionally, the target data structure can be a JSON template. It can be understood that the target data structure is related to the structure of the class in the access client.
[0043] In one embodiment of the present invention, a target data structure of target Mock data is generated based on the basic information of the client, including: obtaining the class name in the basic information of the client, obtaining the structure of the class corresponding to the class name; generating the target data structure based on the structure of the class and the general placeholder specification. Optionally, the target structure data can be determined based on the class name in the basic information of the client. Specifically, the client obtains all classes contained in the access client, parses the structure of the class, selects the general placeholder specification, and generates a standard JSON template as the target data structure.
[0044] On the basis of the above scheme, before generating the target data structure of the target Mock data according to the basic information of the client, it also includes: obtaining the Mock control state of the access client; when the Mock control state is on, generating the target data structure of the target Mock data according to the basic information of the client. Optionally, in order to make the generation of Mock data more flexible, the user can modify the control state of the Mock. When the Mock control state of the access client is on, it is determined that the user has the need to generate Mock data, and the operation of generating the target data structure of the target Mock data according to the basic information of the client is executed.
[0045] Optionally, the control state of the Mock can be controlled by at least one of the application switch and the method switch. Among them, the application switch is used to control the Mock control state of the access client, and the method switch is used to control the Mock control state of a method in the access client. The user can adjust the application switch and / or method switch according to actual needs. Exemplarily, when the user needs to turn on the Mock control of the access client, the application switch can be adjusted to the on state, and when the user needs to turn on the Mock control of a method, the method switch of the method can be adjusted to the on state. When any switch of the application switch and the method switch is in the on state, it is determined that the Mock control state of the access client is in the on state.
[0046] S140, generating target Mock data according to the target data structure.
[0047] In this embodiment, after determining the target data structure of the target Mock data, the target Mock data is generated based on the target data structure. Optionally, the method for generating the target Mock data based on the target data structure can refer to the method for generating Mock data of a specified data structure in the prior art. Exemplarily, cached data can be obtained or data can be called from the server as the target Mock data.
[0048] The embodiment of the present invention obtains the basic information of the client accessing the client based on the package dependency; generates the target data structure of the target Mock data according to the basic information of the client; generates the target Mock data according to the Mock control state of the access client and the target data structure. By automatically collecting the basic information of the client accessing the client based on the package dependency and automatically generating the target Mock data of the access client based on the basic information, the technical problem of the strong intrusiveness of the project code when providing Mock service for the JSF service layer in the prior art is solved, and the automatic generation of Mock data can be realized without other client configurations.
[0049] Embodiment 2
[0050] Figure 2 1 is a flow chart of a method for generating Mock data provided by the second embodiment of the present invention. This embodiment is further optimized on the basis of the above solution. Figure 2 As shown, the method includes:
[0051] S210: When a client access is detected, the operating environment information of the access client is obtained based on the package dependency.
[0052] S220: When the operating environment information meets the set Mock conditions, obtain the basic client information of the access client.
[0053] S230: Generate a target data structure of target Mock data according to the basic information of the client.
[0054] S240 , obtaining a target data source connected to the client, and generating target Mock data of a target data structure based on a target Mock data generation rule of the target data source.
[0055] In this embodiment, multiple data sources are provided to make the generation of target Mock data more flexible. Optionally, the data source can be background data, historical data, intelligent recommendation, automatic generation, etc. Among them, the data source can be a single data source, or it can be composed of multiple data sources, and different data sources correspond to different data acquisition paths and target Mock data generation rules. Exemplarily, the data acquisition path of the background data is to request the server background interface; the data acquisition path of the historical data is to obtain the data in the cache; the recommended data includes data sources with different acquisition orders and different acquisition conditions, such as giving priority to calling the server background data, and calling the cached data when the server background interface is not alive. In other words, in this application, the target data source that the user can select can be a single data source, or it can be composed of multiple data sources. In this embodiment, the target data source can be used in conjunction with the application switch and the method switch as needed.
[0056] In one embodiment of the present invention, generating target Mock data based on the target data source includes: obtaining a target Mock data generation rule corresponding to the target data source, and generating the target Mock data based on the target Mock data generation rule and the target data structure. It is understandable that different data sources correspond to different target Mock data generation rules.
[0057] Optionally, the target Mock data generation rule of the target data source is used to generate the target Mock data of the target data structure, including at least one of the following: when the target data source is historical data, the cached data of the target data structure is called as the target Mock data; when the target data source is automatically generated, the Mock data is generated based on the target data structure; when the target data source is intelligent recommendation or background data, the target Mock data of the target data structure is obtained by requesting the setting interface. Specifically, when the target data source is historical data, the target Mock data generation rule is to call the cached data of the target data structure as the target Mock data. When the target data source is automatically generated, the target Mock data generation rule is to force the Mock operation and generate Mock data through the target data structure. When the target data source is intelligent recommendation or background data, the target Mock data generation rule is to request the corresponding setting interface to obtain the target Mock data. Optionally, the setting interface can be a backend service interface of the server.
[0058] Based on the above scheme, there may be a situation where the setting interface is not alive. Optionally, the target Mock data of the target data structure is obtained by requesting the setting interface, including: judging whether the setting interface is alive; when the setting interface is alive, calling the setting interface to obtain the target Mock data of the target data structure; when the setting interface is not alive, calling the cached data of the target data structure as the target Mock data or generating Mock data based on the target data structure. Specifically, when the setting interface is alive, the setting interface can be directly called to obtain the target Mock data of the target data structure; when the setting interface is not alive, the target Mock data of the target data structure can be first obtained from the cache, and when the data does not exist in the cache data table, the Mock service is directly called to generate the target Mock data of the target data structure.
[0059] In one embodiment, the determination of whether the setting interface is alive includes: verifying whether the method declaration of the setting interface is registered in the JSF registration center; when the method declaration is not registered in the JSF registration center, determining that the setting interface is not alive; when the method declaration is registered in the JSF registration center, determining whether the setting interface can call valid data within a set time period; when the setting interface can call valid data within a set time period, determining that the setting interface is alive, otherwise, determining that the setting interface is not alive. Optionally, whether the server interface is alive can be determined in the following manner: obtaining the transfer parameters and method declarations passed from the Mock-client end to the Mock-server end, and the mock-server end calls the jsf service according to the transferred data to determine whether the interface is alive. Specifically, first verify whether it is registered in the JSF registration center according to the method declaration. If it is not registered, it indicates that the method declaration is not alive; if it has been registered, determine whether the interface is alive according to whether the jsf interface can return the expected data of the method call within 1000ms. If the jsf interface does not return the expected data of the method call within 1000ms, it is determined to be not alive, and the survival status of the interface declaration is fed back to quickly locate the problem of the dependent interface.
[0060] The embodiment of the present invention generates target Mock data based on a target data source, thereby providing a user with a variety of target Mock data generation methods, making the generation of the target Mock more flexible.
[0061] Embodiment 3
[0062] Figure 3a 1 is a flowchart of a method for generating Mock data provided by Embodiment 3 of the present invention. This embodiment provides a preferred embodiment based on the above embodiments. Figure 3a As shown, the method includes:
[0063] S310. Mock-client collects method declarations, package information, and user information of the client code, and initiates a request.
[0064] In this embodiment, zero configuration and zero code intrusion of the Mock-client are achieved by introducing Maven dependencies. Optionally, the introduction of Maven dependencies can refer to the following introduction method:
[0065] <dependency>
[0066] <groupid> com.jd.m.mocker< / groupid>
[0067] <artifactid> mocker-client< / artifactid>
[0068] <version> xxx-beta.x< / version>
[0069] < / dependency>
[0070] In addition, Mock-client can also automatically verify whether the application environment of the access client meets the Mock conditions. If it is a production environment machine, Mock-client will actively turn off the switch without causing any unnecessary performance loss and risk. The technical effect of network isolation is achieved through intelligent switch control.
[0071] Specifically, the zero configuration of Mock-client is mainly reflected in the following three aspects:
[0072] 1) Zero configuration of basic data: The basic data of the access application used by Mock, including the user, application name, etc., will be automatically obtained by Mock-client;
[0073] 2) Zero configuration of JSF calls: mock-client uses the extension point support provided by JSF itself to implement zero configuration of the JSF call process. The mock process is completed in the Filter layer of JSF.
[0074] 3) Zero configuration for application health monitoring: The health status of the application startup process will be reported by Mock-client along with the life cycle of the Spring framework, and new applications that are connected for the first time will be automatically registered.
[0075] S320, Mock-sever receives information sent from Mock-client, extracts relevant protocol information and method declaration information, and dynamically generates a JSON return value template.
[0076] In this embodiment, before dynamically generating the JSON return value template, the generation method of the target Mock can be determined according to the switch set by the user. Specifically, the application-level Mock switch and the method-level switch can be set separately in the Mock-server. Once the application-level Mock switch is turned off, all methods under this application will no longer perform Mock operations; the method-dimensional Mock switch only controls whether the method performs Mock operations. Once turned off, it will only affect whether this method performs Mock. If you need to implement smart Mock, you need to set both the application Mock switch and the method Mock development to the on state. Optionally, you can also combine the Mock data source control to determine the target Mock data. Figure 3b It is a control schematic diagram of a mock-server end provided in the third embodiment of the present invention. Figure 3b The generation of the target Mock is described in the example of the data source being the backend data. Figure 3b As shown, when the application switch and interface Mock are both turned on, and the server interface is alive, the backend service is directly called to obtain the target Mock data. When the server interface is not alive, it is determined whether there is cached data. If there is cached data, the cached data is called as the target Mock data. If there is no cached data, the Mock service is called to generate the target Mock data.
[0077] In the above solution, whether the server interface is alive can be determined in the following way: Combined with the above judgment logic, service dependency analysis can determine the interface services automatically generated by mock, and which interfaces are the interface services of the online data that survive. After the application is started, the Mock-client requests to the Mock-server to pass parameters and method declarations. The Mock-server calls the jsf service based on the passed data to determine whether the interface is alive. Figure 3c is a schematic diagram of an interface survival analysis provided by the third embodiment of the present invention, such as Figure 3c As shown, Mock-server detects whether the interface declaration is verified and registered in the jsf registration center. If not, it indicates that the method declaration is not alive. Otherwise, it detects whether the jsf interface can return the expected data of the method call within 1000ms. If the jsf interface fails to return the expected data of the method call within 1000ms, it is determined that the interface is not alive, and the survival status of the interface declaration is fed back.
[0078] S330, Mock receives the information stored in the data of Mock-sever, and generates an operable return value interface in combination with the user request type.
[0079] S340: Return the data return strategy to the Mock-sever according to the optional operation data source control and application control of the user on the Mock platform.
[0080] In this embodiment, the operable return value interface is automatically generated, and Mock data is automatically generated based on the operable return value interface. Figure 3d This is a schematic diagram of automatic generation of Mock data provided by the third embodiment of the present invention. Figure 3d As shown in the figure, after the local application is started, Mock-sever parses and mocks the increasingly complex service interfaces of the project dependencies according to the dependency interface. Among them, the following technical problems need to be solved to realize the automatic generation of service interfaces: 1. Analyze the structure of the class, select the general placeholder specification, and generate a standard JSON template. 2. Parse the JSON template to generate the JSON string required by the client.
[0081] Based on the above solution, the uniqueness of data can be flexibly solved through intelligent control of data sources, while the authenticity of data can be restored to the maximum extent, and the stability of Mock data can be guaranteed. In other words, the strategy of generating return values through the control method of Mock data source is also the key to the realization of intelligent Mock. Figure 3e This is a schematic diagram of a data source control provided by Embodiment 3 of the present invention. Figure 3e The data source may include:
[0082] 1) Historical data: also known as cached data, which can be understood as the last online data pulled and saved in the cache data table when the project is started. It can be used as an application data source at the application level and a method data source at the method level;
[0083] 2) Automatic generation: Force mock operations and generate mock data through return value templates, which can be used as application data sources at the application level and method data sources at the method level;
[0084] 3) Intelligent selection: Intelligent selection is to first request the server interface to pull data in the service. If the interface is not alive, the data is pulled from the cache data table. If the cache data table does not exist, the return value data is directly generated using Mock, which can be used as an application data source at the application level.
[0085] 4) Backend dependency: Force the server interface to pull the return value data, which can be used as a method data source at the method level;
[0086] 5) Same application source: can be used as a method data source at the method level. If the data source is controlled using the same application source, it will be synchronized to the application data source control at the application level.
[0087] Depend on Figure 3eIt can be seen that the data source control of the private template has the highest priority, followed by the application template data source control, then the public template data source control, and finally the application-level data source control. Among them, the public template is a JSON format data specification that is common to all applications and is serialized from the interface declaration information; the application template has a smaller scope than the public template, and is a serialized JSON format data specification used in the application dimension; the parameterized template is a data model that matches the parameters requested with the JSON number data specification serialized from the interface declaration. When the client requests to the server and then to the database, matching is performed through parameters.
[0088] It should be noted that in this embodiment, the Mock switch controls whether the application or method is a Mock, which is the core factor for automatically generating the target Mock data. When the Mock switch is turned on, the Mock data can be processed and generated according to the rules of the Mock data source. Mock automatic generation can also be achieved through the flexible setting of the Mock switch and the Mock data source. Figure 3f This is another schematic diagram of Mock data generation provided by the third embodiment of the present invention. Figure 3f As shown, after determining that the Mock is turned on and the interface is turned on, the Mock-sever executes the corresponding data source rules according to the data source corresponding to the method data source to generate the Mock data.
[0089] The embodiment of the present invention accesses the Mock-client package in a zero-configuration and zero-code-intrusion manner on the client based on package dependency, realizes automatic identification of the network environment and performs local and online network isolation based on the network environment; in addition, the Mock data is flexibly generated through the built-in intelligent data generation strategy of the Mock-server.
[0090] Embodiment 4
[0091] Figure 4 1 is a schematic diagram of the structure of a device for generating Mock data provided by Embodiment 4 of the present invention. The device for generating Mock data can be implemented in software and / or hardware, for example, the device for generating Mock data can be configured in a computer device. Figure 4 As shown, the device includes a basic information acquisition module 410, a data structure generation module 420 and a Mock data generation module 430, wherein:
[0092] The operating environment acquisition module 410 is used to acquire the operating environment information of the accessed client based on the package dependency when the client access is detected;
[0093] The basic information acquisition module 420 is used to acquire the basic client information of the access client when the operating environment information meets the set Mock conditions;
[0094] A data structure generation module 430 is used to generate a target data structure of target Mock data according to the client basic information;
[0095] The Mock data generating module 440 is used to generate target Mock data according to the target data structure.
[0096] The embodiment of the present invention obtains the operating environment information of the access client based on the package dependency when the client access is detected through the operating environment acquisition module; the basic information acquisition module obtains the client basic information of the access client when the operating environment information meets the set Mock condition; the data structure generation module generates the target data structure of the target Mock data according to the client basic information; the Mock data generation module generates the target Mock data according to the Mock control state and the target data structure of the access client, automatically collects the client basic information of the access client based on the package dependency, and automatically generates the target Mock data of the access client based on the basic information, thereby solving the technical problem of strong intrusiveness of project code when providing Mock service for JSF service layer in the prior art, and realizes the automatic generation of Mock data without other client configuration.
[0097] Optionally, based on the above solution, the device further includes a package dependency import module, which is used to:
[0098] Before obtaining the operating environment information of the access client based on the package dependency, a software development kit generated based on the client information acquisition logic is obtained, and the software development kit is introduced into the Maven dependency.
[0099] Optionally, based on the above solution, the basic information acquisition unit is specifically used to:
[0100] When the access client accesses, the operating environment information of the access client is obtained;
[0101] When the running environment information meets the set Mock conditions, the basic client information of the access client is obtained.
[0102] Optionally, based on the above solution, the data structure generation module 430 is specifically used for:
[0103] Get the class name in the client basic information, and get the class structure corresponding to the class name;
[0104] Generates a target data structure based on the structure of the class and generic placeholder specifications.
[0105] Optionally, based on the above solution, the Mock data generating module 440 is specifically used for:
[0106] The target data source of the access client is obtained, and the target Mock data of the target data structure is generated based on the target Mock data generation rule of the target data source.
[0107] Optionally, based on the above solution, the Mock data generating module 440 is specifically used for at least one of the following:
[0108] When the target data source is historical data, the cached data of the target data structure is called as the target Mock data;
[0109] When the target data source is automatically generated, generating Mock data based on the target data structure;
[0110] When the target data source is intelligent recommendation or background data, the target Mock data of the target data structure is obtained by requesting a setting interface.
[0111] Optionally, based on the above solution, the Mock data generating module 440 is specifically used for:
[0112] Determining whether the set interface is alive;
[0113] When the setting interface survives, calling the setting interface to obtain target Mock data of the target data structure;
[0114] When the setting interface is not alive, the cached data of the target data structure is called as the target Mock data or Mock data is generated based on the target data structure.
[0115] Optionally, based on the above solution, the Mock data generating module 440 is specifically used for:
[0116] Verify whether the method declaration of the setting interface is registered in the JSF registration center;
[0117] When the method declaration is not registered in the JSF registration center, it is determined that the setting interface is not alive;
[0118] When the method declaration is registered in the JSF registration center, it is determined whether the setting interface can call valid data within a set time period;
[0119] When the setting interface can call valid data within a set time period, it is determined that the setting interface is alive; otherwise, it is determined that the setting interface is not alive.
[0120] Optionally, based on the above solution, the device further includes a control state judgment module, which is used to:
[0121] Get the Mock control status of the access client;
[0122] When the Mock control state is turned on, the target data structure of the target Mock data is generated according to the client basic information.
[0123] The device for generating Mock data provided in the embodiment of the present invention can execute the method for generating Mock data provided in any embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method.
[0124] Embodiment 5
[0125] Figure 5 It is a structural diagram of a computer device provided in Embodiment 5 of the present invention. Figure 5 A block diagram of an exemplary computer device 512 suitable for use in implementing embodiments of the present invention is shown. Figure 5 The computer device 512 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0126] like Figure 5 As shown, the computer device 512 is in the form of a general-purpose computing device. The components of the computer device 512 may include, but are not limited to: one or more processors 516, a system memory 528, and a bus 518 that connects various system components (including the system memory 528 and the processor 516).
[0127] Bus 518 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a local bus to processor 516, or a bus structure using any of a variety of bus architectures. These architectures include, by way of example, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0128] The computer device 512 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 512, including volatile and non-volatile media, removable and non-removable media.
[0129] System memory 528 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 530 and / or cache memory 532. Computer device 512 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage device 534 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 not shown, usually called a "hard drive"). Although Figure 5Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 518 via one or more data medium interfaces. The memory 528 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0130] A program / utility 540 having a set (at least one) of program modules 542 may be stored, for example, in the memory 528, such program modules 542 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 542 generally perform the functions and / or methods of the embodiments described herein.
[0131] The computer device 512 may also communicate with one or more external devices 514 (e.g., keyboard, pointing device, display 524, etc.), may also communicate with one or more devices that enable a user to interact with the computer device 512, and / or communicate with any device that enables the computer device 512 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed via an input / output (I / O) interface 522. In addition, the computer device 512 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) via a network adapter 520. As shown, the network adapter 520 communicates with other modules of the computer device 512 via a bus 518. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the computer device 512, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0132] The processor 516 executes various functional applications and data processing by running the program stored in the system memory 528, for example, implementing the method for generating Mock data provided in an embodiment of the present invention, the method comprising:
[0133] When a client access is detected, the operating environment information of the access client is obtained based on the package dependency;
[0134] When the operating environment information meets the set Mock conditions, obtain the basic client information of the access client;
[0135] Generate the target data structure of the target Mock data based on the basic information of the client;
[0136] Generate target Mock data based on the target data structure.
[0137] Of course, those skilled in the art can understand that the processor can also implement the technical solution of the method for generating Mock data provided by any embodiment of the present invention.
[0138] Embodiment 6
[0139] Embodiment 6 of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the method for generating Mock data provided in the embodiment of the present invention is implemented. The method includes:
[0140] When a client access is detected, the operating environment information of the access client is obtained based on the package dependency;
[0141] When the operating environment information meets the set Mock conditions, obtain the basic client information of the access client;
[0142] Generate the target data structure of the target Mock data based on the basic information of the client;
[0143] Generate target Mock data based on the target data structure.
[0144] Of course, the computer program stored on the computer-readable storage medium provided by the embodiment of the present invention is not limited to the above method operations, and can also execute related operations of the method for generating Mock data provided by any embodiment of the present invention.
[0145] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0146] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0148] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0149] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for generating Mock data, characterized in that: include: When a client access is detected, the operating environment information of the access client is obtained based on the package dependency; When the operating environment information meets the set Mock conditions, obtain the basic client information of the access client; Generate a target data structure of target Mock data according to the client basic information; Generate the target Mock data based on the target data structure; Before obtaining the operating environment information of the access client based on the package dependency, the following is also included: Obtain a software development kit generated based on client information acquisition logic, and introduce the software development kit into Maven dependency; When the operating environment information meets the set Mock condition, before obtaining the client basic information of the access client, it also includes: Through the verification mechanism added in the software development kit, verify whether the operating environment information of the access client meets the set Mock conditions; The step of generating a target data structure of target Mock data according to the client basic information includes: determining a target data structure based on a class name in the client basic information.
2. The method according to claim 1, characterized in that The step of determining the target data structure based on the class name in the client basic information includes: Obtain the class name in the client basic information, and obtain the class structure corresponding to the class name; The target data structure is generated based on the structure of the class and a generic placeholder specification.
3. The method according to claim 1, characterized in that The generating the target Mock data based on the target data structure includes: The target data source of the access client is obtained, and the target Mock data of the target data structure is generated based on the target Mock data generation rule of the target data source.
4. The method according to claim 3, characterized in that The generating target Mock data of the target data structure based on the target Mock data generating rule of the target data source includes at least one of the following: When the target data source is historical data, the cached data of the target data structure is called as the target Mock data; When the target data source is automatically generated, generating Mock data based on the target data structure; When the target data source is intelligent recommendation or background data, the target Mock data of the target data structure is obtained by requesting a setting interface.
5. The method according to claim 4, characterized in that The step of obtaining target Mock data of the target data structure by requesting the setting interface includes: Determining whether the set interface is alive; When the setting interface survives, calling the setting interface to obtain target Mock data of the target data structure; When the setting interface is not alive, the cached data of the target data structure is called as the target Mock data or Mock data is generated based on the target data structure.
6. The method according to claim 5, characterized in that The determining whether the set interface is alive includes: Verify whether the method declaration of the setting interface is registered in the JSF registration center; When the method declaration is not registered in the JSF registration center, it is determined that the setting interface is not alive; When the method declaration is registered in the JSF registration center, it is determined whether the setting interface can call valid data within a set time period; When the setting interface can call valid data within a set time period, it is determined that the setting interface is alive; otherwise, it is determined that the setting interface is not alive.
7. The method according to claim 1, characterized in that Before generating the target data structure of the target Mock data according to the client basic information, it also includes: Get the Mock control status of the access client; When the Mock control state is in the on state, a target data structure of target Mock data is generated according to the client basic information.
8. A device for generating mock data, characterized in that: include: The operating environment acquisition module is used to acquire the operating environment information of the access client based on the package dependency when the client access is detected; A basic information acquisition module, used to acquire the basic client information of the access client when the operating environment information meets the set Mock conditions; A data structure generation module, used to generate a target data structure of target Mock data according to the client basic information; A Mock data generation module, used to generate the target Mock data according to the target data structure; The device further includes a package dependency introduction module, which is used to: Before obtaining the operating environment information of the access client based on the package dependency, obtaining a software development kit generated based on the client information acquisition logic, and introducing the software development kit into the Maven dependency; When the operating environment information meets the set Mock condition, before obtaining the client basic information of the access client, it also includes: Through the verification mechanism added in the software development kit, verify whether the operating environment information of the access client meets the set Mock conditions; The data structure generation module is specifically used to determine the target data structure based on the class name in the client basic information.
9. A computer device, characterized in that: The device comprises: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method for generating Mock data as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for generating Mock data as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Software testing method, software test device and readable storage medium
CN111090589A