[go: up one dir, main page]

CN114416537A - Unit testing method, server, client and storage medium - Google Patents

Unit testing method, server, client and storage medium Download PDF

Info

Publication number
CN114416537A
CN114416537A CN202111656660.1A CN202111656660A CN114416537A CN 114416537 A CN114416537 A CN 114416537A CN 202111656660 A CN202111656660 A CN 202111656660A CN 114416537 A CN114416537 A CN 114416537A
Authority
CN
China
Prior art keywords
sub
module
code
tested
development code
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.)
Pending
Application number
CN202111656660.1A
Other languages
Chinese (zh)
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.)
Zhejiang Geely Holding Group Co Ltd
Hangzhou Youxing Technology Co Ltd
Original Assignee
Zhejiang Geely Holding Group Co Ltd
Hangzhou Youxing 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 Zhejiang Geely Holding Group Co Ltd, Hangzhou Youxing Technology Co Ltd filed Critical Zhejiang Geely Holding Group Co Ltd
Priority to CN202111656660.1A priority Critical patent/CN114416537A/en
Publication of CN114416537A publication Critical patent/CN114416537A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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

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)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a unit testing method, a server, a client and a storage medium, wherein the method comprises the following steps: responding to a dependency configuration instruction which is sent by a client and aims at a plurality of sub-modules and a parent module, and establishing the dependency relationship between the plurality of sub-modules and the parent module; receiving a unit test request aiming at a sub-module to be tested, which is sent by a client; responding to the unit test request, and determining an associated development code according to the dependency relationship; testing the sub-module to be tested operation unit to obtain code coverage rate; and sending the code coverage rate to the client. In the scheme, the dependency relationship is established between the multiple sub-modules and the parent module, the associated development codes under the parent module and having a calling relationship with the sub-modules to be tested can be determined according to the dependency relationship, and the obtained code coverage rate is the coverage condition of all source codes related to the functions of the sub-modules to be tested, so that the accuracy of code coverage rate test is improved.

Description

一种单元测试方法、服务端、客户端及存储介质A unit testing method, server, client and storage medium

技术领域technical field

本发明涉及计算机视觉领域,尤其涉及一种单元测试方法、服务端、客户端及存储介质。The invention relates to the field of computer vision, in particular to a unit testing method, a server, a client and a storage medium.

背景技术Background technique

代码覆盖率,是指测试代码的覆盖程度。在做单元测试时,代码覆盖率通常作为衡量测试好坏的指标。Code coverage refers to the degree of coverage of the test code. When doing unit testing, code coverage is often used as a measure of how good the test is.

随着微服务架构开发技术的广泛应用,一个项目往往包含多个模块进行分解管理和开发。通常源代码放在一个模块目录下,而单元测试代码放在另外一个模块目录下,这样只能统计到当前模块目录下的单元测试代码覆盖率情况,而需要统计的是单元测试的代码对所有涉及到当前模块功能的源代码的覆盖率情况。因此,这种模块隔离会导致代码覆盖率测试不准确。With the wide application of microservice architecture development technology, a project often contains multiple modules for decomposing management and development. Usually the source code is placed in a module directory, and the unit test code is placed in another module directory, so that only the coverage of the unit test code in the current module directory can be counted, and the unit test code needs to be counted for all Coverage of the source code involving the current module functionality. Therefore, this module isolation can lead to inaccurate code coverage tests.

发明内容SUMMARY OF THE INVENTION

本发明旨在至少解决现有技术中存在的技术问题之一。为此,本发明第一方面提出一种单元测试方法,应用于服务端,所述方法包括:The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the first aspect of the present invention proposes a unit testing method, which is applied to a server, and the method includes:

响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立所述多个子模块与所述父模块的依赖关系;In response to the dependency configuration instruction sent by the client for multiple submodules and the parent module, establishing the dependency relationship between the multiple submodules and the parent module;

接收所述客户端发送的、针对待测试子模块的单元测试请求;所述待测试子模块为所述多个子模块中的至少一个子模块;receiving a unit test request sent by the client for the submodule to be tested; the submodule to be tested is at least one submodule of the plurality of submodules;

响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码;In response to the unit test request, determine the associated development code according to the dependency relationship; the associated development code is the development code that has a calling relationship with the submodule to be tested in the plurality of submodules;

对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率;Run a unit test on the submodule to be tested to obtain code coverage; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code;

将所述代码覆盖率发送给所述客户端。Send the code coverage to the client.

可选的,所述响应于所述单元测试请求,对所述待测试子模块运行单元测试,包括:Optionally, in response to the unit test request, running a unit test on the submodule to be tested includes:

响应于所述单元测试请求,从所述多个子模块中确定与所述待测试子模块有调用关系的子模块,得到关联子模块;In response to the unit test request, determine a submodule having a calling relationship with the submodule to be tested from the plurality of submodules, and obtain an associated submodule;

从所述关联子模块中获取与所述待测试子模块有调用关系的开发代码,得到关联开发代码;Obtain the development code that has a calling relationship with the submodule to be tested from the associated submodule, and obtain the associated development code;

拉取所述待测试子模块的开发代码;Pull the development code of the submodule to be tested;

利用所述待测试子模块的单元测试代码,对所述待测试子模块的开发代码和所述关联开发代码运行单元测试;Using the unit test code of the submodule to be tested, run a unit test on the development code of the submodule to be tested and the associated development code;

获取所述单元测试代码相对于所述待测试子模块的开发代码、所述关联开发代码的覆盖率,得到代码覆盖率。Obtain the coverage rate of the unit test code relative to the development code of the submodule to be tested and the associated development code to obtain the code coverage rate.

可选的,所述拉取所述待测试子模块的开发代码,包括:Optionally, the pulling the development code of the submodule to be tested includes:

获取预先配置的、所述待测试子模块的开发代码对应的Git服务器地址;Obtain the pre-configured Git server address corresponding to the development code of the submodule to be tested;

从所述Git服务器地址拉取所述待测试子模块的开发代码到本地服务器。Pull the development code of the submodule to be tested from the Git server address to the local server.

本发明第二方面提出一种单元测试方法,应用于客户端,所述方法包括:A second aspect of the present invention provides a unit testing method, which is applied to a client, and the method includes:

接收针对多个子模块与父模块的依赖配置操作,生成依赖配置指令;Receive dependency configuration operations for multiple submodules and parent modules, and generate dependency configuration instructions;

将所述依赖配置指令发送给服务端,以使所述服务端建立所述多个子模块与所述父模块的依赖关系;sending the dependency configuration instruction to the server, so that the server establishes the dependencies between the multiple submodules and the parent module;

响应于针对待测试子模块的单元测试请求操作,生成测试请求,并将所述测试请求发送给服务端;所述待测试子模块为所述多个子模块中的至少一个子模块;In response to the unit test request operation for the submodule to be tested, a test request is generated, and the test request is sent to the server; the submodule to be tested is at least one submodule of the plurality of submodules;

