Nothing Special   »   [go: up one dir, main page]

CN113010411B - Method and system for returning data based on mock service and simulation test method - Google Patents

Method and system for returning data based on mock service and simulation test method Download PDF

Info

Publication number
CN113010411B
CN113010411B CN202011468799.9A CN202011468799A CN113010411B CN 113010411 B CN113010411 B CN 113010411B CN 202011468799 A CN202011468799 A CN 202011468799A CN 113010411 B CN113010411 B CN 113010411B
Authority
CN
China
Prior art keywords
data
template
service
type
simulation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011468799.9A
Other languages
Chinese (zh)
Other versions
CN113010411A (en
Inventor
孙伟颖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Cloudwise Beijing Technology Co Ltd
Original Assignee
Cloudwise Beijing Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Cloudwise Beijing Technology Co Ltd filed Critical Cloudwise Beijing Technology Co Ltd
Priority to CN202011468799.9A priority Critical patent/CN113010411B/en
Publication of CN113010411A publication Critical patent/CN113010411A/en
Application granted granted Critical
Publication of CN113010411B publication Critical patent/CN113010411B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3698Environments for analysis, debugging or testing of software

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a method, a system and a simulation test method for returning data based on mock service. After receiving the request, the analog data generation interface MockServer obtains parameters type, taskId and monitorId in url, obtains a specified type template through type, obtains corresponding monitoring point excel file content through monitorId, obtains next line data in the template each time according to the number of requests, and if the last line is reached, the data is always circulated from the first line, and is written into the type template to be returned as interface response data. Therefore, by returning data, the acquisition of related data can be carried out without a real data source by modifying the url of the request and the corresponding analog data template file, so that the tested system not only stabilizes the test scene but also stabilizes the test data, the tested system can test only concerned logic, the environment dependence is reduced, the dependence of a tester on the data source is solved, the test quality is greatly ensured, and the test efficiency is improved.

Description

基于mock服务返回数据的方法、系统和模拟测试方法Method, system and simulation test method based on mock service return data

技术领域Technical Field

本发明属于软件测试领域,具体涉及一种基于mock服务按预定规则返回数据的方法和系统以及据此进行模拟测试的方法,主要用于软件性能测试。The invention belongs to the field of software testing, and specifically relates to a method and system for returning data according to a predetermined rule based on a mock service and a method for performing simulation testing based on the method, which is mainly used for software performance testing.

背景技术Background technique

在软件测试过程中,一方面,由于现有测试方法对于监测点所采集的真实数据的准确性依赖性较强,因此,需要测试人员对于监测点采集的真实数据进行准确性的校验,但是依照现有技术,测试人员对于监测点采集的真实数据,往往无法进行数据准确性的校验,这就导致现有的测试方法存在准确性不足的问题;另一方面,由于产品迭代速度快,而在产品快速迭代过程中,按照现有技术,测试人员需要全面覆盖所有预设好的测试场景,但是这往往也很难实现。During the software testing process, on the one hand, since the existing testing methods are highly dependent on the accuracy of the real data collected by the monitoring points, testers are required to verify the accuracy of the real data collected by the monitoring points. However, according to the existing technology, testers are often unable to verify the accuracy of the real data collected by the monitoring points, which leads to the problem of insufficient accuracy in the existing testing methods. On the other hand, due to the fast iteration speed of products, during the rapid iteration of products, according to the existing technology, testers need to fully cover all preset test scenarios, but this is often difficult to achieve.

综上所述,在软件测试过程中,亟需一种可以减少测试人员对数据源的依赖程度,进而提高测试效率的技术。In summary, in the software testing process, there is an urgent need for a technology that can reduce the tester's dependence on the data source and thus improve the testing efficiency.

发明内容Summary of the invention

为了解决现有技术的上述问题,一方面,本发明提供一种基于mock 服务按预定规则返回数据的方法,其在不能或难以获得真实数据的情况下,可以获得与之相对应的模拟数据。In order to solve the above problems in the prior art, on the one hand, the present invention provides a method for returning data according to a predetermined rule based on a mock service, which can obtain corresponding simulated data when it is impossible or difficult to obtain real data.

为了达到上述目的,本发明采用的主要技术方案包括:In order to achieve the above object, the main technical solutions adopted by the present invention include:

一种基于mock服务按预定规则返回数据的方法,其包括如下步骤:A method for returning data according to a predetermined rule based on a mock service, comprising the following steps:

S3、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。After receiving the request, the simulation data generation interface provided by S3 and MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data and return it.

借助上述方案,本发明的基于mock服务按预定规则返回数据的方法,其在不能或难以获得真实源数据的情况下,可以获得与之相对应的模拟数据,供使用。例如在测试中,有可能难以获得稳定的真实源数据,此时,则可以在不用真实数据源的前提下,只修改请求的url和对应的模拟数据模板文件即可进行相关数据的采集,被测系统中可以只关注本身的逻辑进行测试,减少环境依赖,尤其是可以减少测试人员对数据源的依赖,进而可以提高测试效率。With the help of the above scheme, the method of the present invention based on mock service returning data according to predetermined rules can obtain corresponding simulated data for use when it is impossible or difficult to obtain real source data. For example, in testing, it may be difficult to obtain stable real source data. At this time, the relevant data can be collected by modifying the requested URL and the corresponding simulated data template file without using the real data source. The system under test can only focus on its own logic for testing, reduce environmental dependence, especially reduce the tester's dependence on the data source, and thus improve the test efficiency.

本发明一个实施例的基于mock服务按预定规则返回数据的方法,其步骤S3之前还包括步骤:The method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes the following steps before step S3:

S1、在监测点后台配置模拟监测点,即MockServer提供的模拟数据生成接口,用于被测服务调用;S1. Configure a simulated monitoring point in the monitoring point background, that is, the simulated data generation interface provided by MockServer for calling the tested service;

S2、设置任务的监测点及任务调度频率,用于后端调度服务按频率访问MockServer提供的模拟数据生成接口。S2. Set the task monitoring point and task scheduling frequency, so that the backend scheduling service can access the simulation data generation interface provided by MockServer according to the frequency.

本发明一个实施例的基于mock服务按预定规则返回数据的方法,其步骤S3之后还包括步骤:The method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes the following steps after step S3:

S4、调度服务收到模拟监测点返回的数据后,存入数据库,并将处理后的数据提供给前端使用。S4. After receiving the data returned by the simulation monitoring point, the dispatch service stores it in the database and provides the processed data to the front end for use.

本发明一个实施例的基于mock服务按预定规则返回数据的方法,其步骤S1之前还包括步骤:S0、预先设计好测试场景。The method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes the following steps before step S1: S0, pre-designing a test scenario.

本发明一个实施例的基于mock服务按预定规则返回数据的方法,其步骤S4之后还包括步骤:S5、根据模拟数据进行数据准确性测试。The method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further comprises, after step S4, the following step: S5, performing a data accuracy test based on the simulated data.

另一方面,本发明还提供一种基于mock服务按预定规则返回数据的系统,其在不能或难以获得真实数据的情况下,可以获得与之相对应的模拟数据。On the other hand, the present invention also provides a system for returning data according to predetermined rules based on a mock service, which can obtain corresponding simulated data when it is impossible or difficult to obtain real data.

为了达到上述目的,本发明采用的主要技术方案包括:In order to achieve the above object, the main technical solutions adopted by the present invention include:

一种基于mock服务按预定规则返回数据的系统,其包括:A system for returning data according to predetermined rules based on a mock service, comprising:

模拟数据接口生成模块,用于生成模拟数据接口;A simulation data interface generation module, used for generating a simulation data interface;

返回数据生成模块,用于生成返回数据。The return data generation module is used to generate return data.

借助上述方案,本发明的基于mock服务按预定规则返回数据的系统,其在不能或难以获得真实源数据的情况下,可以获得与之相对应的模拟数据,供使用。例如在测试中,有可能难以获得稳定的真实源数据,此时,则可以在不用真实数据源的前提下,只修改请求的url和对应的模拟数据模板文件即可进行相关数据的采集,被测系统中可以只关注本身的逻辑进行测试,减少环境依赖,尤其是可以减少测试人员对数据源的依赖,进而可以提高测试效率。With the above scheme, the system of the present invention, which returns data according to predetermined rules based on mock services, can obtain corresponding simulated data for use when it is impossible or difficult to obtain real source data. For example, in testing, it may be difficult to obtain stable real source data. In this case, the relevant data can be collected by modifying the requested URL and the corresponding simulated data template file without using the real data source. The system under test can only focus on its own logic for testing, reduce environmental dependence, and especially reduce the tester's dependence on the data source, thereby improving the test efficiency.

本发明一个实施例的基于mock服务按预定规则返回数据的系统,其返回数据生成模块包括:参数获取子模块,用于获取url中的参数 type,taskId,monitorId。In one embodiment of the present invention, a system for returning data according to predetermined rules based on a mock service includes a return data generation module comprising: a parameter acquisition submodule for acquiring parameters type, taskId, and monitorId in the url.

本发明一个实施例的基于mock服务按预定规则返回数据的系统,其返回数据生成模块包括:文件解析子模块,用于解析接口xls描述文件。In an embodiment of the present invention, a system for returning data according to a predetermined rule based on a mock service comprises a return data generation module including: a file parsing submodule for parsing an interface xls description file.

本发明一个实施例的基于mock服务按预定规则返回数据的系统,其还包括:模拟数据接口调度模块,用于调用模拟数据接口。A system for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes: a simulation data interface scheduling module for calling a simulation data interface.

本发明一个实施例的基于mock服务按预定规则返回数据的系统,其还包括:模拟监测点配置模块,用于配置模拟监测点。A system for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes: a simulation monitoring point configuration module for configuring simulation monitoring points.

本发明一个实施例的基于mock服务按预定规则返回数据的系统,其还包括:任务设置模块,用于设置任务的监测点和任务调度频率。A system for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention further includes: a task setting module for setting a monitoring point of a task and a task scheduling frequency.

另一方面,本发明还提供一种基于mock服务进行模拟测试的方法,其可以只关注被测系统本身的逻辑,减少环境依赖,尤其是可以减少测试人员对数据源的依赖,进而可以提高测试效率。On the other hand, the present invention also provides a method for performing simulation testing based on mock services, which can focus only on the logic of the tested system itself, reduce environmental dependence, and especially reduce the tester's dependence on the data source, thereby improving testing efficiency.

为了达到上述目的,本发明采用的主要技术方案包括:In order to achieve the above object, the main technical solutions adopted by the present invention include:

一种基于mock服务进行模拟测试的方法,其在服务器上启动一个 http端口,用来接收被测服务的数据,根据被测服务上传的参数动态获取本地中存储的相关文件,根据预定规则将文件内容转换生成对应接口的返回数据,返回给被测服务,再依据返回数据进行测试。A method for simulation testing based on mock service, which starts an http port on the server to receive data from the service under test, dynamically obtains relevant files stored locally according to the parameters uploaded by the service under test, converts the file content into return data of the corresponding interface according to predetermined rules, returns it to the service under test, and then performs testing based on the return data.

借助上述方案,本发明的基于mock服务进行模拟测试的方法,其可以在不用真实数据源的前提下,只修改请求的url和对应的模拟数据模板文件即可进行相关数据的采集,被测系统中可以只关注本身的逻辑进行测试,减少环境依赖,尤其是可以减少测试人员对数据源的依赖,进而可以提高测试效率。With the help of the above scheme, the method of performing simulation testing based on mock service of the present invention can collect relevant data by only modifying the requested URL and the corresponding simulation data template file without using the real data source. The system under test can only focus on its own logic for testing, reducing environmental dependence, especially reducing the tester's dependence on the data source, thereby improving testing efficiency.

本发明一个实施例的基于mock服务进行模拟测试的方法,其中,获取url中的参数type,taskId,monitorId,通过type获取到指定类型的模板,通过monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。A method for performing simulation testing based on a mock service in one embodiment of the present invention, wherein the parameters type, taskId, and monitorId in the url are obtained, a template of the specified type is obtained through type, the corresponding monitoring point excel file content is obtained through monitorId, and the next row of data in the template is obtained each time according to the number of requests. If it reaches the last row, it loops from the first row and writes the data into the type template as interface response data and returns it.

本发明一个实施例的基于mock服务进行模拟测试的方法,其包括如下步骤:A method for performing simulation testing based on a mock service according to an embodiment of the present invention comprises the following steps:

S3、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。After receiving the request, the simulation data generation interface provided by S3 and MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data and return it.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1为本发明一个实施例的基于mock服务按预定规则返回数据的方法的主要流程示意图;FIG1 is a schematic diagram of the main flow of a method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention;

图2为本发明又一个实施例的基于mock服务按预定规则返回数据的方法的主要流程示意图;FIG2 is a schematic diagram of the main flow of a method for returning data according to a predetermined rule based on a mock service according to another embodiment of the present invention;

图3为本发明又一个实施例的基于mock服务按预定规则返回数据的方法的主要流程示意图;FIG3 is a schematic diagram of the main flow of a method for returning data according to a predetermined rule based on a mock service according to another embodiment of the present invention;

图4为本发明又一个实施例的基于mock服务按预定规则返回数据的方法的主要流程示意图;FIG4 is a schematic diagram of the main flow of a method for returning data according to a predetermined rule based on a mock service according to another embodiment of the present invention;

图5为本发明一个实施例的基于mock服务按预定规则返回数据的系统的结构示意图;5 is a schematic diagram of the structure of a system for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention;

图6为本发明一个应用例中的类型模板文件示意图;FIG6 is a schematic diagram of a type template file in an application example of the present invention;

图7为本发明一个应用例中的excel文件内容示意图(图6中的第一个类型模板文件,文件名称为“51.xlsx”);FIG7 is a schematic diagram of the contents of an Excel file in an application example of the present invention (the first type template file in FIG6 , the file name is “51.xlsx”);

图8为本发明一个应用例中的报文模板内容示意图(图6中的第六个类型模板文件,文件名称为“http.txt”);8 is a schematic diagram of the content of a message template in an application example of the present invention (the sixth type of template file in FIG. 6 , the file name is “http.txt”);

图9为图8应用例中的excel参数文件内容示意图。FIG. 9 is a schematic diagram of the contents of the Excel parameter file in the application example of FIG. 8 .

具体实施方式Detailed ways

为了更好的解释本发明,以便于理解,下面结合附图,通过具体实施方式,对本发明作详细描述。In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation modes in conjunction with the accompanying drawings.

参见图1,本发明一个实施例的基于mock服务按预定规则返回数据的方法,其包括如下步骤:Referring to FIG. 1 , a method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention comprises the following steps:

S3、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。After receiving the request, the simulation data generation interface provided by S3 and MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data and return it.

借助上述方案,本发明的基于mock服务按预定规则返回数据的方法,其可以在不能或难以获得真实源数据的情况下,可以只修改请求的url和对应的模拟数据模板文件即可进行相关数据的采集,获得与之相对应的模拟数据,达到了可以不用真实数据源的前提下,提供稳定的测试数据供使用。With the help of the above scheme, the method of returning data according to predetermined rules based on mock services of the present invention can collect relevant data by only modifying the requested URL and the corresponding simulation data template file when it is impossible or difficult to obtain real source data, and obtain the corresponding simulation data, thereby achieving the goal of providing stable test data for use without using the real data source.

参见图2,本发明一个较佳实施例的基于mock服务按预定规则返回数据的方法,其包括如下步骤:Referring to FIG. 2 , a method for returning data according to a predetermined rule based on a mock service according to a preferred embodiment of the present invention comprises the following steps:

S1、在监测点后台配置模拟监测点,即MockServer提供的模拟数据生成接口,用于被测服务调用;S1. Configure a simulated monitoring point in the monitoring point background, that is, the simulated data generation interface provided by MockServer for calling the tested service;

S2、设置任务的监测点及任务调度频率,用于后端调度服务按频率访问MockServer提供的模拟数据生成接口;S2. Set the task monitoring point and task scheduling frequency, so that the backend scheduling service can access the simulation data generation interface provided by MockServer according to the frequency;

S3、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。After receiving the request, the simulation data generation interface provided by S3 and MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data and return it.

参见图3,本发明一个实施例的基于mock服务按预定规则返回数据的方法,其包括如下步骤:Referring to FIG3 , a method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention includes the following steps:

S0、预先设计好测试场景;S0. Design the test scenario in advance;

S1、在监测点后台配置模拟监测点,即MockServer提供的模拟数据生成接口,用于被测服务调用;S1. Configure a simulated monitoring point in the monitoring point background, that is, the simulated data generation interface provided by MockServer for calling the tested service;

S2、设置任务的监测点及任务调度频率,用于后端调度服务按频率访问MockServer提供的模拟数据生成接口;S2. Set the task monitoring point and task scheduling frequency, so that the backend scheduling service can access the simulation data generation interface provided by MockServer according to the frequency;

S3、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回;After receiving the request, the simulation data generation interface provided by S3 and MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data to be returned;

S4、调度服务收到模拟监测点返回的数据后,存入数据库,并将处理后的数据提供给前端使用。S4. After receiving the data returned by the simulation monitoring point, the dispatch service stores it in the database and provides the processed data to the front end for use.

借此,测试人员可以根据模拟数据进行数据准确性测试,同时可以保证每次迭代测试过程中预先设计好的测试场景都被覆盖,很大程度的提高了测试效率。In this way, testers can conduct data accuracy tests based on simulated data, and at the same time ensure that pre-designed test scenarios are covered during each iterative test process, greatly improving test efficiency.

参见图4,本发明一个实施例的基于mock服务按预定规则返回数据的方法,其包括如下步骤:Referring to FIG. 4 , a method for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention includes the following steps:

在前端页面监测点后台配置模拟监测点,即MockServer提供的模拟数据生成接口;Configure the simulation monitoring point in the background of the front-end page monitoring point, that is, the simulation data generation interface provided by MockServer;

任务选择模拟监测点;Task selection simulation monitoring points;

调度服务按任务指定频率调度,调用MockServer提供的模拟数据生成接口;The scheduling service schedules tasks according to the specified frequency and calls the simulation data generation interface provided by MockServer;

MockServer应用根据任务调度提供模拟数据生成接口,解析模拟数据生成接口xls描述文件(即excel文件),生成mock数据(即模拟数据)并返回;The MockServer application provides a simulation data generation interface according to task scheduling, parses the simulation data generation interface xls description file (i.e., Excel file), generates mock data (i.e., simulation data) and returns it;

调度服务按任务指定频率调度,获取模拟监测点返回的mock数据。The scheduling service schedules tasks according to the specified frequency and obtains the mock data returned by the simulation monitoring point.

上述任一实施例中,指定的类型模板可以是图6所示的类型模板。In any of the above embodiments, the specified type template may be the type template shown in FIG. 6 .

上述任一个实施例中,监测点excel文件可以是图7所示的excel文件。In any of the above embodiments, the monitoring point Excel file may be the Excel file shown in FIG. 7 .

如图5所示,本发明还提供一个实施例的基于mock服务按预定规则返回数据的系统,其包括:As shown in FIG5 , the present invention also provides a system for returning data according to a predetermined rule based on a mock service according to an embodiment of the present invention, which includes:

模拟数据接口生成模块,用于生成模拟数据接口;A simulation data interface generation module, used for generating a simulation data interface;

返回数据生成模块,用于生成返回数据。The return data generation module is used to generate return data.

其中,较佳的,其返回数据生成模块包括:参数获取子模块,用于获取url中的参数type,taskId,monitorId。Preferably, the return data generation module includes: a parameter acquisition submodule, which is used to obtain the parameters type, taskId, and monitorId in the url.

其中,较佳的,其返回数据生成模块包括:文件解析子模块,用于解析接口xls描述文件。Preferably, the return data generation module includes: a file parsing submodule for parsing the interface xls description file.

较佳的,其还包括:模拟数据接口调度模块,用于调用模拟数据接口。Preferably, it also includes: a simulation data interface scheduling module, which is used to call the simulation data interface.

较佳的,其还包括:模拟监测点配置模块,用于配置模拟监测点。Preferably, it also includes: a simulation monitoring point configuration module, used for configuring the simulation monitoring points.

较佳的,其还包括:任务设置模块,用于设置任务的监测点和任务调度频率。Preferably, it also includes: a task setting module, used to set the monitoring points and task scheduling frequency of the task.

参见图8和图9,本发明一个模拟http数据的应用例,具体实施方式如下:8 and 9, an application example of simulating http data of the present invention, the specific implementation method is as follows:

1、预先设计好测试场景:1. Design the test scenario in advance:

1).新建一个http类型任务,任务id为708620;1). Create a new http type task with task id 708620;

