





技术领域technical field
本发明涉及软件工程技术领域,具体而言,涉及一种接口测试方法、装置、计算设备及存储介质。The present invention relates to the technical field of software engineering, and in particular, to an interface testing method, device, computing device and storage medium.
背景技术Background technique
众所周知,在软件产品推出之前,测试人员需要对软件的各部分功能在多种环境下进行多次测试,在和研发人员的共同努力下不断完善软件,其中接口测试是一个重要的环节。实施手工测试不仅需要消耗大量的人力和物力,而且通常需要较长的时间,且测试的可重复性差。随着测试技术的发展,自动化测试很大程度上减轻了手工测试的负担,可实现大量的重复操作,对系统中的接口进行自动测试能够及时发现问题。相比于手工测试,自动化测试在很大程度上能够改善测试性能,节省人力、时间等资源,测试结果准确,测试效率高。As we all know, before a software product is launched, testers need to test the functions of each part of the software many times in a variety of environments, and continuously improve the software with the joint efforts of R&D personnel, of which interface testing is an important link. Implementing manual testing not only consumes a lot of manpower and material resources, but also usually takes a long time and has poor test repeatability. With the development of testing technology, automated testing greatly reduces the burden of manual testing, and can achieve a large number of repetitive operations. Automatic testing of interfaces in the system can detect problems in time. Compared with manual testing, automated testing can greatly improve test performance, save manpower, time and other resources, with accurate test results and high test efficiency.
因此,研究一种基于接口的自动化测试方法,以更好地实现软件自动化测试,成为亟待解决的问题。Therefore, it is an urgent problem to study an interface-based automated testing method to better realize software automated testing.
发明内容SUMMARY OF THE INVENTION
本说明书提供一种接口测试方法、装置、计算设备及存储介质,用以克服现有技术中存在的至少一个技术问题。This specification provides an interface testing method, apparatus, computing device, and storage medium to overcome at least one technical problem existing in the prior art.
根据本说明书实施例的第一方面,提供一种接口测试方法,包括:According to a first aspect of the embodiments of this specification, an interface testing method is provided, including:
S1、获取测试计划包含的接口及接口对应的参数;S1. Obtain the interface included in the test plan and the parameters corresponding to the interface;
S2、确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理;S2. Determine the test case corresponding to each interface, and perform arrangement and combination processing on the test case according to a preset arrangement rule;
S3、执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试报告。S3. Execute the test plan, test the interface by executing the test case, and generate a test report.
可选地,在所述获取测试计划包含的接口及接口对应的参数的步骤之前,还包括:Optionally, before the step of obtaining the interface included in the test plan and the parameters corresponding to the interface, it also includes:
S01、解析配置的定时任务,加入定时工具,在设定时间执行测试计划。S01. Analyze the configured timing task, add a timing tool, and execute the test plan at the set time.
可选地,在所述获取测试计划包含的接口及接口对应的参数的步骤之前,还包括:Optionally, before the step of obtaining the interface included in the test plan and the parameters corresponding to the interface, it also includes:
S02、当监测发现线上有版本迭代时,自动触发执行测试计划。S02. When monitoring finds that there is a version iteration online, the execution of the test plan is automatically triggered.
可选地,所述确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理的步骤包括:Optionally, the step of determining the test case corresponding to each interface, and performing arrangement and combination processing on the test case according to a preset arrangement rule includes:
S21、获取每一接口所对应的测试用例,将所述测试用例的输入和输出统一处理为json形式;S21. Obtain the test case corresponding to each interface, and uniformly process the input and output of the test case into json form;
S22、按照预设的排列规则对所述测试用例进行排列组合处理,形成测试用例流程;S22, arranging and combining the test cases according to a preset arrangement rule to form a test case flow;
S23、按照测试计划对所述测试用例流程进行排列组合处理。S23 , perform permutation and combination processing on the test case flow according to the test plan.
可选地,所述执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试结果报告的步骤包括:Optionally, in the execution of the test plan, the interface is tested by executing a test case, and the step of generating a test result report includes:
S31、按照排列组合后的顺序执行每个测试用例流程中的测试用例,向指定接口发送请求数据,并检查返回数据是否符合预期;若返回数据符合预期,则执行S32;若返回数据不符合预期,则比较返回数据是否满足容错机制,若满足容错机制,则执行S32,否则终止执行并返回错误报告;S31. Execute the test cases in each test case process in the order after the arrangement and combination, send the request data to the specified interface, and check whether the returned data meets expectations; if the returned data meets expectations, execute S32; if the returned data does not meet expectations , then compare whether the returned data satisfies the fault-tolerant mechanism, if it satisfies the fault-tolerant mechanism, execute S32, otherwise terminate the execution and return an error report;
S32、将前一测试用例的请求数据以及返回数据部分注入自定义变量中,将所述自定义变量作为该测试用例流程中后一测试用例的输入参数,所述自定义变量的生命周期是该测试用例流程中的测试用例运行的总时间;S32. Inject the request data and the returned data of the previous test case into a custom variable, and use the custom variable as the input parameter of the next test case in the test case process, and the life cycle of the custom variable is the The total time that the test cases in the test case process were run;
S33、根据每个测试用例流程中测试用例的执行情况,生成测试报告。S33. Generate a test report according to the execution of the test case in each test case process.
根据本说明书实施例的第二方面,提供一种接口测试装置,包括接口获取模块、用例处理模块以及执行报告模块,其中:According to a second aspect of the embodiments of this specification, an interface testing apparatus is provided, including an interface acquisition module, a use case processing module, and an execution report module, wherein:
所述接口获取模块,被配置为获取测试计划包含的接口及接口对应的参数;The interface acquisition module is configured to acquire the interface included in the test plan and the parameters corresponding to the interface;
所述用例处理模块,被配置为确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理;The use case processing module is configured to determine a test case corresponding to each interface, and perform arrangement and combination processing on the test cases according to a preset arrangement rule;
所述执行报告模块,被配置为执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试报告。The execution report module is configured to execute the test plan, test the interface by executing the test case, and generate a test report.
可选地,所述装置还包括定时模块,其中:Optionally, the device further includes a timing module, wherein:
所述定时模块,被配置为解析配置的定时任务,加入定时工具,在设定时间执行测试计划。The timing module is configured to parse the configured timing task, add a timing tool, and execute the test plan at a set time.
可选地,所述装置还包括触发模块,其中:Optionally, the device further includes a trigger module, wherein:
所述触发模块,被配置为当监测发现线上有版本迭代时,自动触发执行测试计划。The triggering module is configured to automatically trigger the execution of the test plan when a version iteration is found online.
根据本说明书实施例的第三方面,提供一种计算设备,包括存储设备以及处理器,所述存储设备用于存储计算机程序,所述处理器运行所述计算机程序以使所述计算设备执行所述接口测试方法的步骤。According to a third aspect of the embodiments of the present specification, there is provided a computing device including a storage device and a processor, the storage device is used to store a computer program, and the processor runs the computer program to cause the computing device to execute the computer program. Describe the steps of the interface testing method.
根据本说明书实施例的第四方面,提供一种存储介质,其存有上述的计算设备中所使用的计算机程序,该计算机程序被处理器执行时实现所述接口测试方法的步骤。According to a fourth aspect of the embodiments of the present specification, a storage medium is provided, which stores a computer program used in the above-mentioned computing device, and when the computer program is executed by a processor, implements the steps of the interface testing method.
本说明书实施例的有益效果如下:The beneficial effects of the embodiments of this specification are as follows:
本说明书实施例,提供一种接口测试方法、装置、计算设备及存储介质,所述接口测试方法通过获取测试接口以及接口对应的测试用例,按照预设的排列顺序对测试用例进行组合处理,生成对应的测试用例流程并对测试用例流程也进行组合排列,并且在测试用例流程之间定义自定义变量,将一个测试用例流程内的测试用例进行关联。此外,通过将测试用例统一处理为json形式,可以测试任何语言、任何协议的接口,对编写测试用例的人员没有任何代码要求。同时,将测试结果生成测试报告,可直接将测试结果的链接进行转发,透明统一,出现的错误一目了然,减少交互,降低测试人员和研发人员的沟通成本。此外,定时功能,增加自动化程度,便于测试人员应用;当项目上线、回滚时,监测到线上版本的迭代,能够自动触发全量回归测试,减少人力成本,能够及时发现问题。The embodiments of this specification provide an interface testing method, device, computing device, and storage medium. The interface testing method obtains a test interface and a test case corresponding to the interface, and combines and processes the test cases according to a preset sequence to generate Corresponding test case processes are combined and arranged, and custom variables are defined between test case processes to associate test cases within a test case process. In addition, by uniformly processing the test cases into json form, the interface of any language and any protocol can be tested, and there is no code requirement for the person who writes the test case. At the same time, a test report is generated from the test results, and the link of the test results can be directly forwarded, which is transparent and unified, and the errors that occur are clear at a glance, reducing interaction and communication costs between testers and R&D personnel. In addition, the timing function increases the degree of automation and is convenient for testers to apply; when the project is launched and rolled back, the iteration of the online version is monitored, which can automatically trigger full regression testing, reduce labor costs, and detect problems in time.
本说明书实施例的创新点包括:The innovative points of the embodiments of this specification include:
1、本实施例中,提供一种接口测试方法通过获取测试接口以及接口对应的测试用例,按照预设的排列顺序对测试用例进行组合处理,生成对应的测试用例流程并对测试用例流程也进行组合排列,并且在测试用例流程之内定义自定义变量,将一个测试用例流程内的测试用例进行关联,是本说明书实施例的创新点之一。1. In this embodiment, an interface testing method is provided by obtaining the test interface and the test case corresponding to the interface, and combining and processing the test cases according to the preset order, generating the corresponding test case process and performing the test case process. Combining and arranging, and defining custom variables in the test case process, to associate test cases in a test case process, is one of the innovations of the embodiments of this specification.
2、本实施例中,将测试用例统一处理为json形式,可以测试任何语言、任何协议的接口,对编写测试用例的人员没有任何代码要求,是本说明书实施例的创新点之一。2. In this embodiment, the test cases are uniformly processed into json form, which can test the interface of any language and any protocol, and there is no code requirement for the personnel who write the test cases, which is one of the innovative points of the embodiments of this specification.
3、本实施例中,当项目上线、回滚时,监测到线上版本的迭代,能够自动触发全量回归测试,减少人力成本,能够第一时间发现问题,是本说明书实施例的创新点之一。3. In this embodiment, when the project is launched and rolled back, the iteration of the online version can be monitored, which can automatically trigger full regression testing, reduce labor costs, and discover problems at the first time, which is one of the innovative points of the embodiments of this specification. one.
附图说明Description of drawings
为了更清楚地说明本说明书实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present specification or the prior art, the following briefly introduces the accompanying drawings required in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained according to these drawings without creative efforts.
图1为本说明书实施例提供的一种接口测试方法的应用场景的结构示意图;1 is a schematic structural diagram of an application scenario of an interface testing method provided by an embodiment of the present specification;
图2为本说明书实施例提供的一种接口测试方法的流程示意图;2 is a schematic flowchart of an interface testing method provided by an embodiment of the present specification;
图3为本说明书实施例提供的一种接口测试装置的结构示意图;3 is a schematic structural diagram of an interface testing device provided by an embodiment of the present specification;
图4为本说明书实施例提供的一种接口测试装置的用例处理模块的结构示意图;FIG. 4 is a schematic structural diagram of a use case processing module of an interface testing device according to an embodiment of the present specification;
图5为本说明书实施例提供的一种接口测试装置的执行报告模块的结构示意图;5 is a schematic structural diagram of an execution report module of an interface testing device provided in an embodiment of the present specification;
图6为本说明书实施例提供的一种计算设备的结构示意图。FIG. 6 is a schematic structural diagram of a computing device according to an embodiment of the present specification.
具体实施方式Detailed ways
下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present specification. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
需要说明的是,本说明书实施例及附图中的术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "comprising" and "having" in the embodiments of the present specification and the accompanying drawings, as well as any modifications thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes unlisted steps or units, or optionally also includes For other steps or units inherent to these processes, methods, products or devices.
随着测试技术的发展,自动化测试很大程度上减轻了手工测试的负担,可实现大量的重复操作,对接口进行自动测试能够快速获得接口的状态,及时发现问题,相比于手工测试,自动化测试在很大程度上能够改善测试性能,节省人力、时间等资源,测试结果准确,测试效率高。With the development of testing technology, automated testing greatly reduces the burden of manual testing, and can achieve a large number of repetitive operations. Automatic testing of interfaces can quickly obtain the status of interfaces and find problems in time. Compared with manual testing, automation To a large extent, the test can improve the test performance, save manpower, time and other resources, the test results are accurate, and the test efficiency is high.
本说明书实施例公开了一种接口测试方法、装置、计算设备及存储介质,以下分别进行详细说明。The embodiments of the present specification disclose an interface testing method, apparatus, computing device and storage medium, which will be described in detail below.
首先对接口测试的测试环境进行说明,接口测试的测试环境可由用户自定义环境(通常为:开发、测试、灰度、线上四种)并配置各个环境的访问地址。环境中可以配置一些验签用到的信息和算法,在获取测试用例配置时会根据指定环境自动关联。单个测试用例或测试计划执行时,根据关联的环境名称读取环境配置信息,从而找到对应的环境地址。同一个测试计划可以在一个或多个环境下同时执行,但由于多接口的布置方式,相同时间在相同环境下,相同测试计划只能执行一次,比如,在11:30的测试环境不能存在两个执行中的plan001,但可以同时存在执行中的plan001,plan002,plan003,plan001也可以在相同时间同时在开发、测试、灰度、生产等环境中执行。First, the test environment of the interface test is explained. The test environment of the interface test can be customized by the user (usually: development, test, grayscale, and online) and the access address of each environment can be configured. Some information and algorithms used for signature verification can be configured in the environment, which will be automatically associated according to the specified environment when obtaining the test case configuration. When a single test case or test plan is executed, the environment configuration information is read according to the associated environment name to find the corresponding environment address. The same test plan can be executed in one or more environments at the same time, but due to the arrangement of multiple interfaces, the same test plan can only be executed once in the same environment at the same time. plan001 in execution, but plan001, plan002, plan003, plan001 in execution can exist at the same time, and they can also be executed in development, test, grayscale, production and other environments at the same time.
其次,对注入项和检查项进行说明。Next, the injection items and inspection items are explained.
注入项:也就是注入变量,从测试用例的请求头、返回头、请求体、返回体,静态类型case的全部或部分中进行注入的。Injection item: that is, injection variables, which are injected from the request header, return header, request body, return body, and all or part of the static type case of the test case.
检查项:也是对请求头、返回头、请求体、返回体中的全部或部分进行检查。Check item: It also checks all or part of the request header, return header, request body, and return body.
比如返回体为:For example, the return body is:
使用$ResponseBody.block.id即可获得值:"1234567",可以对该值进行检查和注入。Use $ResponseBody.block.id to get the value: "1234567", which can be checked and injected.
实施例一Example 1
图1为本说明书实施例提供的一种接口测试方法的应用场景的结构示意图。如图1所示,为一种接口测试方法应用于集成测试平台对应的该平台的架构示意图。图中,该集成测试平台核心部分为:method(接口、实例),case,flow,plan四个部分,辅助部分为:环境和触发执行方式两部分。Method层用于获取测试接口的配置,case层用于配置与接口关联的测试用例,case可配置一个或多个版本;flow层是根据用户需求按照顺序排列组合的一组组测试用例,在单个flow的测试用例之间有自定义变量,将前面执行的case的请求内容或返回数据的部分或全部注入后面执行的case的输入,将一组测试用例进行关联,放在一个流程中测试,flow根据容错性的高低,分为遇到错误终止执行和忽略错误继续执行两种。Plan层Plan是平台中真正要被执行的测试计划,通常是一整个功能模块或者某些服务的一次迭代,plan由若干flow组成,flow之间并行执行,无执行依赖,plan中可以配置要执行的版本,接口类型,运行环境,及在每个环境下的触发方式,plan中的执行方式分为:定时执行,发布执行(触发执行),和手动执行三种。FIG. 1 is a schematic structural diagram of an application scenario of an interface testing method provided by an embodiment of the present specification. As shown in FIG. 1 , it is a schematic structural diagram of an interface testing method applied to an integrated testing platform corresponding to the platform. In the figure, the core part of the integration test platform is: method (interface, instance), case, flow, plan four parts, the auxiliary part is: environment and trigger execution mode two parts. The method layer is used to obtain the configuration of the test interface, the case layer is used to configure the test cases associated with the interface, and the case can be configured with one or more versions; the flow layer is a group of test cases that are arranged and combined in sequence according to user requirements. There are custom variables between the test cases of the flow. Part or all of the request content or the returned data of the previously executed case is injected into the input of the later executed case, and a set of test cases are associated and tested in a flow. According to the level of fault tolerance, it is divided into two types: terminating execution when encountering an error and continuing execution ignoring the error. Plan layer Plan is a test plan that is really to be executed in the platform, usually an entire functional module or an iteration of some services. The plan consists of several flows, which are executed in parallel between flows without execution dependencies. The plan can be configured to be executed. version, interface type, operating environment, and trigger mode in each environment, the execution mode in the plan is divided into three types: timed execution, release execution (triggered execution), and manual execution.
在测试计划以指定方式触发执行后,在指定环境中进行测试,获取所有指定的测试接口即接口,按照预设的顺序执行相关的测试用例从而执行测试计划,各flow之间并行执行,flow内case串行执行,向指定接口发送数据并检查返回值是否符合预期,或对指定数据库进行增删改查,根据测试用例的执行情况,生成测试报告。将测试用例的输入输出统一处理为json形式,不受编程语言和协议的限制;具有定时执行功能,并且项目上线、回滚,自动触发全量回归测试,减少人力成本,透明统一,错误一目了然,测试效率高。After the test plan is triggered to execute in a specified way, perform the test in the specified environment, obtain all the specified test interfaces or interfaces, and execute the relevant test cases in the preset order to execute the test plan. The case is executed serially, sending data to the specified interface and checking whether the return value meets the expectations, or adding, deleting, modifying and checking the specified database, and generating a test report according to the execution of the test case. Unified processing of the input and output of test cases into json form, which is not limited by programming languages and protocols; it has the function of timed execution, and the project goes online and rolls back, automatically triggers full regression testing, reduces labor costs, is transparent and unified, and errors are clear at a glance. efficient.
实施例二Embodiment 2
图2为本说明书实施例提供的一种接口测试方法的流程示意图。如图2所示,一种接口测试方法,包括:FIG. 2 is a schematic flowchart of an interface testing method provided by an embodiment of the present specification. As shown in Figure 2, an interface testing method includes:
110、获取测试计划包含的接口及接口对应的参数。110. Obtain the interface included in the test plan and the parameters corresponding to the interface.
获取测试计划包含的接口及对应的参数,所述接口至少包含三种类型接口中的任一种,分别是grpc,http,graphql三种接口形式,Grpc类型接口,根据proto文件自动获得请求方式,uri、method名称、请求信息、响应信息等,并以此为根据进行Json渲染,用户只需要修改重要Key的value即可;http类型的接口本身是json友好的;Graphql类型接口,自动获得graphql query和garphql variable的格式,用户修改重要variable的value即可。获得接口配置,以确定测试接口。Obtain the interface and corresponding parameters included in the test plan. The interface includes at least any one of three types of interfaces, namely grpc, http, graphql three interface forms, Grpc type interface, and the request method is automatically obtained according to the proto file, uri, method name, request information, response information, etc., and use this as a basis for Json rendering. Users only need to modify the value of important Keys; the http type interface itself is json friendly; the Graphql type interface automatically obtains the graphql query And the format of garphql variable, the user can modify the value of the important variable. Obtain the interface configuration to determine the test interface.
可选地,在所述获取测试计划包含的接口及接口对应的参数的步骤之前,还包括:Optionally, before the step of obtaining the interface included in the test plan and the parameters corresponding to the interface, it also includes:
102、解析配置的定时任务,加入定时工具,在设定时间执行测试计划。102. Analyze the configured timing tasks, add timing tools, and execute the test plan at the set time.
当测试计划提交新增或修改请求时,解析配置的定时任务,将定时任务添加到cron模块,由cron模块实现定时执行。When the test plan submits a new or modified request, the configured scheduled tasks are parsed, and the scheduled tasks are added to the cron module, and the cron module implements scheduled execution.
可选地,在所述获取测试计划包含的接口及接口对应的参数的步骤之前,还包括:Optionally, before the step of obtaining the interface included in the test plan and the parameters corresponding to the interface, it also includes:
103、当监测发现线上有版本迭代时,自动触发执行测试计划。103. When monitoring finds that there are version iterations online, automatically trigger the execution of the test plan.
例如,“用户增删改查测试计划”每天凌晨三点自动触发测试环境的测试,且当发现线上有版本迭代时自动触发线上的测试。For example, "Users add, delete, modify, and check the test plan" automatically triggers the test of the test environment at 3:00 am every day, and automatically triggers the online test when an online version is found to be iterated.
120、确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理。120. Determine a test case corresponding to each interface, and perform an arrangement and combination process on the test case according to a preset arrangement rule.
一个flow中的case通常是面向不同接口的,比如“增删改查”可以对接4个接口,通常放在一个流程中测试。Cases in a flow are usually oriented to different interfaces. For example, "add, delete, modify and check" can connect to 4 interfaces, which are usually tested in one process.
可选地,所述确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理的步骤包括:Optionally, the step of determining the test case corresponding to each interface, and performing arrangement and combination processing on the test case according to a preset arrangement rule includes:
122、获取每一接口所对应的测试用例,将所述测试用例的输入和输出统一处理为json形式。122. Obtain a test case corresponding to each interface, and uniformly process the input and output of the test case into a json form.
获得测试人员编写的测试用例,测试用例可分为三种类型,分别是分为接口类型,实例类型和静态类型。其中,接口类型用例用于向接口发送指定数据,并检查返回数据是否符合预期;实例类型用例用于执行对数据库的增删改查,例如,向mysql插入一条初始化数据:insert into;静态类型用例,用于注入变量的值,例如对于指定用户操作(userid),在不同环境可能存在不同的测试用户,使用静态变量可以在不同环境为同一个变量注入不同的值。Obtain test cases written by testers. Test cases can be divided into three types, namely interface type, instance type and static type. Among them, the interface type use case is used to send the specified data to the interface and check whether the returned data meets the expectations; the instance type use case is used to perform additions, deletions and changes to the database, for example, insert an initialization data into mysql: insert into; static type use cases, The value used to inject the variable, for example, for the specified user action (userid), there may be different test users in different environments, and static variables can be used to inject different values for the same variable in different environments.
其中,接口类型用例的输入、输出要做格式上的统一,具体地,对于grpc类型的接口,根据proto文件将json解析为可通过grpc进行传输的请求;http类型的接口本身是json友好的,不需要进行额外的处理;graphql类型的接口,根据配置的query(接口模块注册)拼接variables(用例输入)生成请求内容。实例类型用例的输入输出与接口类型用例做相似处理;静态类型用例为静态json。Among them, the input and output of the interface type use case should be unified in format. Specifically, for the grpc type interface, json is parsed into a request that can be transmitted through grpc according to the proto file; the http type interface itself is json friendly, No additional processing is required; the graphql-type interface splices variables (use case input) according to the configured query (interface module registration) to generate the request content. The input and output of instance type use cases are handled similarly to interface type use cases; static type use cases are static json.
124、按照预设的排列规则对所述测试用例进行排列组合处理,形成测试用例流程。124. Perform an arrangement and combination process on the test cases according to a preset arrangement rule to form a test case flow.
测试用例流程由一组测试用例组成,同一流程中的测试用例顺序执行,先执行的用例的输入、输出可以作为后执行用例的部分或全部输入。The test case process consists of a set of test cases. The test cases in the same process are executed sequentially, and the input and output of the first executed use case can be used as part or all of the input of the later executed use case.
测试用例流程根据容错机制的高低分为两种,分为遇到错误终止执行,和忽略错误继续执行两种,其中遇到错误终止执行的容错性低,忽略错误继续执行的容错性高。The test case process is divided into two types according to the level of fault tolerance mechanism. It is divided into two types: terminating execution when encountering an error, and continuing to execute ignoring the error. Among them, the fault tolerance of terminating execution when encountering an error is low, and the fault tolerance of ignoring the error and continuing to execute is high.
126、按照测试计划对所述测试用例流程进行排列组合处理。126. Perform permutation and combination processing on the test case flow according to the test plan.
测试计划包含多个测试用例流程,流程之间并行执行,无执行依赖。The test plan contains multiple test case processes, and the processes are executed in parallel without execution dependencies.
130、执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试报告。130. Execute the test plan, test the interface by executing the test case, and generate a test report.
通过按照预设的顺序执行测试用例,对测试计划中的接口进行测试,完成对接口多种状态的覆盖,测试计划是一整个功能模块或者某些服务的一次迭代,最终根据用例的执行情况,生成对整个功能模块或者某次服务的测试报告。By executing the test cases in the preset order, the interface in the test plan is tested, and the coverage of various states of the interface is completed. The test plan is an iteration of an entire functional module or some services, and finally according to the execution of the use case, Generate a test report for the entire function module or a service.
可选地,所述执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试结果报告的步骤包括:Optionally, in the execution of the test plan, the interface is tested by executing a test case, and the step of generating a test result report includes:
132、按照排列组合后的顺序执行每个测试用例流程中的测试用例,向指定接口发送请求数据,并检查返回数据是否符合预期;若返回数据符合预期,则执行S32;若返回数据不符合预期,则比较返回数据是否满足容错机制,若满足容错机制,则执行S32,否则终止执行并返回错误报告。132. Execute the test cases in each test case process in the order of arrangement and combination, send the request data to the specified interface, and check whether the returned data meets expectations; if the returned data meets expectations, execute S32; if the returned data does not meet expectations , then compare whether the returned data satisfies the fault-tolerant mechanism, and if it satisfies the fault-tolerant mechanism, execute S32; otherwise, terminate the execution and return an error report.
测试用例可以单独运行,用于调试或临时测试,也可以在测试计划中被统一调度。单个测试用例在执行中串行运行三种操作,分别为校验、注入和睡眠,当执行遇到错误后立即返回,不再继续执行。Test cases can be run individually for debugging or ad hoc testing, or they can be scheduled collectively in a test plan. A single test case runs three operations serially during execution, namely verification, injection and sleep. When the execution encounters an error, it returns immediately and does not continue to execute.
其中,用例的校验操作是指校验可以检查请求、返回值的任意部分是否符合预期,比如返回的某个字段长度是否等于7,返回值同样以json形式存储。Among them, the verification operation of the use case means that the verification can check whether any part of the request and return value meets the expectations, such as whether the length of a field returned is equal to 7, and the return value is also stored in the form of json.
用例的注入操作是将请求、返回的任意部分注入到自定义名称的变量中,供后续用例使用。自定义变量的使用方式为{{VARIABLE.user_define_variable_name}}。自定义变量的生命周期是一个运行中的flow。The injection operation of a use case is to inject any part of the request and return into a variable with a custom name for subsequent use cases. Custom variables are used as {{VARIABLE.user_define_variable_name}}. The lifecycle of a custom variable is a running flow.
睡眠操作是指,执行完该用例后,等待多长时间进行下一个用例的执行,通常用于等待异步任务返回结果。The sleep operation refers to how long to wait for the execution of the next use case after the execution of the use case, which is usually used to wait for the return result of the asynchronous task.
134、将前一测试用例的请求数据以及返回数据部分注入自定义变量中,将所述自定义变量作为该测试用例流程中后一测试用例的输入参数,所述自定义变量的生命周期是该测试用例流程中的测试用例运行的总时间。134. Inject the request data and return data of the previous test case into a custom variable, and use the custom variable as the input parameter of the next test case in the test case process, and the life cycle of the custom variable is the The total time that the test cases in the test case process ran.
通过测试用例的注入操作,在测试用例流程中的测试用例之间定义自定义变量,实现将一组测试用例进行关联,放在一个流程中进行测试。Through the injection operation of test cases, custom variables are defined between test cases in the test case process, so that a group of test cases can be associated and tested in one process.
136、根据每个测试用例流程中测试用例的执行情况,生成测试报告。136. Generate a test report according to the execution of the test cases in each test case process.
根据测试用例的执行情况,生成测试报告,测试报告可以以链接的形式进行转发,透明统一,出现的错误一目了然,减少交互,降低测试人员和研发人员的沟通成本。According to the execution of the test case, the test report is generated, and the test report can be forwarded in the form of a link, which is transparent and unified, and the errors that occur are clear at a glance, which reduces the interaction and reduces the communication cost between testers and R&D personnel.
本实施例中,提供一种接口测试方法,通过获取测试接口以及接口对应的测试用例,对测试用例的输入输出进行统一的格式处理,从而对编程语言和协议没有限制;按照预设顺序组合测试用例并在测试用例流程之间定义自定义变量,实现测试用例的关联,从而完成对接口的更全面地测试覆盖;自动触发执行、定时执行以及手动执行的多种执行触发方式,提高了测试的自动化程度,提高测试人员的工作效率。In this embodiment, an interface testing method is provided. By acquiring the test interface and the test case corresponding to the interface, the input and output of the test case are processed in a unified format, so that there is no restriction on the programming language and protocol; the tests are combined according to the preset order. Use cases and define custom variables between the test case processes to realize the association of test cases, so as to complete the more comprehensive test coverage of the interface; automatic trigger execution, timed execution and manual execution. The degree of automation improves the work efficiency of testers.
实施例三Embodiment 3
图3为本说明书实施例提供的一种接口测试装置的结构示意图。如图3所示,一种接口测试装置200,包括接口获取模块210、用例处理模块220以及执行报告模块230,其中:FIG. 3 is a schematic structural diagram of an interface testing apparatus according to an embodiment of the present specification. As shown in FIG. 3, an interface testing apparatus 200 includes an interface acquiring module 210, a use case processing module 220 and an execution reporting module 230, wherein:
所述接口获取模块,被配置为获取测试计划包含的接口及接口对应的参数。The interface acquisition module is configured to acquire the interfaces included in the test plan and parameters corresponding to the interfaces.
所述用例处理模块,被配置为确定每一接口所对应的测试用例,按照预设的排列规则对所述测试用例进行排列组合处理。The use case processing module is configured to determine a test case corresponding to each interface, and perform arrangement and combination processing on the test cases according to a preset arrangement rule.
可选地,所述用例处理模块包括获取预处理单元、流程生成单元以及流程组合单元。Optionally, the use case processing module includes an acquisition preprocessing unit, a process generation unit, and a process combination unit.
图4为本说明书实施例提供的一种接口测试装置的用例处理模块的结构示意图。如图4所示,所述用例处理模块220包括获取预处理单元222、流程生成单元224以及流程组合单元226,其中FIG. 4 is a schematic structural diagram of a use case processing module of an interface testing apparatus according to an embodiment of the present specification. As shown in FIG. 4 , the use case processing module 220 includes an
所述获取预处理单元222,被配置为获取每一接口所对应的测试用例,将所述测试用例的输入和输出统一处理为json形式。The
所述流程生成单元224,被配置为按照预设的排列规则对所述测试用例进行排列组合处理,形成测试用例流程。The process generation unit 224 is configured to perform an arrangement and combination process on the test cases according to a preset arrangement rule to form a test case process.
所述流程组合单元226,被配置为按照测试计划对所述测试用例流程进行排列组合处理。The process combination unit 226 is configured to perform permutation and combination processing on the test case process according to the test plan.
所述执行报告模块,被配置为执行所述测试计划,通过执行测试用例来对接口进行测试,生成测试报告。The execution report module is configured to execute the test plan, test the interface by executing the test case, and generate a test report.
可选地,所述执行报告模块包括用例执行单元、流程运行单元以及报告生成单元。Optionally, the execution report module includes a use case execution unit, a process execution unit and a report generation unit.
图5为本说明书实施例提供的一种接口测试装置的执行报告模块的结构示意图。如图5所示,所述执行报告模块230包括用例执行单元232、流程运行单元234以及报告生成单元236,其中FIG. 5 is a schematic structural diagram of an execution report module of an interface testing apparatus according to an embodiment of the present specification. As shown in FIG. 5 , the execution report module 230 includes a use
所述用例执行单元232,被配置为按照排列组合后的顺序执行每个测试用例流程中的测试用例,向指定接口发送请求数据,并检查返回数据是否符合预期;若返回数据符合预期,则继续执行所述流程运行单元;若返回数据不符合预期,则比较返回数据是否满足容错机制,若满足容错机制,则继续执行所述流程运行单元,否则终止执行并返回错误报告。The use
所述流程运行单元234,被配置为将前一测试用例的请求数据以及返回数据部分注入自定义变量中,将所述自定义变量作为该测试用例流程中后一测试用例的输入参数,所述自定义变量的生命周期是该测试用例流程中的测试用例运行的总时间。The process running unit 234 is configured to inject the request data and the returned data part of the previous test case into a custom variable, and use the custom variable as the input parameter of the next test case in the test case process, the The lifetime of a custom variable is the total time the test cases in that test case process run.
所述报告生成单元236,被配置为根据每个测试用例流程中测试用例的执行情况,生成测试报告。The report generating unit 236 is configured to generate a test report according to the execution of the test case in each test case process.
可选地,所述装置200还包括定时模块202,其中:Optionally, the apparatus 200 further includes a timing module 202, wherein:
所述定时模块202,被配置为解析配置的定时任务,加入定时工具,在设定时间执行测试计划。The timing module 202 is configured to parse the configured timing task, add a timing tool, and execute the test plan at the set time.
可选地,所述装置200还包括触发模块204,其中:Optionally, the apparatus 200 further includes a triggering module 204, wherein:
所述触发模块204,被配置为当监测发现线上有版本迭代时,自动触发执行测试计划。The triggering module 204 is configured to automatically trigger the execution of the test plan when a version iteration is found online.
本实施例中,提供一种接口测试装置200,能够实现接口测试方法的功能,对应的实施步骤和效果可参照方法部分。In this embodiment, an interface testing apparatus 200 is provided, which can realize the functions of the interface testing method, and the corresponding implementation steps and effects may refer to the method part.
实施例四Embodiment 4
图6为本说明书实施例提供的一种计算设备的结构示意图。如图6所示,一种计算设备600,包括存储设备610以及处理器620,所述存储设备610用于存储计算机程序,所述处理器620运行所述计算机程序以使所述计算设备600执行所述接口测试方法的步骤。FIG. 6 is a schematic structural diagram of a computing device according to an embodiment of the present specification. As shown in FIG. 6, a computing device 600 includes a
本说明书提供一种存储介质,其存储有上述的计算设备600中所使用的计算机程序,该计算机程序被处理器执行时实现所述接口测试方法的步骤。This specification provides a storage medium, which stores the computer program used in the above-mentioned computing device 600, and when the computer program is executed by the processor, implements the steps of the interface testing method.
综上所述,本说明书提供一种接口测试方法、装置、计算设备及存储介质,所述测试方法通过关联的测试用例形成测试流程,并且对编写测试用例的人员没有任何代码要求,具有定时执行功能和上线自动触发功能,测试结果明了,减少测试的人力成本,提高测试效率。To sum up, this specification provides an interface testing method, device, computing device and storage medium. The testing method forms a testing process through associated test cases, does not require any code for the personnel who write the test cases, and has timed execution. Function and online automatic trigger function, the test results are clear, reduce the labor cost of the test, and improve the test efficiency.
本领域普通技术人员可以理解:附图只是一个实施例的示意图,附图中的模块或流程并不一定是实施本发明所必须的。Those of ordinary skill in the art can understand that the accompanying drawing is only a schematic diagram of an embodiment, and the modules or processes in the accompanying drawing are not necessarily necessary to implement the present invention.
本领域普通技术人员可以理解:实施例中的装置中的模块可以按照实施例描述分布于实施例的装置中,也可以进行相应变化位于不同于本实施例的一个或多个装置中。上述实施例的模块可以合并为一个模块,也可以进一步拆分成多个子模块。Those skilled in the art may understand that: the modules in the apparatus in the embodiment may be distributed in the apparatus in the embodiment according to the description of the embodiment, and may also be located in one or more apparatuses different from this embodiment with corresponding changes. The modules in the foregoing embodiments may be combined into one module, or may be further split into multiple sub-modules.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that it can still be The technical solutions described in the foregoing embodiments are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010612367.4ACN111752844A (en) | 2020-06-30 | 2020-06-30 | An interface testing method, device, computing device and storage medium |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010612367.4ACN111752844A (en) | 2020-06-30 | 2020-06-30 | An interface testing method, device, computing device and storage medium |
| Publication Number | Publication Date |
|---|---|
| CN111752844Atrue CN111752844A (en) | 2020-10-09 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010612367.4APendingCN111752844A (en) | 2020-06-30 | 2020-06-30 | An interface testing method, device, computing device and storage medium |
| Country | Link |
|---|---|
| CN (1) | CN111752844A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112380141A (en)* | 2020-12-11 | 2021-02-19 | 上海中通吉网络技术有限公司 | Interface case set execution method and device |
| CN112559356A (en)* | 2020-12-18 | 2021-03-26 | 杭州兑吧网络科技有限公司 | Automatic software testing method and system |
| CN112597047A (en)* | 2020-12-29 | 2021-04-02 | 上海瑞家信息技术有限公司 | Test method, test device, electronic equipment and computer readable medium |
| CN112631914A (en)* | 2020-12-24 | 2021-04-09 | 上海幻电信息科技有限公司 | Data testing method and device |
| CN113485914A (en)* | 2021-06-09 | 2021-10-08 | 镁佳(北京)科技有限公司 | Vehicle-mounted voice SDK testing method, device and system |
| CN113656309A (en)* | 2021-08-19 | 2021-11-16 | 蔚来汽车科技(安徽)有限公司 | Test case life cycle iteration management method and system and medium |
| CN114546842A (en)* | 2022-02-09 | 2022-05-27 | 青岛海尔科技有限公司 | Interface test method and device, storage medium and electronic equipment |
| CN114741309A (en)* | 2022-04-25 | 2022-07-12 | 湖南快乐阳光互动娱乐传媒有限公司 | Interface testing method, system, storage medium and electronic equipment |
| CN115525561A (en)* | 2022-10-11 | 2022-12-27 | 深圳市航盛电子股份有限公司 | Protocol interface testing method, device, terminal equipment and storage medium |
| CN115952100A (en)* | 2023-01-10 | 2023-04-11 | 北京百度网讯科技有限公司 | Interface test method, device, system, electronic equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US9268672B1 (en)* | 2014-05-27 | 2016-02-23 | Amazon Technologies, Inc. | Automated test case generation for applications |
| CN108563571A (en)* | 2018-04-11 | 2018-09-21 | 车巴达(苏州)网络科技有限公司 | Software interface test approach and system, computer readable storage medium, terminal |
| CN110232016A (en)* | 2019-03-08 | 2019-09-13 | 上海蔚来汽车有限公司 | Interface testing case generation method, device and controller and medium |
| CN110928774A (en)* | 2019-11-07 | 2020-03-27 | 杭州顺网科技股份有限公司 | Automatic test system based on node formula |
| CN111198809A (en)* | 2018-11-16 | 2020-05-26 | 北京奇虎科技有限公司 | Interface automated testing method and device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US9268672B1 (en)* | 2014-05-27 | 2016-02-23 | Amazon Technologies, Inc. | Automated test case generation for applications |
| CN108563571A (en)* | 2018-04-11 | 2018-09-21 | 车巴达(苏州)网络科技有限公司 | Software interface test approach and system, computer readable storage medium, terminal |
| CN111198809A (en)* | 2018-11-16 | 2020-05-26 | 北京奇虎科技有限公司 | Interface automated testing method and device |
| CN110232016A (en)* | 2019-03-08 | 2019-09-13 | 上海蔚来汽车有限公司 | Interface testing case generation method, device and controller and medium |
| CN110928774A (en)* | 2019-11-07 | 2020-03-27 | 杭州顺网科技股份有限公司 | Automatic test system based on node formula |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112380141A (en)* | 2020-12-11 | 2021-02-19 | 上海中通吉网络技术有限公司 | Interface case set execution method and device |
| CN112559356A (en)* | 2020-12-18 | 2021-03-26 | 杭州兑吧网络科技有限公司 | Automatic software testing method and system |
| CN112631914A (en)* | 2020-12-24 | 2021-04-09 | 上海幻电信息科技有限公司 | Data testing method and device |
| CN112631914B (en)* | 2020-12-24 | 2024-11-05 | 上海幻电信息科技有限公司 | A data testing method and device |
| CN112597047A (en)* | 2020-12-29 | 2021-04-02 | 上海瑞家信息技术有限公司 | Test method, test device, electronic equipment and computer readable medium |
| CN113485914A (en)* | 2021-06-09 | 2021-10-08 | 镁佳(北京)科技有限公司 | Vehicle-mounted voice SDK testing method, device and system |
| CN113656309A (en)* | 2021-08-19 | 2021-11-16 | 蔚来汽车科技(安徽)有限公司 | Test case life cycle iteration management method and system and medium |
| CN114546842A (en)* | 2022-02-09 | 2022-05-27 | 青岛海尔科技有限公司 | Interface test method and device, storage medium and electronic equipment |
| CN114741309A (en)* | 2022-04-25 | 2022-07-12 | 湖南快乐阳光互动娱乐传媒有限公司 | Interface testing method, system, storage medium and electronic equipment |
| CN115525561A (en)* | 2022-10-11 | 2022-12-27 | 深圳市航盛电子股份有限公司 | Protocol interface testing method, device, terminal equipment and storage medium |
| CN115952100A (en)* | 2023-01-10 | 2023-04-11 | 北京百度网讯科技有限公司 | Interface test method, device, system, electronic equipment and storage medium |
| Publication | Publication Date | Title |
|---|---|---|
| CN111752844A (en) | An interface testing method, device, computing device and storage medium | |
| CN107273286B (en) | Scene automatic test platform and method for task application | |
| Turner et al. | The state-based testing of object-oriented programs | |
| US20200285570A1 (en) | Systems and methods for automated programmatic test generation and software validation | |
| CN112463586B (en) | Method and medium for automatically generating application program interface test case | |
| CN111221721B (en) | Automatic recording and executing method and device for unit test cases | |
| CN111782452A (en) | Method, system, device and medium for interface comparison test | |
| Sun et al. | Automated testing of WS-BPEL service compositions: A scenario-oriented approach | |
| Wahler et al. | CAST: Automating software tests for embedded systems | |
| CN113448826A (en) | Software automation test system and method | |
| Sag et al. | Measuring COSMIC software size from functional execution traces of Java business applications | |
| CN117493188A (en) | Interface testing methods and devices, electronic equipment and storage media | |
| Braunisch et al. | Maturity evaluation of sdks for i4. 0 digital twins | |
| CN111552648A (en) | Automatic verification method and system for application | |
| Tsai et al. | Scenario-based test case generation for state-based embedded systems | |
| Costa et al. | Taxonomy of performance testing tools: A systematic literature review | |
| CN113220586A (en) | Automatic interface pressure test execution method, device and system | |
| Panthi et al. | Generating and evaluating effectiveness of test sequences using state machine | |
| Wang et al. | Application of Model-based Testing on a Quorum-based Distributed Storage. | |
| CN116048962A (en) | Test report generation method, device, computer equipment and storage medium | |
| US11449412B2 (en) | Automated unit testing in a mainframe CICS environment | |
| CN108984401A (en) | A kind of solution decoupling detecting method | |
| CN114741300A (en) | Test method and device based on test case | |
| CN114116466A (en) | Unit testing method, device and medium based on operation log | |
| CN117472641B (en) | Data quality detection method and device, electronic equipment and storage medium |
| 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 | ||
| CB02 | Change of applicant information | Country or region after:China Address after:1902, 19th Floor, China Electronics Building, No. 3 Danling Road, Haidian District, Beijing Applicant after:BEIJING LAIYE NETWORK TECHNOLOGY Co.,Ltd. Applicant after:Laiye Technology (Beijing) Co.,Ltd. Address before:1902, 19 / F, China Electronics Building, 3 Danling Road, Haidian District, Beijing 100080 Applicant before:BEIJING LAIYE NETWORK TECHNOLOGY Co.,Ltd. Country or region before:China Applicant before:BEIJING BENYING NETWORK TECHNOLOGY Co.,Ltd. | |
| CB02 | Change of applicant information | ||
| RJ01 | Rejection of invention patent application after publication | Application publication date:20201009 | |
| RJ01 | Rejection of invention patent application after publication |