接收服务端发送的代码覆盖率数据;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和关联开发代码的覆盖率;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码。Receive the code coverage data sent by the server; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code; the associated development code is one of the multiple submodules The development code that has a calling relationship with the submodule to be tested.

可选的,在响应于针对待测试子模块的单元测试请求操作,生成测试请求之前,还包括:Optionally, before generating the test request in response to the unit test request operation for the submodule to be tested, the method further includes:

响应于针对所述子模块的选择操作,确定待测试子模块。In response to the selection operation for the submodule, a submodule to be tested is determined.

可选的,在响应于针对所述子模块的选择操作,确定待测试子模块之前,还包括:Optionally, before determining the submodule to be tested in response to the selection operation for the submodule, it also includes:

接收针对所述多个子模块的测试服务配置操作;所述测试服务配置操作包括针对测试环境、代码类型、监听端口、开发代码对应的Git服务器地址的配置操作。A test service configuration operation for the multiple sub-modules is received; the test service configuration operation includes a configuration operation for the test environment, code type, listening port, and Git server address corresponding to the development code.

本发明第三方面提出一种服务端,所述服务端包括:A third aspect of the present invention provides a server, where the server includes:

依赖建立模块,用于响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立所述多个子模块与所述父模块的依赖关系;a dependency establishment module, used for establishing the dependency relationship between the multiple submodules and the parent module in response to the dependency configuration instructions sent by the client for multiple submodules and the parent module;

请求接收模块,用于接收所述客户端发送的、针对待测试子模块的单元测试请求;所述待测试子模块为所述多个子模块中的至少一个子模块;a request receiving module, configured to receive a unit test request sent by the client for the submodule to be tested; the submodule to be tested is at least one submodule of the plurality of submodules;

代码确定模块,用于响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码;a code determination module, configured to determine an associated development code according to the dependency relationship in response to the unit test request; the associated development code is a development code that has a calling relationship with the submodule to be tested among the plurality of submodules;

测试模块,用于对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率;A test module, configured to run unit tests on the submodule to be tested to obtain code coverage; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code ;

发送模块,用于将所述代码覆盖率发送给所述客户端。A sending module, configured to send the code coverage to the client.

可选的,所述测试模块具体用于:Optionally, the test module is specifically used for:

响应于所述单元测试请求,从所述多个子模块中确定与所述待测试子模块有调用关系的子模块,得到关联子模块;In response to the unit test request, determine a submodule having a calling relationship with the submodule to be tested from the plurality of submodules, and obtain an associated submodule;

从所述关联子模块中获取与所述待测试子模块有调用关系的开发代码,得到关联开发代码;Obtain the development code that has a calling relationship with the submodule to be tested from the associated submodule, and obtain the associated development code;

拉取所述待测试子模块的开发代码;Pull the development code of the submodule to be tested;

利用所述待测试子模块的单元测试代码,对所述待测试子模块的开发代码和所述关联开发代码运行单元测试;Using the unit test code of the submodule to be tested, run a unit test on the development code of the submodule to be tested and the associated development code;

获取所述单元测试代码相对于所述待测试子模块的开发代码、所述关联开发代码的覆盖率,得到代码覆盖率。Obtain the coverage rate of the unit test code relative to the development code of the submodule to be tested and the associated development code to obtain the code coverage rate.

可选的,所述测试模块具体用于:Optionally, the test module is specifically used for:

获取预先配置的、所述待测试子模块的开发代码对应的Git服务器地址;Obtain the pre-configured Git server address corresponding to the development code of the submodule to be tested;

从所述Git服务器地址拉取所述待测试子模块的开发代码到本地服务器。Pull the development code of the submodule to be tested from the Git server address to the local server.

本发明第四方面提出一种客户端,所述客户端包括:A fourth aspect of the present invention provides a client, where the client includes:

操作接收模块,用于接收针对多个子模块与父模块的依赖配置操作,生成依赖配置指令;The operation receiving module is used to receive dependency configuration operations for multiple sub-modules and parent modules, and generate dependency configuration instructions;

指令发送模块,用于将所述依赖配置指令发送给服务端,以使所述服务端建立所述多个子模块与所述父模块的依赖关系;an instruction sending module, configured to send the dependency configuration instruction to the server, so that the server establishes the dependencies between the multiple submodules and the parent module;

请求发送模块,用于响应于针对待测试子模块的单元测试请求操作,生成测试请求,并将所述测试请求发送给服务端;所述待测试子模块为所述多个子模块中的至少一个子模块;A request sending module, configured to generate a test request in response to a unit test request operation for the submodule to be tested, and send the test request to the server; the submodule to be tested is at least one of the multiple submodules submodule;

数据接收模块,用于接收服务端发送的代码覆盖率数据;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和关联开发代码的覆盖率;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码。A data receiving module for receiving code coverage data sent by the server; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code; the associated development code is The development code in the plurality of submodules that has a calling relationship with the submodule to be tested.

可选的,所述客户端还包括:Optionally, the client further includes:

子模块确定模块,用于响应于针对所述子模块的选择操作,确定待测试子模块。A submodule determination module, configured to determine a submodule to be tested in response to a selection operation for the submodule.

可选的,所述客户端还包括:Optionally, the client further includes:

配置操作接收模块,用于接收针对所述多个子模块的测试服务配置操作;所述测试服务配置操作包括针对测试环境、代码类型、监听端口、开发代码对应的Git服务器地址的配置操作。The configuration operation receiving module is configured to receive the test service configuration operation for the multiple submodules; the test service configuration operation includes the configuration operation for the test environment, code type, listening port, and Git server address corresponding to the development code.

本发明第五方面提出一种计算机可读存储介质,所述存储介质中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由处理器加载并执行以实现如第一方面和/或第二方面所述的单元测试方法。A fifth aspect of the present invention provides a computer-readable storage medium, the storage medium stores at least one instruction, at least one piece of program, code set or instruction set, the at least one instruction, the at least one piece of program, the code The set or instruction set is loaded and executed by the processor to implement the unit testing method as described in the first aspect and/or the second aspect.

根据本发明提供的具体实施例,本发明具有以下技术效果:According to the specific embodiments provided by the present invention, the present invention has the following technical effects:

本发明实施例提供的单元测试方法,响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立多个子模块与父模块的依赖关系;接收客户端发送的、针对待测试子模块的单元测试请求;待测试子模块为多个子模块中的至少一个子模块;响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码;对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率;将代码覆盖率发送给客户端。本方案中多个子模块与父模块建立了依赖关系,可以根据依赖关系确定父模块下的、与待测试子模块有调用关系的关联开发代码,进而得到的代码覆盖率为所有涉及到待测试子模块功能的源代码的覆盖情况,提高了代码覆盖率测试的准确度。The unit testing method provided by the embodiment of the present invention establishes the dependency relationship between multiple submodules and the parent module in response to the dependency configuration instruction sent by the client for multiple submodules and the parent module; The unit test request; the submodule to be tested is at least one submodule among the multiple submodules; in response to the unit test request, the associated development code is determined according to the dependency relationship; the associated development code is one of the multiple submodules A development code that has a calling relationship with the submodule to be tested; run a unit test on the submodule to be tested to obtain code coverage; the code coverage is the development code of the unit test code relative to the submodule to be tested and the coverage of the associated development code; send the code coverage to the client. In this solution, multiple submodules have established dependencies with the parent module, and the associated development code under the parent module that has a calling relationship with the submodule to be tested can be determined according to the dependency relationship, and the obtained code coverage is all related to the submodule to be tested. The coverage of the source code of the module function improves the accuracy of the code coverage test.

本发明的附加方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本发明的实践了解到。Additional aspects and advantages of the present invention will be set forth, in part, from the following description, and in part will be apparent from the following description, or may be learned by practice of the invention.

附图说明Description of drawings

为了更清楚地说明本发明的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单的介绍。显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还能够根据这些附图获得其它附图。In order to illustrate the technical solutions of the present invention more clearly, the following will briefly introduce the accompanying drawings that are required to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.

图1为本发明实施例提供的一种单元测试方法的步骤流程图;1 is a flow chart of steps of a unit testing method provided by an embodiment of the present invention;

图2为本发明实施例提供的另一种单元测试方法的步骤流程图;2 is a flowchart of steps of another unit testing method provided by an embodiment of the present invention;

图3为本发明实施例提供的一种服务端的结构框图;3 is a structural block diagram of a server according to an embodiment of the present invention;

图4为本发明实施例提供的一种客户端的结构框图。FIG. 4 is a structural block diagram of a client according to an embodiment of the present invention.

具体实施方式Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but 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 work fall within the protection scope of the present invention.

本说明书提供了如实施例或流程图所述的方法操作步骤,但基于常规或无创造性的劳动可以包括更多或者更少的操作步骤。在实际中的系统或服务器产品执行时,可以按照实施例或者附图所示的方法顺序执行或者并行执行(例如并行处理器或者多线程处理的环境)。The present specification provides method operation steps as described in the embodiments or flow charts, but more or less operation steps may be included based on routine or non-creative work. When an actual system or server product is executed, it can be executed sequentially or in parallel (for example, in a parallel processor or multi-threaded processing environment) according to the embodiments or the methods shown in the accompanying drawings.

图1为本发明实施例提供的一种单元测试方法的步骤流程图。该方法可以应用于服务端,包括如下步骤:FIG. 1 is a flowchart of steps of a unit testing method provided by an embodiment of the present invention. This method can be applied to the server, including the following steps:

步骤101、响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立所述多个子模块与所述父模块的依赖关系。Step 101: In response to a dependency configuration instruction sent by a client for multiple submodules and a parent module, establish a dependency relationship between the multiple submodules and the parent module.

在本发明实施例中,建立了代码覆盖率测试平台,在该平台的网页客户端中,可以输入父模块名称,并配置父模块下对应的多个子模块,通过相应控件生成依赖配置指令,由客户端发送给服务端。服务端接收到依赖配置指令后,建立多个子模块与父模块的依赖关系。In the embodiment of the present invention, a code coverage test platform is established. In the web client of the platform, the name of the parent module can be input, and a plurality of sub-modules corresponding to the parent module can be configured, and the dependency configuration instruction can be generated through the corresponding control. Client sends to server. After receiving the dependency configuration instruction, the server establishes dependencies between multiple submodules and the parent module.

步骤102、接收所述客户端发送的、针对待测试子模块的单元测试请求;所述待测试子模块为所述多个子模块中的至少一个子模块。Step 102: Receive a unit test request sent by the client for the sub-module to be tested; the sub-module to be tested is at least one sub-module of the multiple sub-modules.

待测试子模块是用户在客户端从多个子模块中选择的,在客户端选定待测试子模块后,点击生成单元测试报告,即可对服务端发送针对待测试子模块的单元测试请求。The submodule to be tested is selected by the user from multiple submodules on the client side. After the client selects the submodule to be tested, click Generate Unit Test Report to send a unit test request for the submodule to be tested to the server.

此处可以选择至少一个子模块或全部子模块组合进行单元测试,从而避免不能选择子模块使得全部测试运行,导致运行工作量大等问题,提高了测试效率,避免了不必要的计算资源浪费。Here, at least one sub-module or a combination of all sub-modules can be selected for unit testing, so as to avoid the problem of not being able to select sub-modules to run all tests, resulting in a large running workload, improving testing efficiency and avoiding unnecessary waste of computing resources.

步骤103、响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码。Step 103: In response to the unit test request, determine an associated development code according to the dependency relationship; the associated development code is a development code of the multiple submodules that has a calling relationship with the submodule to be tested.

服务端在接收到单元测试请求后,确定与待测试子模块对应的关联开发代码。关联开发代码为父模块下的多个子模块中与待测试子模块有调用关系的开发代码。After receiving the unit test request, the server determines the associated development code corresponding to the submodule to be tested. The associated development code is the development code in the multiple submodules under the parent module that has a calling relationship with the submodule to be tested.

多个子模块均与父模块有依赖关系,因此可以通过该依赖关系确定与待测试子模块的功能有关联的关联子模块,进而从关联子模块中确定关联开发代码。A plurality of submodules all have a dependency relationship with the parent module, so the associated submodule associated with the function of the submodule to be tested can be determined through the dependency relationship, and then the associated development code can be determined from the associated submodule.

例如,父模块为租车,子模块为登录、注册、下单、叫车、结算、支付、购买会员等模块,各个子模块均为父模块下面的功能模块。若待测试子模块为结算子模块,则与待测试子模块关联的有登录、下单、支付等子模块,从关联子模块中获取与结算子模块关联的开发代码,得到关联开发代码。For example, the parent module is car rental, and the sub-modules are modules such as login, registration, ordering, car-hailing, settlement, payment, and membership purchase. Each sub-module is a functional module under the parent module. If the sub-module to be tested is a settlement sub-module, the sub-modules associated with the sub-module to be tested include login, order placement, payment and other sub-modules, and the development code associated with the settlement sub-module is obtained from the associated sub-module to obtain the associated development code.

可选的,所述响应于所述单元测试请求,对所述待测试子模块运行单元测试,包括以下步骤A1-A5:Optionally, in response to the unit test request, running a unit test on the submodule to be tested includes the following steps A1-A5:

A1、响应于所述单元测试请求,从所述多个子模块中确定与所述待测试子模块有调用关系的子模块,得到关联子模块;A1, in response to the unit test request, determine a submodule that has a calling relationship with the submodule to be tested from the plurality of submodules, and obtain an associated submodule;