2).设计http类型请求报文模板,如下:2). Design the http type request message template as follows:

{“task_id”:”708620”,”host”:”www.taobao.com”,”databa se”:null,”table”:null,”database_code”:null,”table_info”:null,”p ackets”:”0”,”task_type”:”http”,”retry”:”1”,”time_out”:n ull,”uid”:”284415”,”ts”:”1550719304”,”ed”:”enterprise”, ”need_file”:true,”used_monitor_id”:51};{“task_id”:”708620”,”host”:”www.taobao.com”,”database”:null,”table”:null,”database_code”:null,”table_info”:null,”packets”:”0”,”task_type”:”http”,”retry”:”1”,”time_out”:null,”uid”:”284415”,”ts”:”1550719304”,”ed”:”enterprise”, “need_file”:true,”used_monitor_id”:51};

3).设计http类型返回值模板,http.txt。3). Design the http type return value template, http.txt.

2、在监测点后台配置模拟监测点,即MockServer提供的模拟数据生成接口,用于被测服务调用:2. Configure the simulation monitoring point in the monitoring point background, that is, the simulation data generation interface provided by MockServer for the tested service call:

在监测点后台将51监测点地址设置为:In the monitoring point background, set the 51 monitoring point address to:

http://localhost:9999/monitor/http/708620/51。http://localhost:9999/monitor/http/708620/51.

