WO2019075994A1 - Method, device and system for mock data at ios end, and storage medium - Google Patents

Method, device and system for mock data at ios end, and storage medium Download PDF

Info

Publication number
WO2019075994A1
WO2019075994A1 PCT/CN2018/081316 CN2018081316W WO2019075994A1 WO 2019075994 A1 WO2019075994 A1 WO 2019075994A1 CN 2018081316 W CN2018081316 W CN 2018081316W WO 2019075994 A1 WO2019075994 A1 WO 2019075994A1
Authority
WO
WIPO (PCT)
Prior art keywords
network
mock
interface
relationship table
data
Prior art date
Application number
PCT/CN2018/081316
Other languages
French (fr)
Chinese (zh)
Inventor
苏正权
张文明
陈少杰
Original Assignee
武汉斗鱼网络科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2019075994A1 publication Critical patent/WO2019075994A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/14Network analysis or design
    • H04L41/145Network analysis or design involving simulating, designing, planning or modelling of a network
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0817Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking functioning

Definitions

  • the invention relates to the field of Mock data technology, in particular to a method, a storage medium, a device and a system for Mock data on an iOS side.
  • Unit testing is the lowest level of testing activity to be performed during the software development process. During the unit testing process, the independent units of the software will be tested in isolation from the rest of the program. In the unit testing process, Some objects that are not easy to construct or are not easy to obtain can be tested by creating a virtual object called a Mock object.
  • the Mock object is a substitute for the actual object during unit testing.
  • the object of the present invention is to overcome the deficiencies of the above background art, and to provide a method, a storage medium, a device and a system for iOS-side Mock data, which can accurately and efficiently perform Mock data effects, and can simulate a network environment of Mock data, thereby Get better work results.
  • the technical solution adopted by the present invention is to provide a method for Mock data on an iOS side, the method comprising the following steps:
  • Establish a network output simulation component use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
  • S2 Establish a relationship table: loading a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and a custom Mock network The correspondence between the speed enumeration values;
  • the network output simulation component simulates a network request, acquires information of the network request interface according to the network request, and according to the first relationship table and the second relationship table, from the multiple interfaces.
  • the dynamic setting network interface matching the network request interface is obtained in the name, and the final Mock file name corresponding to the dynamically set network interface and the Mock network parameter are obtained by combining the customized Mock network speed enumeration value.
  • step S1 before the network output simulation component is first created, the current state of the system is determined. If the current system is in the debug state, the creation step is performed, and if the system is in a non-debug state, the system stops. Create a step that returns an empty object.
  • the second relationship table serves as a basis for judging the abnormal state of the network.
  • step S3 includes the following steps:
  • the network output simulation component simulates a network request, and requests, according to the network request, information about the network request interface.
  • S303 Determine whether a Mock data address exists in the Mock file name in the first relationship table, and determine whether the Mock data corresponding to the Mock data address exists. If any of the Mock data exists, convert the Mock data.
  • the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
  • the requestTime method of the OHHTTPStubs class simulates the normal network speed and uses the responsewithError method to simulate the network abnormality, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
  • the invention further provides a storage medium having stored thereon a computer program, characterized in that the computer program is executed by a processor to carry out the steps of the method according to any one of claims 1 to 4.
  • the present invention also provides an apparatus for Mock data on an iOS side, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor executes the computer program
  • an apparatus for Mock data on an iOS side comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor executes the computer program
  • the invention also provides a system for iOS-side Mock data, which is characterized in that: the system comprises a component creation module, a relationship table creation module, and a dynamic correspondence matching module;
  • the component creation module is configured to: create a network output simulation component, and use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
  • the relationship table creation module is configured to: load a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and the self Define the correspondence between the Mock network speed enumeration values;
  • the dynamic correspondence matching module is configured to: control the network output simulation component to simulate a network request, obtain information of a network request interface according to the network request, and according to the first relationship table and the second relationship table, Obtaining a dynamic setting network interface matching the network request interface, and combining the customized Mock network speed enumeration value to obtain a final Mock file name corresponding to the dynamically setting network interface and a Mock Network parameters.
  • the component creation module determines the current state of the system, and if the current system is in the debug state, the creation step is performed, and if the system is in a non-debug state, Stop the creation step and return an empty object.
  • the second relationship table serves as a basis for judging the abnormal state of the network.
  • the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
  • the requestTime method simulates the normal network speed and uses the responsewithError method to simulate the network anomaly, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
  • the network output analog component is defined by using the dispatch_once function, which can avoid memory occupation when a large amount of Mock data occurs, and avoid affecting normal work; and the first relation table can accurately convert the network request interface and the desired to be Mock interface.
  • the data file name is associated, and the number of interfaces of the network request interface is many.
  • the first relation table can distinguish which interfaces need Mock data;
  • the meaning of the second relationship table is that the network interface corresponds to the network speed of the Mock data, and Set the network speed when Mock data;
  • the present invention can obtain a better and more efficient Mock data effect, and can simulate the network environment of the Mock data, thereby obtaining better performance by using the network output simulation component, the first relational table, and the second relational table.
  • the effect of the work can be obtained by using the network output simulation component, the first relational table, and the second relational table.
  • the current state of the system is judged. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned;
  • the invention can detect the state of the system when the developer works, avoids forgetting to delete the relevant Mock code and causes the audit to be rejected, and ensures the smooth development work.
  • FIG. 1 is a flowchart of a method for Mock data of an iOS terminal according to an embodiment of the present invention
  • FIG. 2 is a schematic structural diagram of an apparatus for Mock data of an iOS terminal according to an embodiment of the present invention
  • FIG. 3 is a structural block diagram of a system for Mock data of an iOS terminal according to an embodiment of the present invention.
  • an embodiment of the present invention provides a method for Mock data on an iOS side, where the method includes the following steps:
  • Establish a network output simulation component use the dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
  • S2 Establish a relationship table: load a first relationship table and a second relationship table, where the first relationship table stores a correspondence between the interface name and the Mock file name, and the second relationship table stores the interface name and the custom Mock network speed enumeration value.
  • first relationship table stores a correspondence between the interface name and the Mock file name
  • second relationship table stores the interface name and the custom Mock network speed enumeration value.
  • the network output simulation component simulates the network request, intercepts the network request and acquires the information of the network request interface, and obtains the network request interface from the plurality of interface names according to the first relationship table and the second relationship table. Dynamically set the network interface, and combine the custom Mock network speed enumeration value to obtain the final Mock file name and Mock network parameters corresponding to the dynamically set network interface.
  • the network output simulation component is defined by using the dispatch_once function, which can avoid memory occupation when a large amount of Mock data occurs, and avoid affecting normal work, and then use the network output simulation component to simulate network request and perform iOS-side Mock data work. It is only necessary to call the first creation result; the first relation table can accurately associate the network request interface with the data file name to be converted into the Mock interface, and the number of interfaces of the network request interface is many, and the first relationship is utilized.
  • the table can distinguish which interfaces need Mock data; the meaning of the second relationship table is to match the network interface with the network speed of the Mock data, and can set the network speed in the Mock data; and output the simulation component, the first relationship table, and the second through the network
  • the relationship table can simulate the network environment of Mock data while obtaining accurate and efficient Mock data effects, so as to obtain better working effect.
  • the network output simulation component obtains the information of the network request interface
  • the network request interface exists in the corresponding relationship of the interface name, and therefore the first relationship table can obtain the dynamic setting network interface from the plurality of interface names, and then combines the second
  • the custom Mock network speed enumeration value of the relation table obtains the Mock network parameter corresponding to the dynamically setting network interface, thereby obtaining the final Mock file name and the Mock network parameter corresponding to the dynamically setting network interface;
  • the Mock network parameters include not only the transmission speed but also the network status information.
  • the network output analog component is a component of the present invention, and the name is not limited to the name.
  • a single component or a combination of multiple components that can achieve its function can be used as a network output analog component, a network output analog component.
  • the network output simulation component is introduced by using the pod method.
  • the specific usage method is: using the pod method in the iOS project to introduce the network output simulation component, only in the appdelegate, calling the network output simulation component setup method, and on the Mock interface Use the following implementation method to call the Mock file that exists in the main project; the implementation method is as follows:
  • the custom Mock network speed enumeration value is set by the staff to the corresponding interface according to the interface and the network speed mapping relationship, according to the enumeration value, use the switch syntax to select different Mock data networks.
  • Parameters call the requestTime method of the OHHTTPStubs class to simulate normal network speed, use the responsewithError method to simulate network anomalies.
  • the manner of intercepting the network request is a traditional way of obtaining a network request, such as using HttpHttpClient, HttpURLConnection or using a URL, and also performing network request interception based on OHHTTPStubs, and introducing OHHTTPStubs using a pod to intercept all network requests. .
  • the loading of the first relational table and the second relational table may be performed by lazy loading according to requirements, so as to improve the working efficiency of the device in data processing and reasonably allocate memory resources.
  • step S1 before the network output simulation component is first created, the current state of the system is determined. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned;
  • this step can detect the state of the system while the developer is working, and avoid forgetting to delete the relevant Mock code and cause the audit to be The refusal of the situation has ensured the smooth development of the work.
  • the second relation table is used as a basis for judging the abnormal state of the network, that is, the correspondence between the interface name and the custom Mock network speed enumeration value by other methods does not match the corresponding relationship in the second relationship table.
  • step S3 includes the following steps:
  • the network output analog component simulates a network request, intercepts the network request, and obtains information of the network request interface.
  • S303 Determine whether the Mock file name in the first relationship table has a Mock data address, and determine whether the Mock data corresponding to the Mock data address exists. If the Mock data exists, convert the Mock data into an OHHTTPStubsResponse format, and set the network request interface as Dynamically setting the network interface, and recording the Mock file corresponding to the network request interface is named the final Mock file name;
  • the custom Mock network speed enumeration value of the network request interface is selected, and the different Mock network parameters are selected according to the custom Mock network speed enumeration value, and the request time method of the OHHTTPStubs class is used to simulate normal.
  • the network speed and the responsewithError method are used to simulate the network anomaly, and the Mock network parameters with the fastest transmission speed and normal network are obtained, which are determined as Mock network parameters;
  • the URL refers to the interface of the Mock, and the jsonName represents the Mock file returned by the simulation, which contains the Mock data, the speedModel is an enumeration amount, and the Mock data network speed is enumerated.
  • requestTime is an analog method, which simulates the network conditions at high speed or low speed or other conditions according to the obtained normal network parameters, so that the network parameters can be notified to the development staff in a way of viewing, so that the development staff Can understand the current network situation;
  • responsewithError is an analog method, when it obtains the network parameters of the abnormal state, it can calculate that the network condition is in an abnormal state, so that the network parameters can be notified to the development staff in a way to view;
  • OHHTTPStubsResponse is a technical means commonly used by those skilled in the art, and OHHTTPStubsResponse can be specified as a file, a picture, a data data, or a json object, and the advantage is that it is flexible.
  • the embodiment of the present invention further provides a storage medium, where the computer program is stored, and the method for realizing the iOS-side Mock data in the foregoing embodiments can be implemented when the computer program is executed by the processor A step of.
  • the storage medium includes a U disk, a mobile hard disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), a disk, or an optical disk, and the like, which can store program codes. .
  • the embodiment of the present invention further provides a device for iOS-side Mock data, including a memory, a processor, and a memory stored on the processor and running on the processor.
  • a computer program characterized in that the processor performs the steps of the method of any one of claims 1 to 4 when the computer program is executed.
  • an embodiment of the present invention further provides a system for iOS-side Mock data, where the system includes a component creation module, a relationship table creation module, and a dynamic correspondence matching module.
  • the component creation module is used to: create a network output simulation component, and use the dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
  • the relationship table creation module is configured to: load the first relationship table and the second relationship table, the first relationship table saves the correspondence between the interface name and the Mock file name, and the second relationship table saves the interface name and the custom Mock network speed enumeration value.
  • the dynamic correspondence matching module is configured to: control the network output simulation component to simulate a network request, acquire information of the network request interface according to the network request, and obtain a network request from multiple interface names according to the first relationship table and the second relationship table.
  • the interface dynamically matches the network interface and combines the custom Mock network speed enumeration values to obtain the final Mock file name and Mock network parameters corresponding to the dynamically set network interface.
  • the component creation module determines the current state of the system. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned.
  • Extract the custom Mock network speed enumeration value of the network request interface in the second relation table select different pending Mock network parameters according to the custom Mock network speed enumeration value, and simulate the normal network speed by using the requestTime method of the OHHTTPStubs class. And use the responsewithError method to simulate the network anomaly, obtain the Mock network parameters with the fastest transmission speed and normal network, and set it as the Mock network parameter;
  • the second relational table serves as a basis for judging the abnormal state of the network.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Environmental & Geological Engineering (AREA)
  • Debugging And Monitoring (AREA)
  • Computer And Data Communications (AREA)