A2、从所述关联子模块中获取与所述待测试子模块有调用关系的开发代码,得到关联开发代码;A2, obtain the development code that has a calling relationship with the submodule to be tested from the associated submodule, and obtain the associated development code;

A3、拉取所述待测试子模块的开发代码;A3. Pull the development code of the submodule to be tested;

A4、利用所述待测试子模块的单元测试代码,对所述待测试子模块的开发代码和所述关联开发代码运行单元测试;A4, using the unit test code of the submodule to be tested, run the unit test on the development code of the submodule to be tested and the associated development code;

A5、获取所述单元测试代码相对于所述待测试子模块的开发代码、所述关联开发代码的覆盖率,得到代码覆盖率。A5. Obtain the coverage rate of the unit test code relative to the development code of the submodule to be tested and the associated development code to obtain the code coverage rate.

在步骤A1-A5中,代码覆盖率描述程序中源代码被测试的比例和程度,所得比例称为代码覆盖率。此处将单元测试代码对于待测试子模块的开发代码、关联开发代码的覆盖比例,作为代码覆盖率。In steps A1-A5, the code coverage describes the proportion and extent of the source code in the program being tested, and the obtained proportion is called the code coverage. Here, the coverage ratio of the unit test code to the development code of the submodule to be tested and the associated development code is taken as the code coverage ratio.

具体地,在测试运行结束后,可以通过执行JaCoCo插件获取单元测试的覆盖率数据。JaCoCo(Java Code Coverage,java代码覆盖率)是一个被广泛使用的java覆盖率测试工具,它利用ASM(字节码引擎)库,通过注入字节码的方式来修改和生成java字节码,从而记录程序的执行数据,它不会改变原有代码的行为。Specifically, after the test runs, the coverage data of the unit test can be obtained by executing the JaCoCo plug-in. JaCoCo (Java Code Coverage, java code coverage) is a widely used java coverage testing tool. It uses the ASM (bytecode engine) library to modify and generate java bytecodes by injecting bytecodes. Thereby recording the execution data of the program, it will not change the behavior of the original code.

可选的,所述拉取所述待测试子模块的开发代码,包括以下步骤A31-A32:Optionally, the pulling of the development code of the submodule to be tested includes the following steps A31-A32:

A31、获取预先配置的、所述待测试子模块的开发代码对应的Git服务器地址;A31. Obtain a pre-configured Git server address corresponding to the development code of the submodule to be tested;

A32、从所述Git服务器地址拉取所述待测试子模块的开发代码到本地服务器。A32. Pull the development code of the submodule to be tested from the Git server address to the local server.

在步骤A31-A32中,用户在客户端预先配置了待测试子模块的开发代码所对应的Git服务器地址,在运行测试时,首先从该地址拉取待测试子模块的开发代码到本地服务器,方可在本地服务器运行测试用例和开发代码。In steps A31-A32, the user pre-configures the Git server address corresponding to the development code of the submodule to be tested on the client, and when running the test, first pulls the development code of the submodule to be tested from the address to the local server, Only then can test cases and development code be run on the local server.

此外,测试代码也可以保管在Git服务器,同样可以从Git服务器地址拉取测试代码,以运行测试用例。In addition, the test code can also be stored on the Git server, and the test code can also be pulled from the Git server address to run the test case.

步骤104、对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率。Step 104: Run a unit test on the submodule to be tested to obtain a code coverage; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code.

单元测试是编写测试代码,用来检测特定的、明确的、细颗粒的功能。单元测试可以用来保证当前代码的正确性,用来保证代码修复、改进或重构以后的正确性。覆盖率是指代码的覆盖程度,常见的度量方式为语句覆盖,用来度量被测代码中每个可执行语句是否被执行到了,还包括分支覆盖,用来度量程序中每一个判定的分支是否都被测试到了,还包括条件覆盖,度量判定中的每个子表达式结果是否被测试到了,还包括函数覆盖,用来度量定义的函数有多少被调用了。Unit testing is writing test code to detect specific, unambiguous, fine-grained functionality. Unit testing can be used to ensure the correctness of the current code, and to ensure the correctness of the code in the future when it is fixed, improved or refactored. Coverage refers to the degree of code coverage. A common measure is statement coverage, which is used to measure whether each executable statement in the code under test has been executed, and branch coverage, which is used to measure whether each branch of the program is determined. have been tested, as well as condition coverage, which measures whether each subexpression result in the decision was tested, and function coverage, which measures how many of the defined functions were called.

本发明实施例中的代码覆盖率可以表示以上几种覆盖率中的至少一种。The code coverage in this embodiment of the present invention may represent at least one of the above coverages.

在运行单元测试时,不仅对待测试子模块的开发代码进行测试,也对关联开发代码进行测试,这样得到的代码覆盖率为单元测试代码相对于待测试子模块的开发代码和关联开发代码的覆盖率。When running the unit test, not only test the development code of the submodule to be tested, but also test the associated development code. The code coverage obtained in this way is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code. Rate.

可选的,对所述待测试子模块的开发代码和所述关联开发代码运行单元测试,包括:Optionally, run unit tests on the development code of the submodule to be tested and the associated development code, including:

在所述本地服务器中通过moven对所述待测试子模块的开发代码和所述关联开发代码执行测试用例。A test case is executed on the development code of the submodule to be tested and the associated development code in the local server through moven.

具体地,采用测试运行器maven-surefire-plugin插件来运行测试用例,在默认情况下,maven-surefire-plugin的test目标会自动执行测试源码路径下所有符合一组命名模式的测试类。Specifically, the test runner maven-surefire-plugin is used to run test cases. By default, the test target of maven-surefire-plugin will automatically execute all test classes in the test source path that conform to a set of naming patterns.

步骤105、将所述代码覆盖率发送给所述客户端。Step 105: Send the code coverage to the client.

Maven通过cobertura-maven-plugin与开源测试覆盖率测试工具Cobertura集成,可以使用简单的命令为Maven项目生成代码覆盖率报告。Maven integrates with the open source test coverage testing tool Cobertura through the cobertura-maven-plugin, which can generate code coverage reports for Maven projects with simple commands.

在本发明实施例中,当用户点击客户端相应选项运行单元测试后,服务端接收到测试指令,自动执行预先编写的测试用例,并自动生成代码覆盖率报告。In the embodiment of the present invention, after the user clicks the corresponding option of the client to run the unit test, the server receives the test instruction, automatically executes the pre-written test case, and automatically generates a code coverage report.

服务端将代码覆盖率报告发送给客户端,以供用户查看和使用。The server sends the code coverage report to the client for the user to view and use.