3、设置任务的监测点及任务调度频率,用于后端调度服务按频率访问:3. Set the task monitoring point and task scheduling frequency for the backend scheduling service to access by frequency:

1).在前端将任务:708620的监测点设置为51;1). Set the monitoring point of task: 708620 to 51 on the front end;

2).将任务调度频率设置为2分钟。2). Set the task scheduling frequency to 2 minutes.

4、MockServer提供的模拟数据生成接口接到请求后,获取url中的参数type,taskId,monitorId,通过type获取到指定的类型模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回:4. After receiving the request, the simulation data generation interface provided by MockServer obtains the parameters type, taskId, and monitorId in the url, obtains the specified type template through type, obtains the corresponding monitoring point excel file content through monitorId, and obtains the next row of data in the template each time according to the number of requests. If it reaches the last row, it will loop from the first row and write the data into the type template as the interface response data and return it:

1).后端调度服务请求:1). Backend scheduling service request:

http://10.0.1.24:9000/monitor/http/708620/51;http://10.0.1.24:9000/monitor/http/708620/51;

2).根据task_type=http找到报文模板,模板内容参见图8;2). Find the message template according to task_type = http. For the template content, see Figure 8;

3).根据task_id=708620找到参数文件51.xlsx,文件内容参见图9;3). According to task_id=708620, find parameter file 51.xlsx. See Figure 9 for the file content;