Abstract

Disclosed are a method, device and system for Mock data at an IOS end, and a storage medium, relating to the technical field of Mock data. The method comprises: establishing a network output simulation assembly: using a dispatch_once function to define the network output simulation assembly, so that after the network output simulation assembly is created for the first time, a creation result of the first time is called in all subsequent creation; establishing a relation table: carrying out lazy loading of a first relation table and a second relation table, wherein the first relation table saves a correlation between an interface name and a Mock file name, and the second relation table saves a correlation between the interface name and a customized Mock network speed value; and network request interception: the network output simulation assembly acquiring information about a network request interface, and acquiring, according to the first relation table and the second relation table, a dynamically set network interface, the Mock file name and a Mock network parameter. While obtaining a precise and efficient Mock data effect, the present invention can simulate a network environment of Mock data, so as to obtain a better work effect.

Description

一种iOS端Mock数据的方法、存储介质、设备及***Method, storage medium, device and system for iOS-side Mock data 技术领域Technical field
本发明涉及Mock数据技术领域,具体来讲是一种iOS端Mock数据的方法、存储介质、设备及***。The invention relates to the field of Mock data technology, in particular to a method, a storage medium, a device and a system for Mock data on an iOS side.
背景技术Background technique
目前,iOS客户端开发中,由于后端和客户端开发同时进行,客户端的开发过程中常常需要等待后端的接口完成,才能进行相关客户端逻辑的开发,造成客户端开发效率低下,此时则需要mock后端的数据从而提高客户端开发效率,缩短工时。At present, in the development of iOS client, since the back-end and client-side development are carried out at the same time, the development process of the client often needs to wait for the interface of the back-end to complete, so that the development of the relevant client logic can be performed, resulting in inefficient development of the client, and at this time, The data of the mock backend is needed to improve client development efficiency and shorten working hours.
单元测试是在软件开发过程中要进行的最低级别的测试活动,在单元测试过程中,软件的独立单元将在与程序的其他部分相隔离的情况下进行测试,而在单元测试过程中,对于某些不容易构造或者不容易获取的对象,可以采用创建一个虚拟的对象来进行测试的方式,这个虚拟的对象就称为Mock对象,Mock对象就是实际中的对象在单元测试期间的代替品。Unit testing is the lowest level of testing activity to be performed during the software development process. During the unit testing process, the independent units of the software will be tested in isolation from the rest of the program. In the unit testing process, Some objects that are not easy to construct or are not easy to obtain can be tested by creating a virtual object called a Mock object. The Mock object is a substitute for the actual object during unit testing.
而现有的Mock数据方案绝大多数使用OHHTTPStubs库来做http数据Mock,需要在事先手动创建一张映射表,分别映射请求接口名称和待Mock的数据文件名称,此方法要求映射请求接口名称在编译以前就必须在Mock类的关系映射表中存在映射关系,故而造成Mock数据效率较低,从而最终导致客户端开发效率低下。Most of the existing Mock data solutions use the OHHTTPStubs library to do the http data Mock. You need to manually create a mapping table in advance to map the request interface name and the data file name to be Mock. This method requires the mapping request interface name to be Before compiling, there must be a mapping relationship in the relationship mapping table of the Mock class, which results in low efficiency of the Mock data, which ultimately leads to inefficient client development.
发明内容Summary of the invention
本发明的目的是为了克服上述背景技术的不足,提供一种iOS端 Mock数据的方法、存储介质、设备及***,获得精准且高效的Mock数据效果的同时,能够模拟Mock数据的网络环境,从而获得较佳的工作效果。The object of the present invention is to overcome the deficiencies of the above background art, and to provide a method, a storage medium, a device and a system for iOS-side Mock data, which can accurately and efficiently perform Mock data effects, and can simulate a network environment of Mock data, thereby Get better work results.
为达到以上目的,本发明采取的技术方案是:提供一种iOS端Mock数据的方法,该方法包括以下步骤:To achieve the above objective, the technical solution adopted by the present invention is to provide a method for Mock data on an iOS side, the method comprising the following steps:
S1、建立网络输出模拟组件:利用dispatch_once函数定义网络输出模拟组件,使所述网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;S1. Establish a network output simulation component: use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
S2、建立关系表:加载第一关系表以及第二关系表,所述第一关系表保存接口名和Mock文件名之间的对应关系,所述第二关系表保存所述接口名和自定义Mock网速枚举值之间的对应关系;S2: Establish a relationship table: loading a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and a custom Mock network The correspondence between the speed enumeration values;
S3、动态对应匹配:所述网络输出模拟组件模拟网络请求,根据所述网络请求获取网络请求接口的信息,并依据所述第一关系表以及所述第二关系表,从多个所述接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合所述自定义Mock网速枚举值,获得与所述动态设定网络接口对应的最终Mock文件名以及Mock网络参数。S3. Dynamic correspondence matching: the network output simulation component simulates a network request, acquires information of the network request interface according to the network request, and according to the first relationship table and the second relationship table, from the multiple interfaces. The dynamic setting network interface matching the network request interface is obtained in the name, and the final Mock file name corresponding to the dynamically set network interface and the Mock network parameter are obtained by combining the customized Mock network speed enumeration value.
在上述技术方案的基础上,步骤S1中,所述网络输出模拟组件初次创建之前,对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象。On the basis of the foregoing technical solution, in step S1, before the network output simulation component is first created, the current state of the system is determined. If the current system is in the debug state, the creation step is performed, and if the system is in a non-debug state, the system stops. Create a step that returns an empty object.
在上述技术方案的基础上,所述第二关系表作为对网络异常状态的判断依据。Based on the foregoing technical solution, the second relationship table serves as a basis for judging the abnormal state of the network.
在上述技术方案的基础上,步骤S3包括以下步骤:Based on the above technical solution, step S3 includes the following steps:
S301、所述网络输出模拟组件模拟网络请求,根据所述网络请求并获取所述网络请求接口的信息;S301. The network output simulation component simulates a network request, and requests, according to the network request, information about the network request interface.
S302、判断所述第一关系表是否存在所述网络请求接口相匹配的所述接口名以及与所述接口名对应的所述Mock文件名,若存在则开启所述网络请求接口的Mock数据工作;S302. Determine whether the first relationship table has the interface name that matches the network request interface and the Mock file name corresponding to the interface name, and if yes, enable the Mock data work of the network request interface. ;
S303、判断所述第一关系表中的所述Mock文件名是否存在Mock数据地址,并判断所述Mock数据地址对应的所述Mock数据是否存在,若存均存在,则将所述Mock数据转化为OHHTTPStubsResponse格式,将所述网络请求接口定为所述动态设定网络接口,并记录所述网络请求接口对应的所述Mock文件名为所述最终Mock文件名;S303. Determine whether a Mock data address exists in the Mock file name in the first relationship table, and determine whether the Mock data corresponding to the Mock data address exists. If any of the Mock data exists, convert the Mock data. For the OHHTTPStubsResponse format, the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
S304、取出所述第二关系表中,所述网络请求接口的所述自定义Mock网速枚举值,以所述自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的所述待定Mock网络参数,定为所述Mock网络参数;S304, in the second relationship table, the custom Mock network speed enumeration value of the network request interface, and selecting different pending Mock network parameters according to the custom Mock network speed enumeration value, The requestTime method of the OHHTTPStubs class simulates the normal network speed and uses the responsewithError method to simulate the network abnormality, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
S305、提取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数。S305. Extract the dynamic setting network interface, the final Mock file name, and the Mock network parameter.
本发明还提供一种存储介质,其上存储有计算机程序,其特征在于:所述计算机程序被处理器执行时实现上述权利要求1至4中任一项所述方法的步骤。The invention further provides a storage medium having stored thereon a computer program, characterized in that the computer program is executed by a processor to carry out the steps of the method according to any one of claims 1 to 4.
本发明还提供一种iOS端Mock数据的设备,包括存储器、处理器及存储在所述存储器上并在所述处理器上运行的计算机程序,其特征在于:所述处理器执行所述计算机程序时实现上述权利要求1至4中任一项所述方法的步骤。The present invention also provides an apparatus for Mock data on an iOS side, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor executes the computer program The steps of the method of any of the preceding claims 1 to 4 are achieved.
本发明还提供一种iOS端Mock数据的***,其特征在于:该***包括组件创建模块、关系表创建模块、动态对应匹配模块;The invention also provides a system for iOS-side Mock data, which is characterized in that: the system comprises a component creation module, a relationship table creation module, and a dynamic correspondence matching module;
所述组件创建模块用于:创建网络输出模拟组件,并利用dispatch_once函数定义网络输出模拟组件,使所述网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;The component creation module is configured to: create a network output simulation component, and use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
所述关系表创建模块用于:加载第一关系表以及第二关系表,所述第一关系表保存接口名和Mock文件名之间的对应关系,所述第二关系表保存所述接口名和自定义Mock网速枚举值之间的对应关系;The relationship table creation module is configured to: load a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and the self Define the correspondence between the Mock network speed enumeration values;
所述动态对应匹配模块用于:控制所述网络输出模拟组件模拟网络请求,根据所述网络请求获取网络请求接口的信息,并依据所述第一关系表以及所述第二关系表,从多个所述接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合所述自定义Mock网速枚举值,获得与所述动态设定网络接口对应的最终Mock文件名以及Mock网络参数。The dynamic correspondence matching module is configured to: control the network output simulation component to simulate a network request, obtain information of a network request interface according to the network request, and according to the first relationship table and the second relationship table, Obtaining a dynamic setting network interface matching the network request interface, and combining the customized Mock network speed enumeration value to obtain a final Mock file name corresponding to the dynamically setting network interface and a Mock Network parameters.
在上述技术方案的基础上,所述网络输出模拟组件初次创建之前,所述组件创建模块对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象。On the basis of the foregoing technical solution, before the network output simulation component is first created, the component creation module determines the current state of the system, and if the current system is in the debug state, the creation step is performed, and if the system is in a non-debug state, Stop the creation step and return an empty object.
在上述技术方案的基础上,所述第二关系表作为对网络异常状态的判断依据。Based on the foregoing technical solution, the second relationship table serves as a basis for judging the abnormal state of the network.
在上述技术方案的基础上,所述动态对应匹配模块获取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数的具体流程为:On the basis of the foregoing technical solution, the specific process of the dynamic correspondence matching module acquiring the dynamic setting network interface, the final Mock file name, and the Mock network parameter is:
控制所述网络输出模拟组件模拟网络请求,根据所述网络请求获取所述网络请求接口的信息;Controlling the network output analog component to simulate a network request, and acquiring information of the network request interface according to the network request;
判断所述第一关系表是否存在所述网络请求接口相匹配的所述接口名以及与所述接口名对应的所述Mock文件名,若存在则开启所 述网络请求接口的Mock数据工作;Determining whether the first relationship table has the interface name that matches the network request interface and the Mock file name corresponding to the interface name, and if yes, enabling Mock data work of the network request interface;
判断所述第一关系表中的所述Mock文件名是否存在Mock数据地址,并判断所述Mock数据地址对应的所述Mock数据是否存在,若存均存在,则将所述Mock数据转化为OHHTTPStubsResponse格式,将所述网络请求接口定为所述动态设定网络接口,并记录所述网络请求接口对应的所述Mock文件名为所述最终Mock文件名;Determining whether the Mock file name in the first relationship table has a Mock data address, and determining whether the Mock data corresponding to the Mock data address exists, and if the existence exists, converting the Mock data into an OHHTTPStubsResponse a format, the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
取出所述第二关系表中,所述网络请求接口的所述自定义Mock网速枚举值,以所述自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的所述待定Mock网络参数,定为所述Mock网络参数;Extracting, in the second relationship table, the custom Mock network speed enumeration value of the network request interface, and selecting different pending Mock network parameters according to the custom Mock network speed enumeration value, using the OHHTTPStubs class The requestTime method simulates the normal network speed and uses the responsewithError method to simulate the network anomaly, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
提取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数。Extracting the dynamic setting network interface, the final Mock file name, and the Mock network parameter.
本发明的有益效果在于:The beneficial effects of the invention are:
(1)本发明中利用dispatch_once函数定义网络输出模拟组件,能够避免在出现大量Mock数据时造成内存占用,避免影响正常工作;利用第一关系表能够精准地将网络请求接口和所要转化成Mock接口数据文件名对应起来,而网络请求接口的接口数量有很多,利用第一关系表能够分清哪些接口需要Mock数据;第二关系表的意义在于将网络接口与Mock数据的网速进行对应,可以在Mock数据时设置网速;(1) In the present invention, the network output analog component is defined by using the dispatch_once function, which can avoid memory occupation when a large amount of Mock data occurs, and avoid affecting normal work; and the first relation table can accurately convert the network request interface and the desired to be Mock interface. The data file name is associated, and the number of interfaces of the network request interface is many. The first relation table can distinguish which interfaces need Mock data; the meaning of the second relationship table is that the network interface corresponds to the network speed of the Mock data, and Set the network speed when Mock data;
与现有技术相比,本发明借助网络输出模拟组件、第一关系表以及第二关系表,能够在获得精准且高效的Mock数据效果的同时,能够模拟Mock数据的网络环境,从而获得较佳的工作效果。Compared with the prior art, the present invention can obtain a better and more efficient Mock data effect, and can simulate the network environment of the Mock data, thereby obtaining better performance by using the network output simulation component, the first relational table, and the second relational table. The effect of the work.
(2)本发明中,网络输出模拟组件初次创建之前,对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象;(2) In the present invention, before the network output simulation component is first created, the current state of the system is judged. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned;
与现有技术相比,本发明能够在开发人员工作时检测***的状态,避免忘记删除相关Mock代码导致审核被拒的情况出现,保证了开发工作的流畅。Compared with the prior art, the invention can detect the state of the system when the developer works, avoids forgetting to delete the relevant Mock code and causes the audit to be rejected, and ensures the smooth development work.
附图说明DRAWINGS
图1为本发明实施例中iOS端Mock数据的方法的流程图;1 is a flowchart of a method for Mock data of an iOS terminal according to an embodiment of the present invention;
图2为本发明实施例中iOS端Mock数据的设备的结构示意图;2 is a schematic structural diagram of an apparatus for Mock data of an iOS terminal according to an embodiment of the present invention;
图3为本发明实施例中iOS端Mock数据的***的结构框图。FIG. 3 is a structural block diagram of a system for Mock data of an iOS terminal according to an embodiment of the present invention.
具体实施方式Detailed ways
下面结合附图及具体实施例对本发明作进一步的详细描述。The present invention will be further described in detail below with reference to the drawings and specific embodiments.
参见图1所示,本发明实施例提供一种iOS端Mock数据的方法,该方法包括以下步骤:As shown in FIG. 1 , an embodiment of the present invention provides a method for Mock data on an iOS side, where the method includes the following steps:
S1、建立网络输出模拟组件:利用dispatch_once函数定义网络输出模拟组件,使网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;S1. Establish a network output simulation component: use the dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
S2、建立关系表:加载第一关系表以及第二关系表,第一关系表保存接口名和Mock文件名之间的对应关系,第二关系表保存接口名和自定义Mock网速枚举值之间的对应关系;S2: Establish a relationship table: load a first relationship table and a second relationship table, where the first relationship table stores a correspondence between the interface name and the Mock file name, and the second relationship table stores the interface name and the custom Mock network speed enumeration value. Correspondence relationship;
S3、动态对应匹配:网络输出模拟组件模拟网络请求,拦截网络请求并获取网络请求接口的信息,并依据第一关系表以及第二关系表,从多个接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合自定义Mock网速枚举值,获得与动态设定网络接口对应的最终 Mock文件名以及Mock网络参数。S3, dynamic correspondence matching: the network output simulation component simulates the network request, intercepts the network request and acquires the information of the network request interface, and obtains the network request interface from the plurality of interface names according to the first relationship table and the second relationship table. Dynamically set the network interface, and combine the custom Mock network speed enumeration value to obtain the final Mock file name and Mock network parameters corresponding to the dynamically set network interface.
本发明中,利用dispatch_once函数定义网络输出模拟组件,能够避免在出现大量Mock数据时造成内存占用,避免影响正常工作,当后续还要利用网络输出模拟组件模拟网络请求并进行iOS端Mock数据工作时,仅需调用第一次创建结果即可;利用第一关系表能够精准地将网络请求接口和所要转化成Mock接口数据文件名对应起来,而网络请求接口的接口数量有很多,利用第一关系表能够分清哪些接口需要Mock数据;第二关系表的意义在于将网络接口与Mock数据的网速进行对应,可以在Mock数据时设置网速;借助网络输出模拟组件、第一关系表以及第二关系表,能够在获得精准且高效的Mock数据效果的同时,能够模拟Mock数据的网络环境,从而获得较佳的工作效果。In the present invention, the network output simulation component is defined by using the dispatch_once function, which can avoid memory occupation when a large amount of Mock data occurs, and avoid affecting normal work, and then use the network output simulation component to simulate network request and perform iOS-side Mock data work. It is only necessary to call the first creation result; the first relation table can accurately associate the network request interface with the data file name to be converted into the Mock interface, and the number of interfaces of the network request interface is many, and the first relationship is utilized. The table can distinguish which interfaces need Mock data; the meaning of the second relationship table is to match the network interface with the network speed of the Mock data, and can set the network speed in the Mock data; and output the simulation component, the first relationship table, and the second through the network The relationship table can simulate the network environment of Mock data while obtaining accurate and efficient Mock data effects, so as to obtain better working effect.
其中,网络输出模拟组件获取网络请求接口的信息时,网络请求接口存在于接口名的对应关系,故而并第一关系表,能够从多个接口名中获取动态设定网络接口,再结合第二关系表的自定义Mock网速枚举值,获得与动态设定网络接口对应的Mock网络参数,从而获得与动态设定网络接口对应的最终Mock文件名以及Mock网络参数;Wherein, when the network output simulation component obtains the information of the network request interface, the network request interface exists in the corresponding relationship of the interface name, and therefore the first relationship table can obtain the dynamic setting network interface from the plurality of interface names, and then combines the second The custom Mock network speed enumeration value of the relation table obtains the Mock network parameter corresponding to the dynamically setting network interface, thereby obtaining the final Mock file name and the Mock network parameter corresponding to the dynamically setting network interface;
而Mock网络参数不仅包括传输的网速,还包括网络状态信息。The Mock network parameters include not only the transmission speed but also the network status information.
需要说明的是,网络输出模拟组件为本发明的一种组件,其名称不限于该名称,能够达到其作用的单个组件或多个组件的组合体均可以作为网络输出模拟组件,网络输出模拟组件可以用于模拟不同网络环境下的网络请求;It should be noted that the network output analog component is a component of the present invention, and the name is not limited to the name. A single component or a combination of multiple components that can achieve its function can be used as a network output analog component, a network output analog component. Can be used to simulate network requests in different network environments;
而网络输出模拟组件使用pod的方式引入,具体使用方法为:在iOS项目中使用pod的方式引入网络输出模拟组件,只需要在appdelegate中,调用网络输出模拟组件的setup方法,并在Mock接 口的时候使用下面实施方法即可调用存在于主工程的Mock文件;实施方法如下:The network output simulation component is introduced by using the pod method. The specific usage method is: using the pod method in the iOS project to introduce the network output simulation component, only in the appdelegate, calling the network output simulation component setup method, and on the Mock interface Use the following implementation method to call the Mock file that exists in the main project; the implementation method is as follows:
setURLString:(NSString*)urlsetURLString:(NSString*)url
JsonName:(NSString*)jsonJsonName: (NSString*)json
speedModel:(DYMockDownloadSpeed)speedModel。speedModel: (DYMockDownloadSpeed) speedModel.
另外,自定义Mock网速枚举值,该网速枚举值为工作人员向对应接口根据接口和网速映射关系来设定的,根据这个枚举值,使用switch语法选择不同的Mock数据网络参数,调用OHHTTPStubs类的requestTime方法来模拟正常网速,使用responsewithError方法来模拟网络异常情况。In addition, the custom Mock network speed enumeration value, the network speed enumeration value is set by the staff to the corresponding interface according to the interface and the network speed mapping relationship, according to the enumeration value, use the switch syntax to select different Mock data networks. Parameters, call the requestTime method of the OHHTTPStubs class to simulate normal network speed, use the responsewithError method to simulate network anomalies.
在本实施例中,拦截网络请求的方式为传统的获取网络请求的方式,诸如使用HttpHttpClient,HttpURLConnection或者使用URL,还可以基于OHHTTPStubs做网络请求拦截,使用pod引入OHHTTPStubs,用来拦截所有的网络请求。In this embodiment, the manner of intercepting the network request is a traditional way of obtaining a network request, such as using HttpHttpClient, HttpURLConnection or using a URL, and also performing network request interception based on OHHTTPStubs, and introducing OHHTTPStubs using a pod to intercept all network requests. .
需要说明的是,Mock文件名中存在存储Mock文件的数据地址。It should be noted that the data address of the Mock file exists in the Mock file name.
在本实施例中,根据需求,加载第一关系表以及第二关系表可以采用懒加载的方式,以提高设备在数据处理时的工作效率,合理分配内存资源。In this embodiment, the loading of the first relational table and the second relational table may be performed by lazy loading according to requirements, so as to improve the working efficiency of the device in data processing and reasonably allocate memory resources.
进一步地,步骤S1中,网络输出模拟组件初次创建之前,对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象;Further, in step S1, before the network output simulation component is first created, the current state of the system is determined. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned;
由于开发人员在debug状态下开发使用Mock数据,提交审核时忘记了删除相关Mock代码,导致审核被拒,因此本步骤能够在开发 人员工作时检测***的状态,避免忘记删除相关Mock代码导致审核被拒的情况出现,保证了开发工作的流畅。Since the developer develops and uses the Mock data in the debug state, and forgot to delete the relevant Mock code when submitting the audit, the audit is rejected. Therefore, this step can detect the state of the system while the developer is working, and avoid forgetting to delete the relevant Mock code and cause the audit to be The refusal of the situation has ensured the smooth development of the work.
进一步地,第二关系表作为对网络异常状态的判断依据,即通过其他方法识别接口名、自定义Mock网速枚举值的对应关系与第二关系表中的对应关系不符。Further, the second relation table is used as a basis for judging the abnormal state of the network, that is, the correspondence between the interface name and the custom Mock network speed enumeration value by other methods does not match the corresponding relationship in the second relationship table.
具体地,步骤S3包括以下步骤:Specifically, step S3 includes the following steps:
S301、网络输出模拟组件模拟网络请求,拦截网络请求并获取网络请求接口的信息;S301. The network output analog component simulates a network request, intercepts the network request, and obtains information of the network request interface.
S302、判断第一关系表是否存在网络请求接口相匹配的接口名以及与接口名对应的Mock文件名,若存在则开启网络请求接口的Mock数据工作;S302. Determine whether the first relationship table has an interface name matching the network request interface and a Mock file name corresponding to the interface name, and if yes, enable the Mock data of the network request interface to work;
S303、判断第一关系表中的Mock文件名是否存在Mock数据地址,并判断Mock数据地址对应的Mock数据是否存在,若存均存在,则将Mock数据转化为OHHTTPStubsResponse格式,将网络请求接口定为动态设定网络接口,并记录网络请求接口对应的Mock文件名为最终Mock文件名;S303. Determine whether the Mock file name in the first relationship table has a Mock data address, and determine whether the Mock data corresponding to the Mock data address exists. If the Mock data exists, convert the Mock data into an OHHTTPStubsResponse format, and set the network request interface as Dynamically setting the network interface, and recording the Mock file corresponding to the network request interface is named the final Mock file name;
S304、取出第二关系表中,网络请求接口的自定义Mock网速枚举值,以自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的待定Mock网络参数,定为Mock网络参数;S304. In the second relation table, the custom Mock network speed enumeration value of the network request interface is selected, and the different Mock network parameters are selected according to the custom Mock network speed enumeration value, and the request time method of the OHHTTPStubs class is used to simulate normal. The network speed and the responsewithError method are used to simulate the network anomaly, and the Mock network parameters with the fastest transmission speed and normal network are obtained, which are determined as Mock network parameters;
S305、提取动态设定网络接口、最终Mock文件名以及Mock网络参数;S305. Extract a dynamic setting network interface, a final Mock file name, and a Mock network parameter.
其中,S301中,使用pod引入OHHTTPStubs,用来拦截所有的网络请求时,所用的调用方法如下:Among them, in S301, when Pod is used to introduce OHHTTPStubs, which is used to intercept all network requests, the calling method is as follows:
OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest*_Nonnull request)block1()OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest*_Nonnull request)block1()
withStubResponse:^OHHTTPStubsResponse*_Nonnull(NSURLRequest*_Nonnull request)block2();withStubResponse:^OHHTTPStubsResponse*_Nonnull(NSURLRequest*_Nonnull request)block2();
而S305中,所用的调用方法如下:setURLString:(NSString*)urlIn S305, the calling method used is as follows: setURLString:(NSString*)url
JsonName:(NSString*)jsonJsonName: (NSString*)json
speedModel:(DYMockDownloadSpeed)speedModel;speedModel: (DYMockDownloadSpeed) speedModel;
URL指Mock的接口,jsonName表示模拟返回的Mock文件,里面装有Mock数据,speedModel为一个枚举量,枚举Mock数据网速。The URL refers to the interface of the Mock, and the jsonName represents the Mock file returned by the simulation, which contains the Mock data, the speedModel is an enumeration amount, and the Mock data network speed is enumerated.
需要说明的是,requestTime为一种模拟方法,根据获得的正常的网络参数,模拟高速或低速或其他情况下的网络状况,从而将网络参数以便于查看的方式告知开发工作人员,使得开发工作人员能够了解当前的网络情况;responsewithError为一种模拟方法,当其获得异常状态的网络参数时,能够运算显示网络状况处于异常状态,从而将网络参数以便于查看的方式告知开发工作人员;It should be noted that requestTime is an analog method, which simulates the network conditions at high speed or low speed or other conditions according to the obtained normal network parameters, so that the network parameters can be notified to the development staff in a way of viewing, so that the development staff Can understand the current network situation; responsewithError is an analog method, when it obtains the network parameters of the abnormal state, it can calculate that the network condition is in an abnormal state, so that the network parameters can be notified to the development staff in a way to view;
另外,OHHTTPStubsResponse为本领域技术人员常用的技术手段,OHHTTPStubsResponse可以指定为文件、图片、data数据、或者json对象,优势在于比较灵活。In addition, OHHTTPStubsResponse is a technical means commonly used by those skilled in the art, and OHHTTPStubsResponse can be specified as a file, a picture, a data data, or a json object, and the advantage is that it is flexible.
对应上述的iOS端Mock数据的方法,本发明实施例还提供一种存储介质,其上存储有计算机程序,该计算机程序被处理器执行时可实现上述各实施例中的iOS端Mock数据的方法的步骤。需要说明的是,存储介质包括U盘、移动硬盘、ROM(Read-Only Memory,只读存储器)、RAM(RandomAccess Memory,随机存取存储器)、磁碟或者光盘等各种可以存储程序代码的介质。Corresponding to the above method for iOS-side Mock data, the embodiment of the present invention further provides a storage medium, where the computer program is stored, and the method for realizing the iOS-side Mock data in the foregoing embodiments can be implemented when the computer program is executed by the processor A step of. It should be noted that the storage medium includes a U disk, a mobile hard disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), a disk, or an optical disk, and the like, which can store program codes. .
另外,参见图2所示,对应上述的iOS端Mock数据的方法,本发明实施例还提供一种iOS端Mock数据的设备,包括存储器、处理器及存储在存储器上并在处理器上运行的计算机程序,其特征在于:处理器执行计算机程序时实现上述权利要求1至4中任一项方法的步骤。In addition, as shown in FIG. 2, the embodiment of the present invention further provides a device for iOS-side Mock data, including a memory, a processor, and a memory stored on the processor and running on the processor. A computer program, characterized in that the processor performs the steps of the method of any one of claims 1 to 4 when the computer program is executed.
参见图3所示,本发明实施例还提供一种iOS端Mock数据的***,该***包括组件创建模块、关系表创建模块、动态对应匹配模块;As shown in FIG. 3, an embodiment of the present invention further provides a system for iOS-side Mock data, where the system includes a component creation module, a relationship table creation module, and a dynamic correspondence matching module.
组件创建模块用于:创建网络输出模拟组件,并利用dispatch_once函数定义网络输出模拟组件,使网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;The component creation module is used to: create a network output simulation component, and use the dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
关系表创建模块用于:加载第一关系表以及第二关系表,第一关系表保存接口名和Mock文件名之间的对应关系,第二关系表保存接口名和自定义Mock网速枚举值之间的对应关系;The relationship table creation module is configured to: load the first relationship table and the second relationship table, the first relationship table saves the correspondence between the interface name and the Mock file name, and the second relationship table saves the interface name and the custom Mock network speed enumeration value. Correspondence between
动态对应匹配模块用于:控制所述网络输出模拟组件模拟网络请求,根据网络请求获取网络请求接口的信息,并依据第一关系表以及第二关系表,从多个接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合自定义Mock网速枚举值,获得与动态设定网络接口对应的最终Mock文件名以及Mock网络参数。The dynamic correspondence matching module is configured to: control the network output simulation component to simulate a network request, acquire information of the network request interface according to the network request, and obtain a network request from multiple interface names according to the first relationship table and the second relationship table. The interface dynamically matches the network interface and combines the custom Mock network speed enumeration values to obtain the final Mock file name and Mock network parameters corresponding to the dynamically set network interface.
进一步地,网络输出模拟组件初次创建之前,组件创建模块对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象。Further, before the network output simulation component is first created, the component creation module determines the current state of the system. If the current system is in the debug state, the creation step is performed. If the system is in the non-debug state, the creation step is stopped, and the empty object is returned.
进一步地,动态对应匹配模块获取动态设定网络接口、最终Mock文件名以及Mock网络参数的具体流程为:Further, the specific process of the dynamic correspondence matching module for dynamically setting the network interface, the final Mock file name, and the Mock network parameter is:
控制所述网络输出模拟组件模拟网络请求,根据所述网络请求获取网络请求接口的信息;Controlling, by the network output analog component, a network request, and acquiring information of the network request interface according to the network request;
判断第一关系表是否存在网络请求接口相匹配的接口名以及与接口名对应的Mock文件名,若存在则开启网络请求接口的Mock数据工作;Determining whether the first relation table has an interface name matching the network request interface and a Mock file name corresponding to the interface name, and if yes, enabling the Mock data of the network request interface to work;
判断第一关系表中的Mock文件名是否存在Mock数据地址,并判断Mock数据地址对应的Mock数据是否存在,若存均存在,则将Mock数据转化为OHHTTPStubsResponse格式,将网络请求接口定为动态设定网络接口,并记录网络请求接口对应的Mock文件名为最终Mock文件名;Determine whether there is a Mock data address in the Mock file name in the first relation table, and determine whether the Mock data corresponding to the Mock data address exists. If the Mock data exists, the Mock data is converted into the OHHTTPStubsResponse format, and the network request interface is set as the dynamic setting. Set the network interface, and record the Mock file corresponding to the network request interface named the final Mock file name;
取出第二关系表中,网络请求接口的自定义Mock网速枚举值,以自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的待定Mock网络参数,定为Mock网络参数;Extract the custom Mock network speed enumeration value of the network request interface in the second relation table, select different pending Mock network parameters according to the custom Mock network speed enumeration value, and simulate the normal network speed by using the requestTime method of the OHHTTPStubs class. And use the responsewithError method to simulate the network anomaly, obtain the Mock network parameters with the fastest transmission speed and normal network, and set it as the Mock network parameter;
提取动态设定网络接口、最终Mock文件名以及Mock网络参数。Extract the dynamic setting network interface, the final Mock file name, and the Mock network parameters.
优选地,第二关系表作为对网络异常状态的判断依据。Preferably, the second relational table serves as a basis for judging the abnormal state of the network.
需要说明的是:上述实施例提供的***在实现iOS端Mock数据操作时,仅以上述各功能模块的划分进行举例说明,实际应用中,可根据需要而将上述功能分配由不同功能模块完成,即将***的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。It should be noted that, when the system provided by the foregoing embodiment implements the Mock data operation on the iOS side, only the division of the above functional modules is illustrated. In an actual application, the foregoing function assignment may be completed by different functional modules according to requirements. The internal structure of the system is divided into different functional modules to complete all or part of the functions described above.
本发明不局限于上述实施方式,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也视为本发明的保护范围之内。The present invention is not limited to the above embodiments, and those skilled in the art can also make several improvements and retouchings without departing from the principles of the present invention. These improvements and retouchings are also considered as protection of the present invention. Within the scope.
本说明书中未作详细描述的内容属于本领域专业技术人员公知的现有技术。The contents not described in detail in the present specification belong to the prior art well known to those skilled in the art.