此外,可以在测试代码中自动编写邮件发送类,这样可自动发送邮件给对应人员直观查看代码覆盖率报告。In addition, the email sending class can be automatically written in the test code, so that the email can be automatically sent to the corresponding personnel to visually check the code coverage report.

在本发明实施例中,单元测试多模块覆盖率测试结合开发单元测试代码和待测试模块开发代码与关联开发代码对比,减少了人工校验步骤,去除冗余的工作,提升测试工作效率,实现单元测试覆盖率的比对;并且,本发明可以有效统计单元测试中功能代码的行覆盖率,代码方法中的函数覆盖率,代码分支覆盖率和代码语句覆盖率,来量化说明测试的充分度。此外,通过在各业务线测试中运行单元测试代码,在详情报告中可以有效查看测试涉及到代码覆盖率是否覆盖,核心场景是否覆盖,用来保证当前代码的正确性,代码修复、改进或重构以后的正确性。In the embodiment of the present invention, the unit test multi-module coverage test is combined with the development unit test code and the development code of the module to be tested is compared with the associated development code, which reduces manual verification steps, removes redundant work, improves test work efficiency, and realizes Comparison of unit test coverage; and, the present invention can effectively count the line coverage of functional codes in unit tests, the function coverage in code methods, the code branch coverage and the code statement coverage to quantify the adequacy of the test. . In addition, by running the unit test code in each line of business test, in the detailed report, you can effectively check whether the code coverage involved in the test is covered and whether the core scenario is covered, which is used to ensure the correctness of the current code, code repair, improvement or re-engineering. correctness in the future.

综上,本发明实施例提供的单元测试方法,响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立多个子模块与父模块的依赖关系;接收客户端发送的、针对待测试子模块的单元测试请求;待测试子模块为多个子模块中的至少一个子模块;响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码;对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率;将代码覆盖率发送给客户端。本方案中多个子模块与父模块建立了依赖关系,可以根据依赖关系确定父模块下的、与待测试子模块有调用关系的关联开发代码,进而得到的代码覆盖率为所有涉及到待测试子模块功能的源代码的覆盖情况,提高了代码覆盖率测试的准确度。To sum up, the unit testing method provided by the embodiment of the present invention establishes the dependency relationship between multiple submodules and the parent module in response to the dependency configuration instructions sent by the client for multiple submodules and the parent module; The unit test request of the test submodule; the submodule to be tested is at least one submodule of the multiple submodules; in response to the unit test request, the associated development code is determined according to the dependency relationship; the associated development code is the multiple submodules. The development code in the submodules that has a calling relationship with the submodule to be tested; run unit tests on the submodule to be tested to obtain code coverage; the code coverage is the unit test code relative to the submodule to be tested The development code and the coverage of the associated development code; send the code coverage to the client. In this solution, multiple submodules have established dependencies with the parent module, and the associated development code under the parent module that has a calling relationship with the submodule to be tested can be determined according to the dependency relationship, and the obtained code coverage is all related to the submodule to be tested. The coverage of the source code of the module function improves the accuracy of the code coverage test.

图2为本发明实施例提供的一种单元测试方法的步骤流程图。该方法可以应用于客户端,包括如下步骤:FIG. 2 is a flowchart of steps of a unit testing method provided by an embodiment of the present invention. This method can be applied to the client and includes the following steps:

步骤201、接收针对多个子模块与父模块的依赖配置操作,生成依赖配置指令。Step 201: Receive dependency configuration operations for multiple submodules and parent modules, and generate dependency configuration instructions.

在代码覆盖率测试平台中的客户端中,可以输入父模块名称,并配置父模块下对应的多个子模块,通过相应控件生成依赖配置指令,由客户端发送给服务端。In the client in the code coverage test platform, you can enter the name of the parent module, and configure multiple submodules corresponding to the parent module, and generate dependency configuration instructions through corresponding controls, which are sent from the client to the server.

步骤202、将所述依赖配置指令发送给服务端,以使所述服务端建立所述多个子模块与所述父模块的依赖关系。Step 202: Send the dependency configuration instruction to the server, so that the server establishes the dependencies between the multiple submodules and the parent module.

服务端接收到依赖配置指令后,建立多个子模块与父模块的依赖关系。具体地,在开发代码对应的父pom文件和子pom文件下配置覆盖率依赖。After receiving the dependency configuration instruction, the server establishes dependencies between multiple submodules and the parent module. Specifically, configure coverage dependencies under the parent pom file and child pom file corresponding to the development code.

步骤203、响应于针对待测试子模块的单元测试请求操作,生成测试请求,并将所述测试请求发送给服务端;所述待测试子模块为所述多个子模块中的至少一个子模块。Step 203 , in response to the unit test request operation for the submodule to be tested, generate a test request, and send the test request to the server; the submodule to be tested is at least one submodule of the plurality of submodules.

待测试子模块是用户在客户端从多个子模块中选择的,在客户端选定待测试子模块后,点击生成单元测试报告选项,即可对服务端发送针对待测试子模块的单元测试请求。The submodule to be tested is selected by the user from multiple submodules on the client side. After the client selects the submodule to be tested, click the Generate Unit Test Report option to send a unit test request for the submodule to be tested to the server. .

步骤204、接收服务端发送的代码覆盖率数据;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和关联开发代码的覆盖率;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码。Step 204: Receive the code coverage data sent by the server; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code; the associated development code is the multiple The development code in each submodule that has a calling relationship with the submodule to be tested.

在本发明实施例中,当用户点击客户端相应选项运行单元测试后,服务端接收到测试指令,自动执行预先编写的测试用例,并自动生成代码覆盖率报告。In the embodiment of the present invention, after the user clicks the corresponding option of the client to run the unit test, the server receives the test instruction, automatically executes the pre-written test case, and automatically generates a code coverage report.

服务端将代码覆盖率报告发送给客户端,以供用户查看和使用。The server sends the code coverage report to the client for the user to view and use.

通过报告不仅能直观地查看子模块各自的单元测试覆盖率数据,还能查到全部子模块的单元测试总覆盖率数据。同时,单元测试覆盖率数据可以作为冒烟测试提测的准入门槛,集成在自动化构建平台,形成自动化的质量管控体系。从报告的详细数据中也可以针对未覆盖代码进行查漏补缺,从而实现测试场景的充分覆盖和代码覆盖率的提升。统计和查看多模块下代码的单元测试覆盖率数据是整个发明方案的核心价值体现。Through the report, you can not only visually view the unit test coverage data of each submodule, but also check the total unit test coverage data of all submodules. At the same time, the unit test coverage data can be used as the entry threshold for smoke test testing, integrated in the automated construction platform to form an automated quality control system. From the detailed data of the report, we can also check and fill in the gaps for the uncovered code, so as to achieve the full coverage of the test scenario and the improvement of the code coverage. Counting and viewing unit test coverage data of code under multiple modules is the core value embodiment of the entire inventive solution.