4).循环读取工作表中的每行数据,将http类型模板中的resp_result,resp_status,resp_time替换成excel中的数据,并作为接口响应返回;4). Loop through each row of data in the worksheet, replace resp_result, resp_status, and resp_time in the http type template with the data in excel, and return it as an interface response;

5).返回http模板替换后的内容,将模板中的resp_result, resp_status,resp_time替换成参数文件中的数据返回,返回的数据内容如下:5). Return the content after the http template is replaced. Replace resp_result, resp_status, and resp_time in the template with the data in the parameter file. The returned data content is as follows:

①.第一次请求返回:{"resp_result":"1","resp_status":"200 OK","resp_time":221.569,"resp_err":"0","extend":{"url":"http:\/\/120.26.48.181\/product\/","content_type":"text\/html;①. The first request returns: {"resp_result":"1","resp_status":"200 OK","resp_time":221.569,"resp_err":"0","extend":{"url":"http:\/\/120.26.48.181\/product\/","content_type":"text\/html;

charset=utf-8","http_code":200,"header_size":330,"request_size":323,"fil etime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":221.569,"namelookup_time":0.012,"connect_time":37.245,"pretransfer_time":37.28 6,"size_upload":0,"size_download":8387,"speed_download":37844,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":186.574,"redirect_time":0,"certinfo":[],"primary_ip":"120.26.48.181","primary_port":80,"local_ip":"192.168.1.7","local_port":49177,"redirect_url":"","http_code_desc":"OK","req_headers":[],"req_method":"GET","req_httpv":"1.1","ip":"120.26.48.181","resp_httpv":"1.1","resp_headers":{"Date":"Tue,03Jul 2018 17:37:40GMT","Server":"Apache\/2.2.21(Win32) PHP\/5.3.10","X-Powered-By":"ThinkPHP","Expires":"Thu,19Nov 198108:52:00charset=utf-8","http_code":200,"header_size":330,"request_size":323,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":221.569,"namelookup_time":0.012,"connect_time":37.245,"pretransfer_time":37.28 6,"size_upload":0,"size_download":8387,"speed_download":37844,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":186.574,"redirect_time":0,"certinfo":[],"primary_ip":"120.26.48.181","primary_port":80,"local_ip":"192.168.1.7","local_port":49177,"redirect_url":"","http_code_desc":"OK","req_headers":[],"req_method":"GET","req_httpv":"1.1","ip":"120.26.48.181","resp_httpv":"1.1","resp_headers":{"Date":"Tue,03Jul 2018 17:37:40GMT","Server":"Apache\/2.2.21(Win32) PHP\/5.3.10","X-Powered-By":"ThinkPHP","Expires":"Thu,19Nov 198108:52:00

GMT","Cache-Control":"private","Pragma":"no-cache","Transfer-Encoding":"chunked","Content-Type":"text\/html;GMT","Cache-Control":"private","Pragma":"no-cache","Transfer-Encoding":"chunked","Content-Type":"text\/html;

charset=utf-8","Set-Cookie":"PHPSESSID=6d8ls1ej362onm0d0ls9m827l 0;path=\/"}}}charset=utf-8","Set-Cookie":"PHPSESSID=6d8ls1ej362onm0d0ls9m827l 0;path=\/"}}}

②第二次请求返回:{"resp_result":"1","resp_status":"200 OK","resp_time":224.449,"resp_err":"0","extend":{"url":"http:\/\/120.26.48.181\/product\/","content_type":"text\/html;②The second request returns: {"resp_result":"1","resp_status":"200 OK","resp_time":224.449,"resp_err":"0","extend":{"url":"http:\/\/120.26.48.181\/product\/","content_type":"text\/html;

charset=utf-8","http_code":200,"header_size":330,"request_size":323,"fil etime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":221.569,"namelookup_time":0.012,"connect_time":37.245,"pretransfer_time":37.28 6,"size_upload":0,"size_download":8387,"speed_download":37844,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":186.574,"redirect_time":0,"certinfo":[],"primary_ip":"120.26.48.181","primary_port":80,"local_ip":"192.168.1.7","local_port":49177,"redirect_url":"","http_code_desc":"OK","req_headers":[],"req_method":"GET","req_httpv":"1.1","ip":"120.26.48.181","resp_httpv":"1.1","resp_headers":{"Date":"Tue,03Jul 2018 17:37:40GMT","Server":"Apache\/2.2.21(Win32) PHP\/5.3.10","X-Powered-By":"ThinkPHP","Expires":"Thu,19Nov 1981 08:52:00charset=utf-8","http_code":200,"header_size":330,"request_size":323,"filetime":-1,"ssl_verify_result":0,"redirect_count":0,"total_time":221.569,"namelookup_time":0.012,"connect_time":37.245,"pretransfer_time":37.28 6,"size_upload":0,"size_download":8387,"speed_download":37844,"speed_upload":0,"download_content_length":-1,"upload_content_length":-1,"starttransfer_time":186.574,"redirect_time":0,"certinfo":[],"primary_ip":"120.26.48.181","primary_port":80,"local_ip":"192.168.1.7","local_port":49177,"redirect_url":"","http_code_desc":"OK","req_headers":[],"req_method":"GET","req_httpv":"1.1","ip":"120.26.48.181","resp_httpv":"1.1","resp_headers":{"Date":"Tue,03Jul 2018 17:37:40GMT","Server":"Apache\/2.2.21(Win32) PHP\/5.3.10","X-Powered-By":"ThinkPHP","Expires":"Thu,19Nov 1981 08:52:00

GMT","Cache-Control":"private","Pragma":"no-cache","Transfer-Encoding":"chunked","Content-Type":"text\/html;GMT","Cache-Control":"private","Pragma":"no-cache","Transfer-Encoding":"chunked","Content-Type":"text\/html;

charset=utf-8","Set-Cookie":"PHPSESSID=6d8ls1ej362onm0d0ls9m827l 0;path=\/"}}}。charset=utf-8","Set-Cookie":"PHPSESSID=6d8ls1ej362onm0d0ls9m827l 0;path=\/"}}}.

5、调度服务收到模拟监测点返回的数据后,存入数据库,并将处理后的数据提供给前端使用:5. After receiving the data returned by the simulated monitoring point, the dispatch service stores it in the database and provides the processed data to the front end for use:

1).前端查看任务id为708620的数据;1). The front end checks the data of task ID 708620;