Claims (10)

  1. 一种iOS端Mock数据的方法,其特征在于,该方法包括以下步骤:A method for Mock data on an iOS side, characterized in that the method comprises the following steps:
    S1、建立网络输出模拟组件:利用dispatch_once函数定义网络输出模拟组件,使所述网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;S1. Establish a network output simulation component: use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
    S2、建立关系表:加载第一关系表以及第二关系表,所述第一关系表保存接口名和Mock文件名之间的对应关系,所述第二关系表保存所述接口名和自定义Mock网速枚举值之间的对应关系;S2: Establish a relationship table: loading a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and a custom Mock network The correspondence between the speed enumeration values;
    S3、动态对应匹配:所述网络输出模拟组件模拟网络请求,拦截网络请求并获取网络请求接口的信息,并依据所述第一关系表以及所述第二关系表,从多个所述接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合所述自定义Mock网速枚举值,获得与所述动态设定网络接口对应的最终Mock文件名以及Mock网络参数。S3. Dynamic correspondence matching: the network output simulation component simulates a network request, intercepts a network request, and acquires information of a network request interface, and according to the first relationship table and the second relationship table, multiple interface names Obtaining a dynamic setting network interface matching the network request interface, and combining the customized Mock network speed enumeration value, obtaining a final Mock file name and a Mock network parameter corresponding to the dynamically setting network interface.
  2. 如权利要求1所述的iOS端Mock数据的方法,其特征在于:步骤S1中,所述网络输出模拟组件初次创建之前,对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象。The method for iOS-side Mock data according to claim 1, wherein in step S1, before the network output simulation component is first created, the current state of the system is determined, and if the current system is in a debug state, the creation step is performed. If the system is in a non-debug state, stop the creation step and return an empty object.
  3. 如权利要求1所述的iOS端Mock数据的方法,其特征在于:所述第二关系表作为对网络异常状态的判断依据。The method for iOS-side Mock data according to claim 1, wherein the second relation table serves as a basis for judging a network abnormal state.
  4. 如权利要求1所述的iOS端Mock数据的方法,其特征在于:步骤S3包括以下步骤:The method for iOS-side Mock data according to claim 1, wherein the step S3 comprises the following steps:
    S301、所述网络输出模拟组件模拟网络请求,拦截网络请求并获取所述网络请求接口的信息;S301. The network output analog component simulates a network request, intercepts a network request, and obtains information about the network request interface.
    S302、判断所述第一关系表是否存在所述网络请求接口相匹配的 所述接口名以及与所述接口名对应的所述Mock文件名,若存在则开启所述网络请求接口的Mock数据工作;S302. Determine whether the first relationship table has the interface name that matches the network request interface and the Mock file name corresponding to the interface name, and if yes, enable the Mock data work of the network request interface. ;
    S303、判断所述第一关系表中的所述Mock文件名是否存在Mock数据地址,并判断所述Mock数据地址对应的所述Mock数据是否存在,若存均存在,则将所述Mock数据转化为OHHTTPStubsResponse格式,将所述网络请求接口定为所述动态设定网络接口,并记录所述网络请求接口对应的所述Mock文件名为所述最终Mock文件名;S303. Determine whether a Mock data address exists in the Mock file name in the first relationship table, and determine whether the Mock data corresponding to the Mock data address exists. If any of the Mock data exists, convert the Mock data. For the OHHTTPStubsResponse format, the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
    S304、取出所述第二关系表中,所述网络请求接口的所述自定义Mock网速枚举值,以所述自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的所述待定Mock网络参数,定为所述Mock网络参数;S304, in the second relationship table, the custom Mock network speed enumeration value of the network request interface, and selecting different pending Mock network parameters according to the custom Mock network speed enumeration value, The requestTime method of the OHHTTPStubs class simulates the normal network speed and uses the responsewithError method to simulate the network abnormality, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
    S305、提取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数。S305. Extract the dynamic setting network interface, the final Mock file name, and the Mock network parameter.
  5. 一种存储介质,其上存储有计算机程序,其特征在于:所述计算机程序被处理器执行时实现上述权利要求1至4中任一项所述方法的步骤。A storage medium having stored thereon a computer program, characterized in that the computer program is executed by a processor to carry out the steps of the method of any one of claims 1 to 4.
  6. 一种iOS端Mock数据的设备,包括存储器、处理器及存储在所述存储器上并在所述处理器上运行的计算机程序,其特征在于:所述处理器执行所述计算机程序时实现上述权利要求1至4中任一项所述方法的步骤。An apparatus for Mock data on an iOS side, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor implements the right when executing the computer program The method of any one of claims 1 to 4.
  7. 一种iOS端Mock数据的***,其特征在于:该***包括组件创建模块、关系表创建模块、动态对应匹配模块;A system for iOS-side Mock data, characterized in that: the system comprises a component creation module, a relationship table creation module, and a dynamic correspondence matching module;
    所述组件创建模块用于:创建网络输出模拟组件,并利用 dispatch_once函数定义网络输出模拟组件,使所述网络输出模拟组件初次创建后,后续的创建均调用第一次创建结果;The component creation module is configured to: create a network output simulation component, and use a dispatch_once function to define a network output simulation component, so that after the network output simulation component is first created, the subsequent creation calls the first creation result;
    所述关系表创建模块用于:加载第一关系表以及第二关系表,所述第一关系表保存接口名和Mock文件名之间的对应关系,所述第二关系表保存所述接口名和自定义Mock网速枚举值之间的对应关系;The relationship table creation module is configured to: load a first relationship table and a second relationship table, where the first relationship table stores a correspondence between an interface name and a Mock file name, where the second relationship table saves the interface name and the self Define the correspondence between the Mock network speed enumeration values;
    所述动态对应匹配模块用于:控制所述网络输出模拟组件模拟网络请求,根据网络请求获取网络请求接口的信息,并依据所述第一关系表以及所述第二关系表,从多个所述接口名中获取与网络请求接口相匹配的动态设定网络接口,并结合所述自定义Mock网速枚举值,获得与所述动态设定网络接口对应的最终Mock文件名以及Mock网络参数。The dynamic correspondence matching module is configured to: control the network output analog component to simulate a network request, acquire information of a network request interface according to the network request, and according to the first relationship table and the second relationship table, from multiple sites Obtaining a dynamic setting network interface matching the network request interface in the interface name, and combining the customized Mock network speed enumeration value to obtain a final Mock file name and a Mock network parameter corresponding to the dynamically setting network interface. .
  8. 如权利要求7所述的iOS端Mock数据的***,其特征在于:所述网络输出模拟组件初次创建之前,所述组件创建模块对***当前状态进行判断,若当前***处于debug状态,则进行创建步骤,若***处于非debug状态,则停止创建步骤,返回空对象。The system for iOS-side Mock data according to claim 7, wherein before the network output simulation component is first created, the component creation module determines a current state of the system, and if the current system is in a debug state, it is created. Step, if the system is in a non-debug state, stop the creation step and return an empty object.
  9. 如权利要求7所述的iOS端Mock数据的***,其特征在于:所述第二关系表作为对网络异常状态的判断依据。The system for iOS-side Mock data according to claim 7, wherein the second relation table is used as a basis for judging a network abnormal state.
  10. 如权利要求7所述的iOS端Mock数据的***,其特征在于,所述动态对应匹配模块获取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数的具体流程为:The iOS-side Mock data system of claim 7, wherein the specific process of the dynamic correspondence matching module acquiring the dynamically setting network interface, the final Mock file name, and the Mock network parameter is:
    控制所述网络输出模拟组件模拟网络请求,根据所述网络请求获取所述网络请求接口的信息;Controlling the network output analog component to simulate a network request, and acquiring information of the network request interface according to the network request;
    判断所述第一关系表是否存在所述网络请求接口相匹配的所述接口名以及与所述接口名对应的所述Mock文件名,若存在则开启所述网络请求接口的Mock数据工作;Determining, by the first relationship table, the interface name that matches the network request interface and the Mock file name corresponding to the interface name, and if yes, enabling Mock data work of the network request interface;
    判断所述第一关系表中的所述Mock文件名是否存在Mock数据地址,并判断所述Mock数据地址对应的所述Mock数据是否存在,若存均存在,则将所述Mock数据转化为OHHTTPStubsResponse格式,将所述网络请求接口定为所述动态设定网络接口,并记录所述网络请求接口对应的所述Mock文件名为所述最终Mock文件名;Determining whether the Mock file name in the first relationship table has a Mock data address, and determining whether the Mock data corresponding to the Mock data address exists, and if the existence exists, converting the Mock data into an OHHTTPStubsResponse a format, the network request interface is defined as the dynamic setting network interface, and the Mock file corresponding to the network request interface is recorded as the final Mock file name;
    取出所述第二关系表中,所述网络请求接口的所述自定义Mock网速枚举值,以所述自定义Mock网速枚举值为依据选择不同的待定Mock网络参数,用OHHTTPStubs类的requestTime方法来模拟正常网速并使用responsewithError方法来模拟网络异常情况,获取传输速度最快且网络正常的所述待定Mock网络参数,定为所述Mock网络参数;Extracting, in the second relationship table, the custom Mock network speed enumeration value of the network request interface, and selecting different pending Mock network parameters according to the custom Mock network speed enumeration value, using the OHHTTPStubs class The requestTime method simulates the normal network speed and uses the responsewithError method to simulate the network anomaly, and obtains the to-be-determined Mock network parameter with the fastest transmission speed and normal network, and is determined as the Mock network parameter;
    提取所述动态设定网络接口、所述最终Mock文件名以及所述Mock网络参数。Extracting the dynamic setting network interface, the final Mock file name, and the Mock network parameter.