首先,直观查看多模块下单元测试覆盖代码率。通过集成统计报告直观的看到开发编写的单元测试代码和开发功能代码是否完全覆盖,是否有遗漏点,从而有效的提高代码测试覆盖率。First, visually check the unit test coverage code rate under multiple modules. Through the integrated statistical report, you can intuitively see whether the unit test code written by the development and the development function code are completely covered, and whether there are any omissions, thereby effectively improving the code test coverage rate.

其次,直观有效查看单元测试代码与对应的接口的开发代码是否完全覆盖。通过多模块代码覆盖率实现单元测试代码和开发代码覆盖范围进行对比,覆盖全业务线流程,有效代替冒烟测试中的手工测试,提高测试效率,提高测试质量,从而直观看业务遗漏代码,进而保证产品质量。Secondly, visually and effectively check whether the unit test code and the development code of the corresponding interface are completely covered. Through multi-module code coverage, the coverage of unit test code and development code can be compared, covering the entire business line process, effectively replacing manual testing in smoke testing, improving test efficiency and improving test quality, so as to visually see the missing code in the business, and then Guarantee product quality.

再次,直观有效查看单元测试代码与新增代码是否完全覆盖。通过单元测试多模块覆盖代码率实现单元测试代码和开发新增代码覆盖范围进行对比,覆盖开发新增代码对比,避免测试过程中有新增代码遗漏。Again, intuitively and effectively check whether the unit test code and the new code are completely covered. Through the unit test multi-module coverage code rate, the unit test code can be compared with the new code coverage of the development, and the comparison of the new code in the coverage development can avoid the omission of the new code in the testing process.

可选的,在响应于针对待测试子模块的单元测试请求操作,生成测试请求之前,还包括:Optionally, before generating the test request in response to the unit test request operation for the submodule to be tested, the method further includes:

响应于针对所述子模块的选择操作,确定待测试子模块。In response to the selection operation for the submodule, a submodule to be tested is determined.

在本发明实施例中,可以在客户端页面中选择至少一个子模块或全部子模块组合作为待测试子模块,从而避免不能选择子模块使得全部测试运行,导致运行工作量大等问题,提高了测试效率,避免了不必要的计算资源浪费。In the embodiment of the present invention, at least one sub-module or a combination of all sub-modules can be selected as the sub-module to be tested on the client page, so as to avoid problems such as the inability to select sub-modules to make all tests run, resulting in a large running workload, etc. Test efficiency and avoid unnecessary waste of computing resources.

可选的,在响应于针对所述子模块的选择操作,确定待测试子模块之前,还包括:Optionally, before determining the submodule to be tested in response to the selection operation for the submodule, it also includes:

接收针对所述多个子模块的测试服务配置操作;所述测试服务配置操作包括针对测试环境、代码类型、监听端口、开发代码对应的Git服务器地址的配置操作。A test service configuration operation for the multiple sub-modules is received; the test service configuration operation includes a configuration operation for the test environment, code type, listening port, and Git server address corresponding to the development code.

在本发明实施例中,可以在客户端页面中对每个子模块的测试服务进行配置操作,包括对测试环境、代码类型、监听端口、开发代码对应的Git服务器地址的配置操作。In this embodiment of the present invention, a configuration operation can be performed on the test service of each submodule on the client page, including configuration operations on the test environment, code type, listening port, and Git server address corresponding to the development code.

具体地,测试环境是指为了完成软件测试工作所必需的计算机硬件、软件、网络设备、历史数据的总称;代码类型是指开发代码的类型;监听端口是指开发服务所部署的服务器对应的端口。Specifically, the test environment refers to the general term for computer hardware, software, network equipment, and historical data necessary to complete the software testing work; the code type refers to the type of development code; the listening port refers to the port corresponding to the server deployed by the development service .

综上,在本发明实施例中,接收针对多个子模块与父模块的依赖配置操作,生成依赖配置指令;将依赖配置指令发送给服务端,以使服务端建立多个子模块与父模块的依赖关系;响应于针对待测试子模块的单元测试请求操作,生成测试请求,并将测试请求发送给服务端;待测试子模块为多个子模块中的至少一个子模块;接收服务端发送的代码覆盖率数据;代码覆盖率为单元测试代码相对于待测试子模块的开发代码和关联开发代码的覆盖率;关联开发代码为多个子模块中与待测试子模块有调用关系的开发代码。本方案中多个子模块与父模块建立了依赖关系,可以根据依赖关系确定父模块下的、与待测试子模块有调用关系的关联开发代码,进而得到的代码覆盖率为所有涉及到待测试子模块功能的源代码的覆盖情况,提高了代码覆盖率测试的准确度。To sum up, in this embodiment of the present invention, a dependency configuration operation for multiple submodules and a parent module is received, and a dependency configuration instruction is generated; the dependency configuration instruction is sent to the server, so that the server establishes dependencies between multiple submodules and the parent module. relationship; in response to the unit test request operation for the submodule to be tested, generate a test request, and send the test request to the server; the submodule to be tested is at least one submodule among multiple submodules; receive the code coverage sent by the server The code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code; the associated development code is the development code of multiple submodules that has a calling relationship with the submodule to be tested. In this solution, multiple submodules have established dependencies with the parent module, and the associated development code under the parent module that has a calling relationship with the submodule to be tested can be determined according to the dependency relationship, and the obtained code coverage is all related to the submodule to be tested. The coverage of the source code of the module function improves the accuracy of the code coverage test.

图3为本发明实施例提供的一种服务端的结构框图。FIG. 3 is a structural block diagram of a server according to an embodiment of the present invention.

该服务端300包括:The server 300 includes:

依赖建立模块301,用于响应于客户端发送的针对多个子模块与父模块的依赖配置指令,建立所述多个子模块与所述父模块的依赖关系;A dependency establishment module 301, configured to establish a dependency relationship between the multiple submodules and the parent module in response to the dependency configuration instructions sent by the client for multiple submodules and the parent module;

请求接收模块302,用于接收所述客户端发送的、针对待测试子模块的单元测试请求;所述待测试子模块为所述多个子模块中的至少一个子模块;A request receiving module 302, configured to receive a unit test request sent by the client for the submodule to be tested; the submodule to be tested is at least one submodule of the multiple submodules;

代码确定模块303,用于响应于所述单元测试请求,根据所述依赖关系确定关联开发代码;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码;A code determination module 303, configured to determine the associated development code according to the dependency relationship in response to the unit test request; the associated development code is the development code that has a calling relationship with the submodule to be tested among the multiple submodules ;

测试模块304,用于对所述待测试子模块运行单元测试,得到代码覆盖率;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和所述关联开发代码的覆盖率;A testing module 304, configured to run a unit test on the submodule to be tested to obtain code coverage; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code Rate;