2).第一次调度的数据展示为:任务状态【正常】,响应时间【221.569ms】,任务状态码【200】;2). The data displayed for the first scheduling is: task status [Normal], response time [221.569ms], task status code [200];

3).第二次调度的数据展示为:任务状态【正常】,响应时间3). The data of the second scheduling is displayed as: Task status [Normal], Response time

【224.449ms】,任务状态码【200】。【224.449ms】, task status code 【200】.

本发明在模拟ping数据/ftp数据的应用中,与上述模拟http数据流程相同,此处不再赘述。The present invention is similar to the above-mentioned simulation of http data flow in the application of simulating ping data/ftp data, and will not be described in detail here.

综上所述,本发明的基于mock服务按预定规则返回数据的方法和系统,可以通过在服务器上启动一个http端口,用来接收被测服务的数据,根据被测服务上传的参数动态获取本地中存储的相关文件,根据预定规则将文件内容转换生成对应接口的返回数据,返回给被测服务,使得不需要真实的监测点也能进行测试。其中,可以通过获取url中的参数type,taskId,monitorId,通过type获取到指定的类型的模板,通过 monitorId获取对应的监测点excel文件内容,根据请求次数每次获取模板中的下一行数据,如果到最后一行则从第一行开始一直循环,将数据写入到类型模板中作为接口响应数据返回。借此,通过实际的测试验证,本发明可以不用真实数据源的前提,只修改请求的url和对应的模拟数据模板文件即可进行相关数据的采集,使得被测系统既稳固了测试场景又稳固了测试数据,使得被测系统中可以只关注本身的逻辑进行测试,减少了环境依赖,解决了测试人员对数据源的依赖,大大的保障了测试的质量,提高了测试效率。In summary, the method and system for returning data according to predetermined rules based on mock services of the present invention can be started on a server to receive data of the tested service, dynamically obtain relevant files stored locally according to the parameters uploaded by the tested service, convert the file content to generate the return data of the corresponding interface according to the predetermined rules, and return it to the tested service, so that the test can be performed without the need for a real monitoring point. Among them, the parameters type, taskId, and monitorId in the url can be obtained, the template of the specified type can be obtained through type, the corresponding monitoring point excel file content can be obtained through monitorId, and the next row of data in the template can be obtained each time according to the number of requests. If it reaches the last row, it will be circulated from the first row, and the data will be written into the type template as the interface response data and returned. By this, through actual test verification, the present invention can collect relevant data without the premise of a real data source, only modify the requested url and the corresponding simulation data template file, so that the tested system can stabilize the test scene and stabilize the test data, so that the tested system can only focus on its own logic for testing, reduce environmental dependence, solve the dependence of testers on data sources, greatly guarantee the quality of the test, and improve the test efficiency.

