CN114741296A - Unit testing method, unit testing device, electronic equipment and storage medium - Google Patents
Unit testing method, unit testing device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114741296A CN114741296A CN202210376644.5A CN202210376644A CN114741296A CN 114741296 A CN114741296 A CN 114741296A CN 202210376644 A CN202210376644 A CN 202210376644A CN 114741296 A CN114741296 A CN 114741296A
- Authority
- CN
- China
- Prior art keywords
- test
- test case
- fatjar
- code
- unit testing
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/368—Test management for test version control, e.g. updating test cases to a new software version
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3692—Test management for test results analysis
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)
- Stored Programmes (AREA)
Abstract
Description
技术领域technical field
本文涉及但不限于测试领域。This article covers but is not limited to the testing field.
背景技术Background technique
基础组件一般逻辑都非常复杂,需要进行非常多的测试来尽可能的保证质量。The general logic of basic components is very complex and requires a lot of testing to ensure the quality as much as possible.
在现有技术中,开发测试人员主要使用有以下几种方式进行单元测试:In the prior art, development testers mainly use the following methods for unit testing:
(1)基于Junit编写测试用例(1) Write test cases based on Junit
Junit本身非常强大,并且和spring完美集成,是java领域写单元测试的首选。但是它只能在代码内手动执行,并且无法很好的管理。因为一般都是写在当前项目内的。所以当开发新的功能,拉取新的代码分支的时候,测试用例一般都会重新编写。因此之前版本的测试用例可能很久不会维护而不可用。另外新的项目分支一般也只测试当前分支的特性,导致整体测试场景不全,也很难保证测试质量。本身定位的时候就是功能测试,所以并没有考虑过管理以及自动化方面。尤其是随着版本的迭代,功能越来越多,代码复杂度越来越高,单元测试的管理更显得尤为重要。Junit itself is very powerful and perfectly integrated with spring, it is the first choice for writing unit tests in the java field. But it can only be done manually within the code and is not well managed. Because it is generally written in the current project. So when new features are developed and new code branches are pulled, test cases are usually rewritten. Therefore, the test cases of the previous version may not be maintained and unavailable for a long time. In addition, new project branches generally only test the features of the current branch, resulting in incomplete test scenarios and difficulty in ensuring test quality. When positioning itself, it is functional testing, so management and automation are not considered. Especially with the iteration of the version, more and more functions, the code complexity is getting higher and higher, the management of unit tests is even more important.
(2)通过代码自己编写单元测试(2) Write unit tests by yourself through code
通过代码自己构建测试用例,更加灵活,比较适合一些简单的场景测试。但是对于复杂的场景测试,尤其是依赖第三方组件的时候就会异常困难,几乎不可行。所以适用场景非常有限,也就不具备管理以及自动化等的条件。只能用于日常开发过程中的一些简单功能的校验。Building test cases by yourself through code is more flexible and more suitable for some simple scenario tests. But for complex scenario testing, especially when relying on third-party components, it is extremely difficult and almost impossible. Therefore, the applicable scenarios are very limited, and there are no conditions for management and automation. It can only be used for the verification of some simple functions in the daily development process.
(3)Postman(3) Postman
postman是一款模拟http调用的工具,本身也具备存储API调用的能力,而且此方面功能非常强大,另外它可以存储之前执行过的API及其参数。所以具备一定的管理能力,对于一些前后端调用的功能可以通过postman来进行测试。但是它的使用场景对于基础组件来说相对有限,只能用于前端交互领域。Postman is a tool for simulating http calls. It also has the ability to store API calls, and this aspect is very powerful. In addition, it can store previously executed APIs and their parameters. Therefore, it has certain management capabilities, and some functions called by the front and back ends can be tested by postman. However, its usage scenarios are relatively limited for basic components and can only be used in the field of front-end interaction.
基础组件的版本迭代非常快,所以现有技术一直不能解决以下几个比较严重的问题:The version iteration of basic components is very fast, so the existing technology has not been able to solve the following serious problems:
1.单元测试用例数量多1. A large number of unit test cases
2.单元测试用例维护困难2. Unit test case maintenance is difficult
3.不同版本之间单元测试用例不同3. Unit test cases are different between different versions
4.基础组件回归测试困难4. Regression testing of basic components is difficult
5.单元测试用例很难自动化5. Unit test cases are hard to automate
基础组件的质量保障一直是个艰巨的任务。很多时候新版本发布了会发现之前修复的问题又出现了,或者出现了新的问题。甚至之前编写的测试用例已经因为版本变更而无法运行,历史无法查证。现有技术对于一些UI端,以及一些过程中行为或者状态相关的测试支持也不够充分。另外因为要编译成FatJar,所以加载过程会比较长。因此急需一种新的测试方法。Quality assurance of basic components has always been a difficult task. Many times when a new version is released, it is found that the previously fixed problems have reappeared, or new problems have appeared. Even the previously written test cases have been unable to run due to version changes, and the history cannot be verified. The existing technology is also insufficient for some UI terminals and some in-process behavior or state-related testing support. In addition, because it needs to be compiled into FatJar, the loading process will be longer. Therefore, a new test method is urgently needed.
发明内容SUMMARY OF THE INVENTION
下文呈现各种示例性技术方案的概述。在以下概述中可以进行一些简化和省略,其意在突出并介绍各种示例性技术方案的一些方面,但不限制本发明的范围。将在后续部分呈现足以允许本领域的普通技术人员产生并使用本发明概念的示例性技术方案的详细描述。An overview of various exemplary technical solutions is presented below. Some simplifications and omissions may be made in the following summary, which is intended to highlight and introduce some aspects of various exemplary solutions, but not to limit the scope of the invention. A detailed description of exemplary solutions sufficient to allow one of ordinary skill in the art to make and use the inventive concepts will be presented in subsequent sections.
为解决上述技术问题,本发明的技术方案提供一种单元测试方法,包括:为开发用例编写对应的测试用例代码并存储;拉取测试用例代码,编译成FatJar;通过FatJar的反射的方式执行测试用例;存储执行结果。In order to solve the above technical problems, the technical solution of the present invention provides a unit testing method, which includes: writing corresponding test case codes for development use cases and storing them; pulling the test case codes and compiling them into FatJar; Use case; stores execution results.
优选地,所述测试用例代码还包括以下至少之一的注释:分类级别注释、方法级别注释。Preferably, the test case code further includes at least one of the following annotations: category-level annotations and method-level annotations.
优选地,所述通过FatJar的反射的方式执行测试用例还包括:通过自定义classloader将FatJar加载到jvm内,通过FatJar里类的反射的方式执行测试用例。Preferably, executing the test case by means of reflection of the FatJar further includes: loading the FatJar into the jvm through a custom classloader, and executing the test case by means of the reflection of the classes in the FatJar.
优选地,还包括将执行结果输出到前端。Preferably, it also includes outputting the execution result to the front end.
本发明的另一个技术方案提供了一种单元测试装置,包括:测试代码编写模块,被配置为为开发用例编写对应的测试用例代码;测试代码管理模块:被配置为存储测试用例代码;测试用例管理模块,被配置为从测试代码管理模块拉取测试用例代码,编译成FatJar,并通过FatJar的反射的方式执行测试用例;数据库,被配置为存储执行结果。Another technical solution of the present invention provides a unit testing device, comprising: a test code writing module, configured to write corresponding test case codes for development use cases; a test code management module: configured to store test case codes; The management module is configured to pull the test case code from the test code management module, compile it into FatJar, and execute the test case through the reflection of FatJar; the database is configured to store the execution result.
优选地,所述测试用例代码还包括以下至少之一的注释:分类级别注释、方法级别注释。Preferably, the test case code further includes at least one of the following annotations: category-level annotations and method-level annotations.
优选地,所述测试代码管理模块是GitLab。Preferably, the test code management module is GitLab.
优选地,所述通过FatJar的反射的方式执行测试用例包括:通过自定义classloader将FatJar加载到jvm内,通过FatJar里类的反射的方式执行测试用例。Preferably, executing the test case by means of reflection of FatJar includes: loading the FatJar into the jvm through a custom classloader, and executing the test case by means of reflection of classes in the FatJar.
本发明的另一个技术方案还提供了一种电子设备,包括:处理器、存储器以及存储在存储器上运行的计算机程序,所述处理器执行计算机程序时实现上述任一个技术方案所述的方法的步骤。Another technical solution of the present invention also provides an electronic device, comprising: a processor, a memory, and a computer program stored and run on the memory, the processor implementing the method described in any one of the above technical solutions when the processor executes the computer program step.
本发明的另一个技术方案还提供了一种计算机可读存储介质,所述计算机程序被处理器执行时实现上述任一个技术方案所述的方法的步骤。Another technical solution of the present invention also provides a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method described in any one of the above-mentioned technical solutions are implemented.
本发明的技术方案主要具有以下几个发面的有益效果:The technical scheme of the present invention mainly has the following beneficial effects:
第一,单元测试用例可根据基础组件版本集中管理维护。First, unit test cases can be centrally managed and maintained according to the basic component version.
第二,不同组件版本之间的测试用例集合可以并行自动化执行。Second, collections of test cases between different component versions can be automated and executed in parallel.
第三,可以追踪历史单元测试用例以及当时测试用例要解决的问题场景。Third, historical unit test cases and the problem scenarios to be solved by the test cases at that time can be traced.
附图说明Description of drawings
为了更好地理解各种示例性实施例,可以参考附图,在附图中:For a better understanding of the various exemplary embodiments, reference may be made to the accompanying drawings, in which:
图1示出了实施例提供的单元测试方法的流程示意图;1 shows a schematic flowchart of a unit testing method provided by an embodiment;
图2示出了实施例提供的单元测试装置的结构示意图。FIG. 2 shows a schematic structural diagram of a unit testing apparatus provided by an embodiment.
为了便于理解,相同的附图标记已用于指代具有基本上相同或类似结构和/或基本上相同或类似功能的元件。To facilitate understanding, the same reference numerals have been used to refer to elements having substantially the same or similar structure and/or substantially the same or similar function.
具体实施方式Detailed ways
描述和图式示出了本发明的原理。因此,将了解,本领域的技术人员将能够设计各种布置,尽管本文中未明确地描述或示出所述布置,但所述布置体现本发明的原理且包括在本发明的范围内。此外,本文中所引述的所有例子主要旨在明确地用于教学目的,以帮助读者理解本发明的原理和由发明人提供的用以深化本领域的概念,并且所有例子应视为并不限于此类特定引述的例子和条件。另外,如本文中所使用,除非另有指示(例如,“或另外”或“或在替代方案中”),否则术语“或”是指非排他性的或(即,和/或)。并且,本文中所描述的各种实施例不一定相互排斥,因为一些实施例可以与一个或多个其它实施例组合以形成新的实施例。The description and drawings illustrate the principles of the invention. Accordingly, it will be appreciated that those skilled in the art will be able to devise various arrangements that, although not expressly described or illustrated herein, embody the principles of and are included within the scope of the invention. Furthermore, all examples cited herein are primarily intended to be expressly used for teaching purposes to assist the reader in understanding the principles of the invention and the concepts provided by the inventors to deepen the art, and all examples should be construed as not limiting Examples and conditions of such specific citations. Also, as used herein, the term "or" refers to a non-exclusive or (ie, and/or) unless otherwise indicated (eg, "or otherwise" or "or in the alternative"). Also, the various embodiments described herein are not necessarily mutually exclusive, as some embodiments can be combined with one or more other embodiments to form new embodiments.
名词解释:Glossary:
JUnit:JUnit是一个开放源代码的Java测试框架,用于编写和运行可重复的测试。他是用于单元测试框架体系xUnit的一个实例(用于java语言)。它包括以下特性:1、用于测试期望结果的断言(Assertion);2、用于共享共同测试数据的测试工具;3、用于方便的组织和运行测试的测试套件;4、图形和文本的测试运行器JUnit: JUnit is an open source Java testing framework for writing and running repeatable tests. It is an instance of xUnit for the unit testing framework system (for the java language). It includes the following features: 1. Assertion for testing expected results; 2. Test tools for sharing common test data; 3. Test suites for easy organization and running of tests; 4. Graphical and textual test runner
GitLab:GitLab是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。安装方法是参考GitLab在GitHub上的Wiki页面。GitLab: GitLab is an open source project for a warehouse management system, using Git as a code management tool and building a web service on this basis. The installation method is to refer to GitLab's wiki page on GitHub.
Classloader:Classloader类加载器,用来加载Java类到Java虚拟机中的一种加载器。Classloader: Classloader class loader, a loader used to load Java classes into the Java virtual machine.
FatJar:FatJar是一个包含所有项目类文件和资源以及所有依赖关系的jar包。FatJar: FatJar is a jar package that contains all project class files and resources and all dependencies.
第一个实施例提供了一种单元测试方法,参见图1,所述方法包括:The first embodiment provides a unit testing method, see FIG. 1 , the method includes:
步骤S101:为开发用例编写对应的测试用例代码并存储;Step S101: write the corresponding test case code for the development case and store it;
应用程序App应用程序里有很多应用程序接口API,每个API都有对应的一到多个测试用例。每个开发版本对应一个测试版本。There are many application program interface APIs in the application program, and each API has one or more test cases corresponding to it. Each development version corresponds to a test version.
可以采用GitLab或者其他合适的代码管理工具(下文以GitLab举例),按分支单独存储单元测试代码,一个分支对应一个版本发布或者大的特性改进先建一个开发分支,产生相应测试分支,为开发用例编写对应的测试用例代码并存储。把开发分支和测试分支关联起来。单元测试用例可以是基于Junit的,也可以基于其他测试框架来实现,下文以Junit举例。GitLab or other suitable code management tools can be used (GitLab is used as an example below) to store unit test code separately by branch. One branch corresponds to one version release or major feature improvement. First, create a development branch to generate corresponding test branches for development use cases. Write the corresponding test case code and store it. Associate the development branch with the test branch. Unit test cases can be based on Junit, or can be implemented based on other test frameworks. The following uses Junit as an example.
每个单元测试用例可以额外添加自定义注释annotation,annotation分类级别和方法级别2个维度。Each unit test case can additionally add custom annotation annotation, annotation classification level and method level 2 dimensions.
类级别主要描述类作者以及阐述类的目的,以及所属范畴等。如下:The class level mainly describes the author of the class and the purpose of the class, as well as the category to which it belongs. as follows:
方法级别主要是扩展了方法本身的一些特征,例如名称,用例对应的测试场景,作者,方法的一些额外表述(主要用来查询,统计等)。如下:The method level mainly extends some characteristics of the method itself, such as the name, the test scenario corresponding to the use case, the author, and some additional expressions of the method (mainly used for query, statistics, etc.). as follows:
定义了额外的属性,可具体定义测试用例的目的、是干什么的、结果是什么,把属性与测试用例做映射。增强Junit单元测试属性,可以更好的管理单元测试用例。Additional attributes are defined, which can specifically define the purpose of the test case, what it does, and what the result is, and map the attributes to the test case. Enhanced Junit unit test properties to better manage unit test cases.
步骤S102:拉取测试用例代码,编译成FatJar;Step S102: pull the test case code and compile it into FatJar;
GitLab拉取开发分支和对应的测试分支。基础组件相关Junit单元测试用例可以是单独项目维护,也可以是一个项目中的一个独立模块。当用户想从控制台执行某个单元测试用例的时候需要从GitLab拉取相关测试用例分支代码,然后编译成FatJar。GitLab pulls development branches and corresponding test branches. Junit unit test cases related to basic components can be maintained in a separate project, or can be an independent module in a project. When users want to execute a unit test case from the console, they need to pull the relevant test case branch code from GitLab, and then compile it into FatJar.
传统的Junit只能在开发环境代码里,没办法调取单独一个测试用例,必须调取一个类里面的多个测试用例。可以对Junit代码进行改造,使其支持外部触发调用,使之能够支持自动反射调用并执行测试用例。改了源代码,可以通过外部单独执行任何一个用例。The traditional Junit can only be in the development environment code, there is no way to call a single test case, you must call multiple test cases in a class. Junit code can be modified to support external trigger calls, so that it can support automatic reflection calls and execute test cases. The source code has been changed, and any use case can be executed externally independently.
另外插件maven pom.xml文件里面必须添加FatJar打包相关配置否则可能无法通过加载FatJar的方式来进行测试用例的调用,如下:In addition, the plugin maven pom.xml file must add FatJar packaging related configuration, otherwise it may not be possible to call test cases by loading FatJar, as follows:
不把测试用例放到项目里,而是编译成FatJar统一管理,单独触发,每个测试测试与开发测试关联,可以追溯,可以管理。Instead of putting test cases into the project, they are compiled into FatJar for unified management and triggered individually. Each test test is associated with the development test, which can be traced and managed.
步骤S103:通过FatJar的反射的方式执行测试用例;Step S103: execute the test case by means of the reflection of FatJar;
FatJar包含所有的类。系统会将FatJar通过自定义classloader加载到jvm内,通过FatJar里类的反射的方式进行调用,并执行相关测试用例。FatJar contains all the classes. The system will load the FatJar into the jvm through the custom classloader, call it through the reflection of the classes in the FatJar, and execute the relevant test cases.
用户可以在控制台绑定单元测试git地址与项目分支,方便以后管理。Users can bind the unit test git address and project branch in the console to facilitate future management.
当用户需要进行项目某个开发版本的测试时候,可以先选择测试项目,然后获取项目所有分支,然后根据项目分支获取对应单元测试用例git地址。When users need to test a development version of the project, they can first select the test project, then obtain all branches of the project, and then obtain the git address of the corresponding unit test case according to the project branch.
然后从git远端将代码拉取到本地后编译成FatJar,并将FatJar存放到本地路径,之所以编译成FatJar是因为不同的组件版本依赖的第三方包版本可能不一样,如果使用系统本身的jar包,一方面可能因为版本问题导致测试用例无法执行,另外就是要不断添加需要依赖的jar包,无形中增加成本。Then pull the code from the git remote to the local, compile it into FatJar, and store the FatJar in the local path. The reason for compiling into FatJar is because different component versions may depend on different third-party package versions. If you use the system's own version jar package, on the one hand, the test case may not be executed due to the version problem, and on the other hand, it is necessary to continuously add the jar package that needs to be dependent, which increases the cost virtually.
然后将FatJar通过自定义classloader加载到jvm内,遍历所有单元测试根据annotation将单元测试信息管理维护起来,并可以从前端进行查看。并且可以根据从前端选择的测试用例通过反射方式来进行调用,执行测试用例。Then load the FatJar into the jvm through the custom classloader, traverse all the unit tests, manage and maintain the unit test information according to the annotation, and can view it from the front end. And according to the test case selected from the front end, it can be invoked through reflection to execute the test case.
步骤S104:存储执行结果。Step S104: Store the execution result.
执行完测试用例后,将执行结果存储在数据库中,并输出到前端(如用户端)已便查询。After the test case is executed, the execution result is stored in the database and output to the front end (such as the user end) for query.
依据GitLab来管理单元测试用例,约定每个基础组件的分支对应一个单元测试用例的分支。二次开发Junit,通过自定义annotation丰富单元测试的基础属性,通过修改源码支持通过不同的classloader来加载已经打包成FatJar的单元测试集合,从而不仅实现了类之间的隔离,并且具备了从外部触发调用的能力,由此可以实现测试用例的自动化执行。According to GitLab to manage unit test cases, it is agreed that the branch of each basic component corresponds to a branch of the unit test case. The secondary development of Junit enriches the basic properties of unit tests by customizing annotations, and supports loading the unit test collections that have been packaged into FatJar through different classloaders by modifying the source code, so as to not only realize the isolation between classes, but also have external The ability to trigger calls, thereby enabling automated execution of test cases.
第二个实施例提供了一种单元测试装置200,参见图2,包括:测试代码编写模块201、测试代码管理模块202、测试用例管理模块203、数据库204。The second embodiment provides a
测试代码编写模块201,被配置为为开发用例编写对应的测试用例代码;The test
测试代码管理模块202:被配置为存储测试用例代码;Test code management module 202: configured to store test case codes;
应用程序App应用程序里有很多应用程序接口API,每个API都有对应的一到多个测试用例。每个开发版本对应一个测试版本。There are many application program interface APIs in the application program, and each API has one or more test cases corresponding to it. Each development version corresponds to a test version.
可以采用GitLab或者其他合适的代码管理工具(下文以GitLab举例)作为测试代码管理模块202,按分支单独存储单元测试代码,一个分支对应一个版本发布或者大的特性改进先建一个开发分支,产生相应测试分支,为开发用例编写对应的测试用例代码并存储。把开发分支和测试分支关联起来。单元测试用例可以是基于Junit的,也可以基于其他测试框架来实现,下文以Junit举例。GitLab or other suitable code management tools (GitLab is used as an example below) can be used as the test
每个单元测试用例可以额外添加自定义注释annotation,annotation分类级别和方法级别2个维度。类级别主要描述类作者以及阐述类的目的,以及所属范畴等。方法级别主要是扩展了方法本身的一些特征,例如名称,用例对应的测试场景,作者,方法的一些额外表述(主要用来查询,统计等)。定义了额外的属性,具体定义测试用例的目的、是干什么的、结果是什么,把属性与测试用例做映射。增强Junit单元测试属性,可以更好的管理单元测试用例。Each unit test case can additionally add custom annotation annotation, annotation classification level and method level 2 dimensions. The class level mainly describes the author of the class and the purpose of the class, as well as the category to which it belongs. The method level mainly extends some characteristics of the method itself, such as the name, the test scenario corresponding to the use case, the author, and some additional expressions of the method (mainly used for query, statistics, etc.). Defines additional attributes, specifically defines the purpose of the test case, what it does, and what the result is, and maps the attributes to the test case. Enhanced Junit unit test properties to better manage unit test cases.
测试用例管理模块203,被配置为从测试代码管理模块202拉取测试用例代码,编译成FatJar;并通过FatJar的反射的方式执行测试用例;The test
测试用例管理模块203,被配置为从测试代码管理模块202拉取测试用例代码。基础组件相关Junit单元测试用例可以是单独项目维护,也可以是一个项目中的一个独立模块。当用户想从控制台执行某个单元测试用例的时候需要从GitLab拉取相关测试用例分支代码,然后编译成FatJar。The test
传统的Junit只能在开发环境代码里,没办法调取单独一个测试用例,必须调取一个类里面的多个测试用例。可以对Junit代码进行改造,使其支持外部触发调用,使之能够支持自动反射调用并执行测试用例。改了源代码,可以通过外部单独执行任何一个用例。The traditional Junit can only be in the development environment code, there is no way to call a single test case, you must call multiple test cases in a class. Junit code can be modified to support external trigger calls, so that it can support automatic reflection calls and execute test cases. The source code has been changed, and any use case can be executed externally independently.
另外插件maven pom.xml文件里面必须添加FatJar打包相关配置否则可能无法通过加载FatJar的方式来进行测试用例的调用。In addition, the plugin maven pom.xml file must add FatJar packaging related configuration, otherwise it may not be possible to call test cases by loading FatJar.
测试用例管理模块203不把测试用例放到项目里,而是编译成FatJar统一管理,单独触发,每个测试测试与开发测试关联,可以追溯,可以管理。The test
FatJar包含所有的类。测试用例管理模块203将FatJar通过自定义classloader加载到jvm内,通过FatJar里类的反射的方式进行调用,并执行相关测试用例。FatJar contains all the classes. The test
用户可以在控制台绑定单元测试git地址与项目分支,方便以后管理。Users can bind the unit test git address and project branch in the console to facilitate future management.
当用户需要进行项目某个开发版本的测试时候,可以先选择测试项目,然后获取项目所有分支,然后根据项目分支获取对应单元测试用例git地址。When users need to test a development version of the project, they can first select the test project, then obtain all branches of the project, and then obtain the git address of the corresponding unit test case according to the project branch.
然后从git远端将代码拉取到本地后编译成FatJar,并将FatJar存放到本地路径,之所以编译成FatJar是因为不同的组件版本依赖的第三方包版本可能不一样,如果使用系统本身的jar包,一方面可能因为版本问题导致测试用例无法执行,另外就是要不断添加需要依赖的jar包,无形中增加成本。Then pull the code from the git remote to the local, compile it into FatJar, and store the FatJar in the local path. The reason for compiling into FatJar is because different component versions may depend on different third-party package versions. If you use the system's own version jar package, on the one hand, the test case may not be executed due to the version problem, and on the other hand, it is necessary to continuously add the jar package that needs to be dependent, which increases the cost virtually.
然后将FatJar通过自定义classloader加载到jvm内,遍历所有单元测试根据annotation将单元测试信息管理维护起来,并可以从前端进行查看。并且可以根据从前端选择的测试用例通过反射方式来进行调用,执行测试用例。Then load the FatJar into the jvm through the custom classloader, traverse all the unit tests, manage and maintain the unit test information according to the annotation, and can view it from the front end. And according to the test case selected from the front end, it can be invoked through reflection to execute the test case.
数据库204,存储执行结果。The
执行完测试用例后,将执行结果存储在数据库204中,并输出到前端已便查询。After the test case is executed, the execution result is stored in the
第三个实施例还提供了一种电子设备,包括:处理器、存储器以及存储在存储器上运行的计算机程序,所述处理器执行计算机程序时实现上述任一实施例方法的步骤,例如步骤S101至S104,或者所述处理器执行所述计算机程序时实现上述各实施例中各模块/单元的功能,例如单元201至204的功能。所述计算机程序可以被分割成一个或多个模块/单元,所述一个或者多个模块/单元被存储在所述存储器中,并由所述处理器执行。所述一个或多个模块/单元可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述所述计算机程序在所述电子设备中的执行过程。A third embodiment also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and running on the memory, where the processor implements the steps of the method in any of the foregoing embodiments when the processor executes the computer program, for example, step S101 to S104, or when the processor executes the computer program, the functions of the modules/units in the foregoing embodiments, for example, the functions of the
所述电子设备可以是智能手机等移动终端,或者是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。所述电子设备可包括,但不仅限于,处理器、存储器,可以包括更多或更少的部件,或者组合某些部件,例如所述电子设备还可以包括输入输出设备、网络接入设备、总线等。所称处理器可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字消息队列的管理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(FieldProgrammable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。所述存储器可以是所述电子设备的内部存储单元,例如电子设备的硬盘或内存。所述存储器也可以是所述电子设备的外部存储设备,例如所述电子设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(FlashCard)等。进一步地,所述存储器还可以既包括所述电子设备的内部存储单元也包括外部存储设备。The electronic device may be a mobile terminal such as a smart phone, or a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server. The electronic device may include, but is not limited to, a processor, a memory, more or less components, or a combination of certain components, for example, the electronic device may also include an input and output device, a network access device, a bus Wait. The processor may be a central processing unit (Central Processing Unit, CPU), other general-purpose processors, a digital message queue manager (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC) , Off-the-shelf programmable gate array (FieldProgrammable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The memory may be an internal storage unit of the electronic device, such as a hard disk or a memory of the electronic device. The memory may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a Secure Digital (SD) card, a flash memory equipped on the electronic device Card (FlashCard) and so on. Further, the memory may also include both an internal storage unit of the electronic device and an external storage device.
第五个实施例还提供了一种计算机可读存储介质,所述计算机程序被处理器执行时实现上述任一实施例方法的步骤。The fifth embodiment also provides a computer-readable storage medium, when the computer program is executed by the processor, the steps of the method of any of the above-mentioned embodiments are implemented.
在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。所述集成的模块/单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读介质不包括电载波信号和电信信号。Each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units. The integrated modules/units, if implemented in the form of software functional units and sold or used as independent products, may be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer When the program is executed by the processor, the steps of the foregoing method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form, and the like. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, Read-Only Memory (ROM) , Random Access Memory (Random Access Memory, RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable media may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer-readable media Electric carrier signals and telecommunication signals are not included.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. Module completion, that is, dividing the internal structure of the device into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment may be integrated in one processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit, and the above-mentioned integrated units may adopt hardware. It can also be realized in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing from each other, and are not used to limit the protection scope of the present application. For the specific working processes of the units and modules in the above-mentioned system, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。In the foregoing embodiments, the description of each embodiment has its own emphasis. For parts that are not described or described in detail in a certain embodiment, reference may be made to the relevant descriptions of other embodiments. Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of this application.
在本申请所提供的实施例中,应该理解到,所揭露的系统、电子设备和方法,可以通过其它的方式实现。例如,以上所描述的系统、电子设备实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,系统或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。In the embodiments provided in this application, it should be understood that the disclosed systems, electronic devices and methods may be implemented in other manners. For example, the above-described system and electronic device embodiments are only illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units. Or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of systems or units, and may be in electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the above-mentioned embodiments, those of ordinary skill in the art should understand that: it can still be used for the above-mentioned implementations. The technical solutions described in the examples 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 application, and should be included in the within the scope of protection of this application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210376644.5A CN114741296A (en) | 2022-04-12 | 2022-04-12 | Unit testing method, unit testing device, electronic equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210376644.5A CN114741296A (en) | 2022-04-12 | 2022-04-12 | Unit testing method, unit testing device, electronic equipment and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN114741296A true CN114741296A (en) | 2022-07-12 |
Family
ID=82281377
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210376644.5A Pending CN114741296A (en) | 2022-04-12 | 2022-04-12 | Unit testing method, unit testing device, electronic equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114741296A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115576854A (en) * | 2022-11-25 | 2023-01-06 | 微科智检(佛山市)科技有限公司 | Android automation unit testing method |
Citations (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20040181713A1 (en) * | 2003-03-10 | 2004-09-16 | Lambert John Robert | Automatic identification of input values that expose output failures in software object |
| CN104750606A (en) * | 2015-03-03 | 2015-07-01 | 北京空间飞行器总体设计部 | Reflection-based automated testing method |
| CN106354624A (en) * | 2015-07-17 | 2017-01-25 | 北京奇虎科技有限公司 | Automatic testing method and device |
| CN110990286A (en) * | 2019-12-12 | 2020-04-10 | 携程计算机技术(上海)有限公司 | BDD-based unit test system |
| CN111382055A (en) * | 2018-12-29 | 2020-07-07 | 贝壳技术有限公司 | Automatic unit testing method and device based on unified description language |
| CN111399814A (en) * | 2020-03-09 | 2020-07-10 | 中国邮政储蓄银行股份有限公司 | A method and device for visual arrangement of construction tasks |
| CN111797013A (en) * | 2020-06-29 | 2020-10-20 | 北京字节跳动网络技术有限公司 | Interface detection tool generation, interface detection method, device, device and medium |
| CN112965905A (en) * | 2021-03-11 | 2021-06-15 | 京东数科海益信息科技有限公司 | Data testing method, device, equipment and storage medium |
| CN113157572A (en) * | 2021-04-16 | 2021-07-23 | 中国工商银行股份有限公司 | Test case generation method and system, electronic equipment and storage medium |
-
2022
- 2022-04-12 CN CN202210376644.5A patent/CN114741296A/en active Pending
Patent Citations (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20040181713A1 (en) * | 2003-03-10 | 2004-09-16 | Lambert John Robert | Automatic identification of input values that expose output failures in software object |
| CN104750606A (en) * | 2015-03-03 | 2015-07-01 | 北京空间飞行器总体设计部 | Reflection-based automated testing method |
| CN106354624A (en) * | 2015-07-17 | 2017-01-25 | 北京奇虎科技有限公司 | Automatic testing method and device |
| CN111382055A (en) * | 2018-12-29 | 2020-07-07 | 贝壳技术有限公司 | Automatic unit testing method and device based on unified description language |
| CN110990286A (en) * | 2019-12-12 | 2020-04-10 | 携程计算机技术(上海)有限公司 | BDD-based unit test system |
| CN111399814A (en) * | 2020-03-09 | 2020-07-10 | 中国邮政储蓄银行股份有限公司 | A method and device for visual arrangement of construction tasks |
| CN111797013A (en) * | 2020-06-29 | 2020-10-20 | 北京字节跳动网络技术有限公司 | Interface detection tool generation, interface detection method, device, device and medium |
| CN112965905A (en) * | 2021-03-11 | 2021-06-15 | 京东数科海益信息科技有限公司 | Data testing method, device, equipment and storage medium |
| CN113157572A (en) * | 2021-04-16 | 2021-07-23 | 中国工商银行股份有限公司 | Test case generation method and system, electronic equipment and storage medium |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115576854A (en) * | 2022-11-25 | 2023-01-06 | 微科智检(佛山市)科技有限公司 | Android automation unit testing method |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108415832B (en) | Interface automation test method, device, equipment and storage medium | |
| US11010283B2 (en) | Mock-based unit test(s) for an end-to-end test of a code snippet | |
| US10481884B2 (en) | Systems and methods for dynamically replacing code objects for code pushdown | |
| US8806437B2 (en) | Automated testing process | |
| WO2020062673A1 (en) | Smart contract test method, storage medium, test terminal and test device | |
| US10019298B2 (en) | Middleware interface and middleware interface generator | |
| CN110888794B (en) | Interface testing method and device | |
| US11593342B2 (en) | Systems and methods for database orientation transformation | |
| WO2019090994A1 (en) | Script testing automated execution method, apparatus, equipment and storage medium | |
| CN113076253A (en) | Test method and test device | |
| CN112148278A (en) | Visual block chain intelligent contract framework and intelligent contract development and deployment method | |
| CN112764729A (en) | Application software development method and device, computer equipment and readable storage medium | |
| US20150143267A1 (en) | SYSTEM AND METHOD FOR DEVELOPING A RULE-BASED EVENT-DRIVEN MULTI-LAYERED FRONTEND FOR BUSINESS SERVICES AND RENDERING THE GUIs ON MULTIPLE CLIENT DEVICES | |
| CN114217789A (en) | Functional component expansion method, apparatus, device, storage medium and program product | |
| CN117149162A (en) | SDK automatic generation method and device, electronic equipment and storage medium | |
| CN117493188A (en) | Interface testing methods and devices, electronic equipment and storage media | |
| CN116679912A (en) | Code generation method, apparatus, device, storage medium, and computer program | |
| CN114741296A (en) | Unit testing method, unit testing device, electronic equipment and storage medium | |
| CN109725932B (en) | Method and device for generating description document of application component | |
| CN110188071B (en) | Data processing method and device, electronic equipment and computer readable medium | |
| CN113778388A (en) | Program development method and apparatus | |
| CN111367512A (en) | Method and device for creating Android library module dependency relationship in application development | |
| CN115905020A (en) | Application testing method and device, electronic equipment and storage medium | |
| CN116185826A (en) | Test method, device, equipment and storage medium | |
| CN114691246A (en) | Native platform function invocation method, apparatus and computer device |
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 |