发送模块305,用于将所述代码覆盖率发送给所述客户端。A sending module 305, configured to send the code coverage to the client.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above may refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

图4为本发明实施例提供的一种客户端的结构框图。FIG. 4 is a structural block diagram of a client according to an embodiment of the present invention.

该客户端400包括:The client 400 includes:

操作接收模块401,用于接收针对多个子模块与父模块的依赖配置操作,生成依赖配置指令;The operation receiving module 401 is used for receiving dependency configuration operations for multiple submodules and parent modules, and generating dependency configuration instructions;

指令发送模块402,用于将所述依赖配置指令发送给服务端,以使所述服务端建立所述多个子模块与所述父模块的依赖关系;An instruction sending module 402, configured to send the dependency configuration instruction to the server, so that the server establishes the dependency between the multiple submodules and the parent module;

请求发送模块403,用于响应于针对待测试子模块的单元测试请求操作,生成测试请求,并将所述测试请求发送给服务端;所述待测试子模块为所述多个子模块中的至少一个子模块;The request sending module 403 is configured to generate a test request in response to a unit test request operation for the submodule to be tested, and send the test request to the server; the submodule to be tested is at least one of the multiple submodules a submodule;

数据接收模块404,用于接收服务端发送的代码覆盖率数据;所述代码覆盖率为单元测试代码相对于所述待测试子模块的开发代码和关联开发代码的覆盖率;所述关联开发代码为所述多个子模块中与所述待测试子模块有调用关系的开发代码。A data receiving module 404, configured to receive code coverage data sent by the server; the code coverage is the coverage of the unit test code relative to the development code of the submodule to be tested and the associated development code; the associated development code Develop code that has a calling relationship with the sub-module to be tested among the multiple sub-modules.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above may refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

在本发明提供的又一实施例中,还提供了一种设备,所述设备包括处理器和存储器,所述存储器种存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由所述处理器加载并执行以实现本发明实施例中所述的单元测试方法。In another embodiment provided by the present invention, there is also provided a device, the device includes a processor and a memory, the memory stores at least one instruction, at least a piece of program, a code set or an instruction set, the at least one One instruction, the at least one piece of program, the code set or the instruction set are loaded and executed by the processor to implement the unit testing method described in the embodiments of the present invention.

在本发明提供的又一实施例中,还提供了一种计算机可读存储介质,所述存储介质中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由处理器加载并执行以实现本发明实施例中所述的单元测试方法。In yet another embodiment provided by the present invention, a computer-readable storage medium is also provided, wherein the storage medium stores at least one instruction, at least one piece of program, code set or instruction set, the at least one instruction, all the The at least one piece of program, the code set or the instruction set is loaded and executed by the processor to implement the unit testing method described in the embodiments of the present invention.