Claims (5)

1. A method for returning data according to a predetermined rule based on a mock service, comprising the steps of:
S3, after the analog data generation interface provided by MockServer receives the request, parameters type, task Id and monitorId in url are acquired, a specified type template is acquired through the type, corresponding monitoring point excel file content is acquired through monitorId, next line data in the template is acquired each time according to the number of requests, and if the last line is reached, the process is always circulated from the first line, and the data is written into the type template to be returned as interface response data.
2. The method for returning data according to a predetermined rule based on the mock service of claim 1, wherein step S3 is preceded by the further step of:
s1, configuring a simulation monitoring point, namely MockServer a simulation data generation interface provided by a monitoring point background for the call of a tested service;
s2, setting monitoring points of tasks and task scheduling frequency, and enabling the back-end scheduling service to access the simulation data generation interface provided by MockServer according to the frequency.
3. The method for returning data according to a predetermined rule based on the mock service of claim 1, further comprising the step of, after step S3:
And S4, after receiving the data returned by the simulated monitoring points, the scheduling service stores the data into a database and provides the processed data for the front end for use.
4. The method for returning data according to a predetermined rule based on mock service of claim 3 wherein:
the step S1 is preceded by the steps of: s0, pre-designing a test scene;
And/or
The step S4 further comprises the following steps: s5, testing the data accuracy according to the simulation data.
5. A method of performing analogue testing based on mock services, which tests on analogue data returned by the method of any one of claims 1 to 4.
CN202011468799.9A 2020-12-15 2020-12-15 Method and system for returning data based on mock service and simulation test method Active CN113010411B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011468799.9A CN113010411B (en) 2020-12-15 2020-12-15 Method and system for returning data based on mock service and simulation test method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011468799.9A CN113010411B (en) 2020-12-15 2020-12-15 Method and system for returning data based on mock service and simulation test method