PCT/CN2018/081316 2017-10-16 2018-03-30 Method, device and system for mock data at ios end, and storage medium WO2019075994A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710962003.7 2017-10-16
CN201710962003.7A CN107659455B (en) 2017-10-16 2017-10-16 Method, storage medium, device and system for Mock data of iOS (internet operating system) end

Publications (1)

Publication Number Publication Date
WO2019075994A1 true WO2019075994A1 (en) 2019-04-25

Family

ID=61118783

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/081316 WO2019075994A1 (en) 2017-10-16 2018-03-30 Method, device and system for mock data at ios end, and storage medium

Country Status (2)

Country Link
CN (1) CN107659455B (en)
WO (1) WO2019075994A1 (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107659455B (en) * 2017-10-16 2020-01-03 武汉斗鱼网络科技有限公司 Method, storage medium, device and system for Mock data of iOS (internet operating system) end
CN108345543B (en) * 2018-03-02 2021-08-17 财付通支付科技有限公司 Data processing method, device, equipment and storage medium
CN108563426B (en) * 2018-03-06 2021-06-11 北京酷我科技有限公司 iOS request simulation method
CN109783363A (en) * 2018-12-14 2019-05-21 深圳壹账通智能科技有限公司 A kind of anomalous event analogy method and device and computer equipment
CN109635589B (en) * 2018-12-25 2022-06-14 成都卫士通信息产业股份有限公司 SO file calling method and device
CN110389751B (en) * 2019-07-17 2022-02-08 北京海致星图科技有限公司 Data interface mock method applied to knowledge graph
CN110502224B (en) * 2019-08-22 2023-04-28 深圳前海环融联易信息科技服务有限公司 Interface simulation method and device based on HTTP request and computer equipment
CN114978970B (en) * 2022-04-07 2023-11-24 上海钧正网络科技有限公司 Data testing system, method, equipment and medium based on custom mock platform

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105138448A (en) * 2014-06-05 2015-12-09 北京畅游天下网络技术有限公司 Method and device for page test at front end
CN106528400A (en) * 2016-09-22 2017-03-22 深圳峰创智诚科技有限公司 MOCK testing method and device
CN107122292A (en) * 2016-10-21 2017-09-01 北京小度信息科技有限公司 A kind of method and system of analog service
CN107659455A (en) * 2017-10-16 2018-02-02 武汉斗鱼网络科技有限公司 A kind of method, storage medium, equipment and the system of iOS ends Mock data

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7352853B1 (en) * 2001-05-22 2008-04-01 Cisco Technology, Inc. Automation of customer premises equipment provisioning in a telecommunications network
CN102855177B (en) * 2011-06-30 2015-08-26 阿里巴巴集团控股有限公司 A kind of method and apparatus of unit testing
CN102855178B (en) * 2011-06-30 2015-03-04 阿里巴巴集团控股有限公司 Method and device for generating Mock base during unit test
CN103297475B (en) * 2012-03-01 2017-03-01 阿里巴巴集团控股有限公司 Mock service system and the processing method of Mock service
US20140149966A1 (en) * 2012-11-27 2014-05-29 Inadev Corporation Application, build, integration, and release management system and method
CN105335281B (en) * 2014-07-30 2018-03-20 阿里巴巴集团控股有限公司 A kind of method and device relied on outside automatic mock
CN104375933A (en) * 2014-09-18 2015-02-25 广州华多网络科技有限公司 Unit testing method and device
CN105068791B (en) * 2015-07-15 2018-10-23 贵阳朗玛信息技术股份有限公司 A kind of method and device for realizing bottom library
CN106201878B (en) * 2016-07-08 2018-11-30 百度在线网络技术(北京)有限公司 The execution method and apparatus of test program
CN106776313B (en) * 2016-12-13 2020-06-23 广州品唯软件有限公司 Method and device for simulating service and centralized management platform

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105138448A (en) * 2014-06-05 2015-12-09 北京畅游天下网络技术有限公司 Method and device for page test at front end
CN106528400A (en) * 2016-09-22 2017-03-22 深圳峰创智诚科技有限公司 MOCK testing method and device
CN107122292A (en) * 2016-10-21 2017-09-01 北京小度信息科技有限公司 A kind of method and system of analog service
CN107659455A (en) * 2017-10-16 2018-02-02 武汉斗鱼网络科技有限公司 A kind of method, storage medium, equipment and the system of iOS ends Mock data

Also Published As

Publication number Publication date
CN107659455B (en) 2020-01-03
CN107659455A (en) 2018-02-02

Similar Documents

Publication Publication Date Title
WO2019075994A1 (en) Method, device and system for mock data at ios end, and storage medium
CN110334021B (en) Interface test case generation method, device, equipment and storage medium
CN110287696B (en) Detection method, device and equipment for rebound shell process
CN106648556B (en) Method and device for front-end and back-end integrated development test
CN111597110B (en) Page test method and device, electronic equipment and storage medium
US20160283357A1 (en) Call stack relationship acquiring method and apparatus
TW201610735A (en) Point-wise protection of application using runtime agent and dynamic security analysis
WO2016201995A1 (en) Method and apparatus for implementation of test object construction, and service configuration test apparatus
CN108459850B (en) Method, device and system for generating test script
CN111522728A (en) Method for generating automatic test case, electronic device and readable storage medium
CN109683997B (en) Method for accessing application program interface through sandbox, sandbox and sandbox equipment
CN115080398A (en) Automatic interface test system and method
CN112035344A (en) Multi-scenario test method, device, equipment and computer readable storage medium
US11663113B2 (en) Real time fault localization using combinatorial test design techniques and test case priority selection
CN103605610A (en) System and method for software testing based on Hadoop
CN107704568A (en) Method and device for adding test data
JP2018156294A (en) Software verification apparatus and software verification program
CN112650689A (en) Test method, test device, electronic equipment and storage medium
CN112559335A (en) Test method, device, equipment and storage medium
CN108563578B (en) SDK compatibility detection method, device, equipment and readable storage medium
CN112445692A (en) Case testing method and terminal
CN114328180A (en) Interface automation test method, system, electronic equipment and storage medium
CN113127369A (en) Processing method and device for execution script
CN111078527A (en) Auxiliary system and method for pressure testing of server
CN111125149B (en) Hive-based data acquisition method, hive-based data acquisition device and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18867693

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18867693

Country of ref document: EP

Kind code of ref document: A1