在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk(SSD))等。In the above-mentioned embodiments, it may be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented in software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer may be a general purpose computer, special purpose computer, computer network, or other programmable device. The computer instructions may be stored in or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be downloaded from a website site, computer, server or data center Transmission to another website site, computer, server, or data center is by wire (eg, coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (eg, infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes an integration of one or more available media. The usable media may be magnetic media (eg, floppy disks, hard disks, magnetic tapes), optical media (eg, DVD), or semiconductor media (eg, Solid State Disk (SSD)), among others.

需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that, in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any relationship between these entities or operations. any such actual relationship or sequence exists. Moreover, the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, article or device that includes a list of elements includes not only those elements, but also includes not explicitly listed or other elements inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.

本说明书中的各个实施例均采用相关的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this specification is described in a related manner, and the same and similar parts between the various embodiments may be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for related parts, please refer to the partial descriptions of the method embodiments.

以上所述仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内所作的任何修改、等同替换、改进等,均包含在本发明的保护范围内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (13)

1. A unit testing method is applied to a server side, and the method comprises the following steps:
responding to a dependency configuration instruction which is sent by a client and aims at a plurality of sub-modules and a parent module, and establishing the dependency relationship between the plurality of sub-modules and the parent module;
receiving a unit test request aiming at a sub-module to be tested, which is sent by the client; the sub-module to be tested is at least one sub-module in the plurality of sub-modules;
responding to the unit test request, and determining an associated development code according to the dependency relationship; the associated development code is a development code which has a calling relationship with the sub-module to be tested in the plurality of sub-modules;
testing the sub-module to be tested operation unit to obtain code coverage rate; the code coverage rate is the coverage rate of the unit test code relative to the development code and the associated development code of the sub-module to be tested;
and sending the code coverage rate to the client.
2. The method of claim 1, wherein said running unit tests on said sub-modules under test in response to said unit test requests comprises:
responding to the unit test request, determining a sub-module having a calling relationship with the sub-module to be tested from the plurality of sub-modules, and obtaining an associated sub-module;
acquiring a development code having a calling relationship with the sub-module to be tested from the association sub-module to obtain an association development code;
pulling the development code of the sub-module to be tested;
utilizing the unit test code of the sub-module to be tested to run a unit test on the development code of the sub-module to be tested and the associated development code;
and acquiring the coverage rate of the unit test code relative to the development code of the sub-module to be tested and the associated development code to obtain the code coverage rate.
3. The method of claim 2, wherein pulling development code for the sub-module under test comprises:
acquiring a preset Git server address corresponding to the development code of the sub-module to be tested;
and pulling the development code of the sub-module to be tested from the Git server address to a local server.
4. A unit testing method is applied to a client side, and comprises the following steps:
receiving a dependent configuration operation aiming at a plurality of sub-modules and a parent module, and generating a dependent configuration instruction;
sending the dependency configuration instruction to a server so that the server establishes a dependency relationship between the plurality of sub-modules and the parent module;
responding to unit test request operation aiming at the sub-modules to be tested, generating a test request, and sending the test request to a server; the sub-module to be tested is at least one sub-module in the plurality of sub-modules;
receiving code coverage rate data sent by a server; the code coverage rate is the coverage rate of the unit test code relative to the development code and the associated development code of the sub-module to be tested; the associated development code is a development code which has a calling relationship with the sub-module to be tested in the plurality of sub-modules.
5. The method of claim 4, further comprising, prior to generating a test request in response to a unit test request operation for a sub-module under test:
and determining the sub-module to be tested in response to the selection operation aiming at the sub-module.
6. The method of claim 5, further comprising, prior to determining the sub-module to be tested in response to the selection operation for the sub-module:
receiving test service configuration operations for the plurality of sub-modules; the test service configuration operation comprises configuration operation aiming at test environment, code type, monitoring port and Git server address corresponding to development code.
7. A server, characterized in that the server comprises:
the dependency establishing module is used for responding to a dependency configuration instruction which is sent by a client and aims at a plurality of sub-modules and a parent module, and establishing the dependency relationship between the plurality of sub-modules and the parent module;
the request receiving module is used for receiving a unit test request aiming at the sub-module to be tested, which is sent by the client; the sub-module to be tested is at least one sub-module in the plurality of sub-modules;
the code determining module is used for responding to the unit test request and determining the associated development code according to the dependency relationship; the associated development code is a development code which has a calling relationship with the sub-module to be tested in the plurality of sub-modules;
the testing module is used for testing the sub-module to be tested to obtain the code coverage rate; the code coverage rate is the coverage rate of the unit test code relative to the development code and the associated development code of the sub-module to be tested;
and the sending module is used for sending the code coverage rate to the client.
8. The server-side of claim 7, wherein the testing module is specifically configured to:
responding to the unit test request, determining a sub-module having a calling relationship with the sub-module to be tested from the plurality of sub-modules, and obtaining an associated sub-module;
acquiring a development code having a calling relationship with the sub-module to be tested from the association sub-module to obtain an association development code;
pulling the development code of the sub-module to be tested;
utilizing the unit test code of the sub-module to be tested to run a unit test on the development code of the sub-module to be tested and the associated development code;
and acquiring the coverage rate of the unit test code relative to the development code of the sub-module to be tested and the associated development code to obtain the code coverage rate.
9. The server-side of claim 8, wherein the testing module is specifically configured to:
acquiring a preset Git server address corresponding to the development code of the sub-module to be tested;
and pulling the development code of the sub-module to be tested from the Git server address to a local server.
10. A client, the client comprising:
the operation receiving module is used for receiving the dependent configuration operation aiming at the plurality of sub-modules and the parent module and generating a dependent configuration instruction;
the instruction sending module is used for sending the dependency configuration instruction to a server so that the server establishes the dependency relationship between the plurality of sub-modules and the parent module;
the request sending module is used for responding to unit test request operation aiming at the sub-modules to be tested, generating a test request and sending the test request to the server; the sub-module to be tested is at least one sub-module in the plurality of sub-modules;
the data receiving module is used for receiving the code coverage rate data sent by the server; the code coverage rate is the coverage rate of the unit test code relative to the development code and the associated development code of the sub-module to be tested; the associated development code is a development code which has a calling relationship with the sub-module to be tested in the plurality of sub-modules.
11. The client of claim 10, further comprising:
a submodule determination module for determining a submodule to be tested in response to a selection operation for the submodule.
12. The client of claim 11, further comprising:
a configuration operation receiving module for receiving test service configuration operations for the plurality of sub-modules; the test service configuration operation comprises configuration operation aiming at test environment, code type, monitoring port and Git server address corresponding to development code.
13. A computer readable storage medium having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by a processor to implement the unit testing method of any of claims 1-6.
CN202111656660.1A 2021-12-30 2021-12-30 Unit testing method, server, client and storage medium Pending CN114416537A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111656660.1A CN114416537A (en) 2021-12-30 2021-12-30 Unit testing method, server, client and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111656660.1A CN114416537A (en) 2021-12-30 2021-12-30 Unit testing method, server, client and storage medium

Publications (1)

Publication Number Publication Date
CN114416537A true CN114416537A (en) 2022-04-29

Family

ID=81268799

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111656660.1A Pending CN114416537A (en) 2021-12-30 2021-12-30 Unit testing method, server, client and storage medium

Country Status (1)

Country Link
CN (1) CN114416537A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115145819A (en) * 2022-07-14 2022-10-04 中国银行股份有限公司 Unit testing method and related device for bank system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109684226A (en) * 2018-12-29 2019-04-26 携程计算机技术(上海)有限公司 Java code coverage rate statistical system
CN110008115A (en) * 2019-02-27 2019-07-12 北京三快在线科技有限公司 Code coverage statistical method, device, electronic equipment and readable storage medium storing program for executing
CN112463634A (en) * 2020-12-11 2021-03-09 中国人民银行清算总中心 Software testing method and device under micro-service architecture
CN112579475A (en) * 2020-12-31 2021-03-30 平安银行股份有限公司 Code testing method, device, equipment and readable storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109684226A (en) * 2018-12-29 2019-04-26 携程计算机技术(上海)有限公司 Java code coverage rate statistical system
CN110008115A (en) * 2019-02-27 2019-07-12 北京三快在线科技有限公司 Code coverage statistical method, device, electronic equipment and readable storage medium storing program for executing
CN112463634A (en) * 2020-12-11 2021-03-09 中国人民银行清算总中心 Software testing method and device under micro-service architecture
CN112579475A (en) * 2020-12-31 2021-03-30 平安银行股份有限公司 Code testing method, device, equipment and readable storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
MIYAOW: "maven多模块使用,父模块(modules使用,package为pom),子模块(parent使用)", pages 1 - 5, Retrieved from the Internet <URL:《https://blog.csdn.net/fjnpysh/article/details/71638341》> *
SOMMER_XIA: "Cobertura 统计多模块maven项目测试覆盖率_cobertura 多模块", Retrieved from the Internet <URL:《https://blog.csdn.net/shymi1991/article/details/52849947》> *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115145819A (en) * 2022-07-14 2022-10-04 中国银行股份有限公司 Unit testing method and related device for bank system

Similar Documents

Publication Publication Date Title
US11080121B2 (en) Generating runbooks for problem events
CN110147317B (en) Code testing method and device, electronic device and storage medium
US9465725B2 (en) Software defect reporting
US8396815B2 (en) Adaptive business process automation
US8640096B2 (en) Configuration of componentized software applications
US8677194B2 (en) Method and system for site configurable error reporting
US9497096B2 (en) Dynamic control over tracing of messages received by a message broker
CN103984626B (en) A kind of method and device for generating test case script
US20170024307A1 (en) Debugging in a Production Environment
CN111309621A (en) Interface test method, system, equipment and storage medium
CN111666217A (en) Method and apparatus for testing code
CN106970865B (en) Monitoring and management of software as a service in a microcloud environment
CN113127358B (en) A testing method, device, electronic equipment and medium
CN110806967B (en) Unit testing method and unit testing device
CN112699011A (en) Method and device for counting incremental code coverage rate, electronic equipment and storage medium
CN113392002A (en) Test system construction method, device, equipment and storage medium
CN113254340B (en) A method and device for generating test cases
CN114416537A (en) Unit testing method, server, client and storage medium
CN112965910B (en) Automatic regression testing method and device, electronic equipment and storage medium
CN112559338B (en) Application verification methods, devices, equipment and storage media
CN112445473A (en) Client layout method and device, storage medium and electronic equipment
US11138094B2 (en) Creation of minimal working examples and environments for troubleshooting code issues
CN110162982B (en) Method and device for detecting illegal rights, storage medium and electronic equipment
CN112732320B (en) Continuous integration method, device, electronic device and medium for software development process
CN114942887A (en) Program safety testing method, device, equipment and medium

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