Publications (2)

Publication Number Publication Date
CN113010411A CN113010411A (en) 2021-06-22
CN113010411B true CN113010411B (en) 2024-07-05

Family

ID=76383257

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011468799.9A Active CN113010411B (en) 2020-12-15 2020-12-15 Method and system for returning data based on mock service and simulation test method

Country Status (1)

Country Link
CN (1) CN113010411B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113342353B (en) * 2021-07-01 2023-05-23 银联商务股份有限公司 Mock data generation method and device
CN114416602B (en) * 2022-03-30 2022-07-05 互联网域名系统北京市工程研究中心有限公司 Method and device for realizing Restful interface simulation test service based on Netty

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109491905A (en) * 2018-11-02 2019-03-19 北京金山云网络技术有限公司 Head end test method, apparatus and electronic equipment

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10089219B1 (en) * 2017-01-20 2018-10-02 Intuit Inc. Mock server for testing
CN110309048A (en) * 2019-05-21 2019-10-08 深圳壹账通智能科技有限公司 The method and relevant device of integrated software system are improved based on analog port
CN110569159A (en) * 2019-09-05 2019-12-13 深圳前海微众银行股份有限公司 Baffle generation method, device, equipment and computer storage medium
CN110727587A (en) * 2019-09-20 2020-01-24 平安普惠企业管理有限公司 Test data acquisition method and device, storage medium and computer equipment
CN110990205B (en) * 2019-11-28 2022-09-02 腾讯科技(深圳)有限公司 Interface call testing method, device and computer readable storage medium
CN111581079B (en) * 2020-04-16 2023-05-26 微梦创科网络科技(中国)有限公司 Third party advertisement monitoring method and system based on asynchronous verification
CN111695328B (en) * 2020-06-16 2023-01-24 深圳前海微众银行股份有限公司 Simulation test message generation method, device, equipment and storage medium
CN111708702A (en) * 2020-06-18 2020-09-25 深圳前海微众银行股份有限公司 Simulation test method, client, server, system and readable storage medium
CN111782330B (en) * 2020-07-07 2024-01-26 赞同科技股份有限公司 Page data acquisition method, device and equipment based on Web application

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109491905A (en) * 2018-11-02 2019-03-19 北京金山云网络技术有限公司 Head end test method, apparatus and electronic equipment

Also Published As

Publication number Publication date
CN113010411A (en) 2021-06-22

Similar Documents

Publication Publication Date Title
CN110457199B (en) Performance test method and device
CN105335293B (en) A kind of automatization test system and method based on interface concurrent
US7464014B2 (en) Server recording and client playback of computer network characteristics
US8578017B2 (en) Automatic correlation of service level agreement and operating level agreement
US7765096B1 (en) Simulation of network traffic using non-deterministic user behavior models
CN113010411B (en) Method and system for returning data based on mock service and simulation test method
CN107133161B (en) Method and device for generating client performance test script
CN104579822A (en) Automatic performance test system and method of mobile application based on Http protocol
CN105024872A (en) Network performance test method and device
CN103685354A (en) Method and device for testing based on RMI protocol
CN116881145B (en) Interface testing method, device, equipment and storage medium based on flow playback
US20040172253A1 (en) Capture and playback web automation tool
CN116974948A (en) Service system testing method, system, equipment and medium
CN102025555B (en) Method and device for testing IP multimedia sub-system performance
CN113127335A (en) System testing method and device
CN114564387A (en) Scene type automatic testing method and system for OpenStack cloud platform
WO2024139538A1 (en) Script generation method and apparatus, and computing device, system and readable storage medium
CN114416597A (en) Test case record generation method and device
CN114500348A (en) CDN gateway test method and system
CN115617319A (en) An information processing method and device
Helvey Trafgen: An efficient approach to statistically accurate artificial network traffic generation
CN117971693B (en) Software defect processing method, system and storage medium
CN115967797B (en) Product testing method and device, electronic equipment and storage medium
CN114840275A (en) Interface management method, system, computer device and storage medium
CN116955188A (en) Determination method, device, equipment and storage medium of test script

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant