CN106294130A - A kind of unit test method and device - Google Patents
A kind of unit test method and device Download PDFInfo
- Publication number
- CN106294130A CN106294130A CN201610606319.8A CN201610606319A CN106294130A CN 106294130 A CN106294130 A CN 106294130A CN 201610606319 A CN201610606319 A CN 201610606319A CN 106294130 A CN106294130 A CN 106294130A
- Authority
- CN
- China
- Prior art keywords
- test
- unit
- document file
- value
- input variable
- 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
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR 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
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 discloses a unit testing method and device, comprising: determining a target unit to be tested; generating a first document file according to a function corresponding to the target unit, and the first document file includes: at least one input variable , and the output variable corresponding to the at least one input variable; according to each test value corresponding to each input variable in the first document file, generate the expected value of the output variable; store the attribute information corresponding to the target unit into the second document file, and compile the attribute information in the second document file; test the compiled second document file to obtain the actual test value; according to the expected value and the Actual test values to generate test results. The invention can reduce the workload of unit testing.
Description
技术领域technical field
本发明涉及软件技术领域,特别涉及一种单元测试方法及装置。The invention relates to the technical field of software, in particular to a unit testing method and device.
背景技术Background technique
单元测试是对软件程序中的最小可测试单元进行的最有针对性、覆盖最全面、最彻底的系统性测试,用以检验软件程序的逻辑正确性,保证所编写软件程序的行为满足编程者的具体需要。单元测试在软件程序开发阶段可以充分发现软件程序中存在的Bug(漏洞),以保证软件程序的质量和使用效率。Unit testing is the most targeted, comprehensive, and thorough systematic testing of the smallest testable unit in a software program to verify the logical correctness of the software program and ensure that the behavior of the written software program satisfies the requirements of the programmer. specific needs. Unit testing can fully discover bugs (loopholes) in the software program during the software program development stage, so as to ensure the quality and efficiency of the software program.
目前,主要是通过人工实现单元测试,该人工实现的单元测试主要包括:完成一段软件程序,并对该段软件程序进行编译;确定出该段软件程序存在的语法错误、词法错误等漏洞,并对存在的漏洞进行修改,修改后再对该段软件程序进行编译,直到编译通过为止。针对编译通过的软件程序,输入变量值进行运行操作,以确定测试结果。可见,现有技术中单元测试的工作量巨大。At present, the unit test is mainly implemented manually. The unit test implemented manually mainly includes: completing a piece of software program and compiling the piece of software program; Modify the existing loopholes, and then compile the software program after modification until the compilation is passed. For the software program that has passed the compilation, input the variable value and run the operation to determine the test result. It can be seen that the workload of unit testing in the prior art is huge.
发明内容Contents of the invention
本发明实施例提供了一种单元测试方法及装置,以便于减少单元测试的工作量。The embodiment of the present invention provides a unit testing method and device, so as to reduce the workload of unit testing.
第一方面,本发明实施例提供了一种单元测试的方法,该方法包括:In the first aspect, the embodiment of the present invention provides a method for unit testing, the method comprising:
确定需要测试的目标单元;Identify the target units that need to be tested;
根据所述目标单元所对应的函数,生成第一文档文件,所述第一文档文件中包括:至少一个输入变量、以及所述至少一个输入变量对应的输出变量;According to the function corresponding to the target unit, a first document file is generated, and the first document file includes: at least one input variable and an output variable corresponding to the at least one input variable;
根据所述第一文档文件中每一个输入变量对应的各个测试值,生成所述输出变量的预期值;generating an expected value of the output variable according to each test value corresponding to each input variable in the first document file;
将所述目标单元对应的属性信息存储到第二文档文件中,并对所述第二文档文件中的所述属性信息进行编译;storing attribute information corresponding to the target unit in a second document file, and compiling the attribute information in the second document file;
对编译后的所述第二文档文件进行测试,得到实际测试值;performing a test on the compiled second document file to obtain an actual test value;
根据所述预期值和所述实际测试值,生成测试结果。A test result is generated based on the expected value and the actual test value.
优选地,Preferably,
在所述确定需要测试的目标单元之前,进一步包括:确定所需测试的软件程序对应的多个最小单元;对所述软件程序进行编译;针对编译后的所述软件程序进行静态分析;根据分析结果确定不存在漏洞的最小单元;Before the determination of the target unit to be tested, it further includes: determining a plurality of minimum units corresponding to the software program to be tested; compiling the software program; performing static analysis on the compiled software program; according to the analysis As a result, it is determined that there is no minimum unit of loopholes;
所述确定需要测试的目标单元,包括:将不存在漏洞的最小单元确定为所述目标单元。The determining the target unit that needs to be tested includes: determining the minimum unit without loopholes as the target unit.
优选地,Preferably,
进一步包括:设定条数阈值;It further includes: setting the number threshold;
在所述生成所述输出变量的预期值之前,进一步包括:根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数;在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值;其中,所述测试脚本条数为各个输入变量对应测试值个数的乘积。Before generating the expected value of the output variable, it further includes: according to each test value corresponding to each input variable in the first document file, determining to execute the test script item for generating the expected value of the output variable number; when the determined number of test scripts is greater than the number threshold, the number of test scripts is divided into at least two groups; for each group, perform the generation of the expected value of the output variable; Wherein, the number of test scripts is the product of the number of test values corresponding to each input variable.
优选地,所述测试结果包括:所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档;其中,所述测试报告,包括:漏洞总数、严重漏洞总数、漏洞类型、单元测试总工作量、漏洞原因分析;所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况、未执行的代码;Preferably, the test results include: comparison results between the expected value and the actual test value, test reports and test coverage documents; wherein, the test reports include: total number of vulnerabilities, total number of serious vulnerabilities, type of vulnerabilities, unit The total workload of the test and the analysis of the cause of the vulnerability; the test coverage document includes: the percentage of the test coverage, the execution status of each line of code, and the unexecuted code;
优选地,所述第二文档文件,包括:所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值。Preferably, the second document file includes: the definition of input variables, the definition of output variables, the definition of types, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit.
第二方面,本发明实施例提供了一种单元测试的装置,该装置包括:In a second aspect, an embodiment of the present invention provides a device for unit testing, which includes:
确定单元,用于确定需要测试的目标单元;Determine the unit, used to determine the target unit that needs to be tested;
第一生成单元,用于根据所述目标单元所对应的函数,生成第一文档文件;则,所述第一文档文件中包括:至少一个输入变量、以及所述至少一个输入变量对应的输出变量;根据所述第一文档文件中每一个输入变量对应的各个测试值,生成所述输出变量的预期值;The first generation unit is configured to generate a first document file according to the function corresponding to the target unit; then, the first document file includes: at least one input variable and an output variable corresponding to the at least one input variable ; According to each test value corresponding to each input variable in the first document file, generate the expected value of the output variable;
编译单元,用于将所述目标单元对应的属性信息存储到第二文档文件中,并对所述第二文档文件中的所述属性信息进行编译;a compiling unit, configured to store attribute information corresponding to the target unit in a second document file, and compile the attribute information in the second document file;
测试单元,用于对编译后的所述第二文档文件进行测试,得到实际测试值;a test unit, configured to test the compiled second document file to obtain actual test values;
第二生成单元,用于根据所述预期值和所述实际测试值,生成测试结果。A second generating unit, configured to generate a test result according to the expected value and the actual test value.
优选地,Preferably,
进一步包括:Further includes:
分析单元,用于确定所需测试的软件程序对应的多个最小单元;对所述软件程序进行编译;针对编译后的所述软件程序进行静态分析;根据分析结果确定不存在漏洞的最小单元;其中,所述确定单元,具体用于:将不存在漏洞的最小单元确定为所述目标单元。The analysis unit is used to determine a plurality of minimum units corresponding to the software program to be tested; compile the software program; perform static analysis on the compiled software program; determine the minimum unit without loopholes according to the analysis results; Wherein, the determining unit is specifically configured to: determine the smallest unit without loopholes as the target unit.
优选地,Preferably,
进一步包括:Further includes:
存储单元,用于存储设定的条数阈值;The storage unit is used to store the set number threshold;
进一步包括:Further includes:
划分单元,用于根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数;在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值;其中,所述测试脚本条数为各个输入变量对应测试值个数的乘积。A division unit, configured to determine the number of test scripts for executing the expected value of the output variable that is generated according to each test value corresponding to each input variable in the first document file; after the determined number of test scripts When greater than the number of thresholds, the number of test scripts is divided into at least two groups; for each group, perform the generation of the expected value of the output variable; wherein, the number of test scripts is each input Variables correspond to the product of the number of test values.
优选地,所述测试结果包括:所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档;其中,Preferably, the test results include: a comparison result between the expected value and the actual test value, a test report and a test coverage document; wherein,
所述测试报告,包括:漏洞总数、严重漏洞总数、漏洞类型、单元测试总工作量、漏洞原因分析;The test report includes: the total number of vulnerabilities, the total number of serious vulnerabilities, the types of vulnerabilities, the total workload of unit testing, and the analysis of the causes of vulnerabilities;
所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况、未执行的代码。The test coverage document includes: the percentage of test coverage, the execution status of each line of code, and unexecuted code.
优选地,所述第二文档文件,包括:所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值。Preferably, the second document file includes: the definition of input variables, the definition of output variables, the definition of types, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit.
可见,本发明实施例提供了一种单元测试方法及装置,首先确定需要测试的目标单元,根据所述目标单元所对应的函数,生成一个包括至少一个输入变量以及与所述至少一个输入变量对应的输出变量的第一文档文件。在所述第一文档文件中输入各个输入变量的各个测试值,根据所述测试值生成所述输出变量的预期值,然后把所述目标单元对应的属性信息存储到第二文档文件中,并编译所述第二文档文件,直至编译通过。对所述编译通过后的所述第二文档文件进行测试,得到实际测试值,比较所述实际测试值与所述预期值进行比较,生成测试结果,这个单元测试方法实现了半自动化的操作,减少了测试人员的手动操作时间,因此减少了单元测试的工作量。It can be seen that the embodiment of the present invention provides a unit testing method and device. Firstly, the target unit to be tested is determined, and according to the function corresponding to the target unit, a function including at least one input variable and the corresponding input variable is generated. The first documentation file for the output variable. Input each test value of each input variable in the first document file, generate the expected value of the output variable according to the test value, then store the attribute information corresponding to the target unit in the second document file, and Compile the second document file until the compilation is passed. Test the second document file after the compilation is passed to obtain an actual test value, compare the actual test value with the expected value, and generate a test result. This unit test method realizes a semi-automatic operation, Less hands-on time for testers and therefore less effort for unit testing.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are For some embodiments of the present invention, those skilled in the art can also obtain other drawings based on these drawings without creative work.
图1是本发明一个实施例提供的一种单元测试方法流程图;Fig. 1 is a kind of flow chart of unit testing method provided by one embodiment of the present invention;
图2是本发明一个实施例提供的另一种单元测试方法流程图;Fig. 2 is another kind of unit test method flowchart provided by one embodiment of the present invention;
图3是本发明一个实施例提供的一种装置所在设备的硬件架构图;FIG. 3 is a hardware architecture diagram of a device where a device is located according to an embodiment of the present invention;
图4是本发明一个实施例提供的一种单元测试装置结构图;Fig. 4 is a structural diagram of a unit testing device provided by an embodiment of the present invention;
图5是本发明一个实施例提供的另一种单元测试装置结构图;FIG. 5 is a structural diagram of another unit testing device provided by an embodiment of the present invention;
图6是本发明一个实施例提供的又一种单元测试装置结构图。Fig. 6 is a structural diagram of another unit testing device provided by an embodiment of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例,基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of the embodiments of the present invention, but not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work belong to the protection of the present invention. scope.
如图1所示,本发明实施例提供了一种单元测试方法,该方法可以包括以下步骤:As shown in Figure 1, the embodiment of the present invention provides a unit testing method, which may include the following steps:
步骤101:确定需要测试的目标单元;Step 101: Determine the target unit to be tested;
步骤102:根据所述目标单元所对应的函数,生成第一文档文件,所述第一文档文件中包括:至少一个输入变量、以及所述至少一个输入变量对应的输出变量;Step 102: Generate a first document file according to the function corresponding to the target unit, and the first document file includes: at least one input variable and an output variable corresponding to the at least one input variable;
步骤103:根据所述第一文档文件中每一个输入变量对应的各个测试值,生成所述输出变量的预期值;Step 103: Generate the expected value of the output variable according to each test value corresponding to each input variable in the first document file;
步骤104:将所述目标单元对应的属性信息存储到第二文档文件中,并对所述第二文档文件中的所述属性信息进行编译;Step 104: storing the attribute information corresponding to the target unit in a second document file, and compiling the attribute information in the second document file;
步骤105:对编译后的所述第二文档文件进行测试,得到实际测试值;Step 105: Test the compiled second document file to obtain an actual test value;
步骤106:根据所述预期值和所述实际测试值,生成测试结果。Step 106: Generate a test result according to the expected value and the actual test value.
根据上述实施例,首先确定需要测试的目标单元,根据所述目标单元所对应的函数,生成一个包括至少一个输入变量以及与所述至少一个输入变量对应的输出变量的第一文档文件。在所述第一文档文件中输入各个输入变量对应的各个测试值,根据所述测试值生成所述输出变量的预期值,然后把所述目标单元对应的属性信息存储到第二文档文件中,并编译所述第二文档文件,直至编译通过。对所述编译通过后的所述第二文档文件进行测试,得到实际测试值,比较所述实际测试值与所述预期值进行比较,生成测试结果,这个单元测试方法实现了半自动化的操作,减少了测试人员的手动操作时间,因此减少了单元测试的工作量。According to the above embodiment, the target unit to be tested is first determined, and a first document file including at least one input variable and an output variable corresponding to the at least one input variable is generated according to the function corresponding to the target unit. Input each test value corresponding to each input variable in the first document file, generate the expected value of the output variable according to the test value, and then store the attribute information corresponding to the target unit in the second document file, And compile the second document file until the compilation is passed. Test the second document file after the compilation is passed to obtain an actual test value, compare the actual test value with the expected value, and generate a test result. This unit test method realizes a semi-automatic operation, Less hands-on time for testers and therefore less effort for unit testing.
在本发明一个实施例中,在确定所述需要测试的目标单元之前,需要对所述软件程序进行静态分析,人工排除所述软件程序中存在漏洞的最小单元,在不存在漏洞的那部分最小单元中确定需要测试的所述目标单元,包括:In one embodiment of the present invention, before determining the target unit to be tested, it is necessary to statically analyze the software program, manually exclude the smallest unit with loopholes in the software program, and the smallest unit without loopholes. The target units that need to be tested are identified in the unit, including:
确定所需测试的软件程序对应的多个最小单元;对所述软件程序进行编译;针对编译后的所述软件程序进行静态分析;根据分析结果确定不存在漏洞的最小单元;Determining multiple minimum units corresponding to the software program to be tested; compiling the software program; performing static analysis on the compiled software program; determining the minimum unit without loopholes according to the analysis results;
所述确定需要测试的目标单元,包括:将不存在漏洞的最小单元确定为所述目标单元。The determining the target unit that needs to be tested includes: determining the minimum unit without loopholes as the target unit.
根据上述实施例,首先要确定所需测试的软件程序中所有的最小单元,对所述的软件程序进行编译,查看所述软件程序中存在的词法错误、语法错误等这些漏洞,然后排除存在所述漏洞的那部分程序,对余下的那部分软件程序进行静态分析,人工对所述余下的软件程序进行词法分析与、语法分析、静态错误分析找出漏洞,然后排除存在所述漏洞的那部分程序,而剩下的那部分软件程序中的所有最小单元就都是不存在漏洞的最小单元,所述确定需要测试的目标单元,就是在这些不存在漏洞的最小单元中来确定的。可以看出在确定所述确定需要测试的目标单元之前,进行所述软件程序的编译及静态分析,保证确定的所述目标单元是在不存在漏洞的那部分最小单元中确定的,因此可以减少单元测试的工作量。According to the above-mentioned embodiment, at first all minimum units in the software program to be tested shall be determined, the software program shall be compiled, and the loopholes such as lexical errors and grammatical errors existing in the software program shall be checked, and then the existence of all such loopholes shall be ruled out The part of the program with the above-mentioned loopholes, statically analyze the remaining part of the software program, manually perform lexical analysis, syntax analysis, and static error analysis on the remaining software programs to find out the loopholes, and then eliminate the part with the above-mentioned loopholes program, and all the smallest units in the remaining part of the software program are the smallest units without loopholes, and the determination of the target units to be tested is determined in these smallest units without loopholes. It can be seen that before determining the target unit that needs to be tested, the software program is compiled and statically analyzed to ensure that the determined target unit is determined in the part of the smallest unit that does not have loopholes, so it can reduce The workload of unit testing.
在本发明一个实施例中,在单元测试过程中,如果测试的数据量很大,那么就会影响到单元测试的速度,那么这个时候就需要限制每次测试的数据量,保证单元测试可以迅速的完成,那么就需要预先设置测试条数的阈值,保证测试的条数在一定的阈值内,保证单元测试可以快速的完成。包括:In one embodiment of the present invention, in the unit test process, if the amount of data tested is very large, then the speed of the unit test will be affected, so at this time it is necessary to limit the amount of data tested each time to ensure that the unit test can be performed quickly. The completion of the test, then it is necessary to pre-set the threshold of the number of tests to ensure that the number of tests is within a certain threshold and ensure that the unit test can be completed quickly. include:
设定条数阈值;Set the number threshold;
在所述生成所述输出变量的预期值之前,根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数;在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值;其中,所述测试脚本条数为各个输入变量对应测试值个数的乘积。Before generating the expected value of the output variable, according to each test value corresponding to each input variable in the first document file, determine the number of test scripts for executing the generation of the expected value of the output variable; When the determined number of test scripts is greater than the number threshold, divide the number of test scripts into at least two groups; for each group, perform the generation of the expected value of the output variable; wherein, the The number of test scripts mentioned above is the product of the number of test values corresponding to each input variable.
根据上述实施例,可预先设定条数阈值,在根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数,比较预期值的测试脚本条数与所述设定过的条数阈值,当所述在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值。测试脚本条数分组后,可以分别对每一组测试脚本条数内的相应的代码进行分组测试,减少每次测试的数据量,因此这样可以提高单元测试的速度。According to the above-mentioned embodiment, the number of thresholds can be preset, and the number of test scripts that execute the generation of the expected value of the output variable is determined according to each test value corresponding to each input variable in the first document file, Compare the number of test scripts of the expected value with the set number threshold, and when the determined number of test scripts is greater than the number threshold, divide the number of test scripts into at least two grouping; for each grouping, perform the generating the expected value of the output variable. After the number of test scripts is grouped, the corresponding codes in each group of test scripts can be grouped and tested to reduce the amount of data for each test, thus improving the speed of unit testing.
在本发明一个实施例中,所述目标单元的测试结果,包括:所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档,测试人员可以从上述的测试结果中,查找漏洞,并根据具体的结果,对各个漏洞进行有针对性的修改。包括:In one embodiment of the present invention, the test results of the target unit include: comparison results between the expected value and the actual test value, test reports and test coverage documents, testers can find out from the above test results Vulnerabilities, and according to the specific results, make targeted modifications to each vulnerability. include:
所述测试结果包括:所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档;其中,所述测试报告,包括:漏洞总数、漏洞类型、单元测试总工作量和漏洞原因分析中的至少一种;所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况和未执行的代码中的至少一种;The test results include: comparison results between the expected value and the actual test value, test reports and test coverage documents; wherein, the test reports include: total number of vulnerabilities, types of vulnerabilities, total unit test workload and causes of vulnerabilities At least one of the analysis; the test coverage document includes: at least one of the percentage of test coverage, the execution of each line of code and the unexecuted code;
根据上述实施例,测试人员根据具体的需要在所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档这三个测试结果的文档中的目标文档中找出需要的测试结果,减少了测试人员查找测试结果的查找时间。According to the above-mentioned embodiment, the tester finds the required test result in the target document among the three test result documents of the expected value and the actual test value comparison result, test report and test coverage document according to specific needs , which reduces the search time for testers to find test results.
在本发明一个实施例中,与所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值全部写入到第二个文档中,包括:In one embodiment of the present invention, the definition of the input variable, the definition of the output variable, the definition of the type, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit are all written into the second documents, including:
所述第二文档文件,包括:所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值。The second document file includes: the definition of input variables, the definition of output variables, the definition of types, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit.
根据上述实施例,与所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值全部放在第二个文档中,保证所述目标单元所定义的属性信息的完整性,方便测试人员对第二个文档的编译操作。According to the above-mentioned embodiment, the definition of the input variable, the definition of the output variable, the definition of the type, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit are all placed in the second document, The integrity of the attribute information defined by the target unit is guaranteed, and it is convenient for testers to compile the second document.
为使本发明的目的、技术方案和优点更加清楚,下面结合图2所示的单元测试的方法,以测试软件程序中的一个目标单元为例,对本发明实施例提供的单元测试的方法作进一步地详细说明。In order to make the purpose, technical solution and advantages of the present invention clearer, below in conjunction with the method for unit testing shown in Figure 2, taking a target unit in the testing software program as an example, the method for unit testing provided by the embodiment of the present invention will be further described in detail.
如图2所示,本发明一个实施例提供了另一种单元测试方法,该方法可以包括以下步骤:As shown in Figure 2, an embodiment of the present invention provides another unit testing method, which may include the following steps:
步骤201:确定所需测试的软件程序对应的多个最小单元并对所述软件程序进行编译。Step 201: Determine multiple minimum units corresponding to the software program to be tested and compile the software program.
确定所需测试的软件程序,并确定所述软件程序中的多个最小单元,并对所述软件程序进行编译。所述的最小单元是这个所述软件程序中的最小可检测单元,例如,编程语言为C语言的,那么要进行测试的最小单元就是函数,而编程语言为C++的,那么要进行测试的最小单元就是类。例如,确定所需测试的软件程序的编程为C语言,那么就需要确定所述软件程序中的多个或者所有的最小单元,如确定所述软件程序中有函数1、函数2、函数3直到函数50,共50个最小单元。确定之后并对这个所述软件程序进行整体编译,找出所述软件程序中的词法错误、语法错误等漏洞,这个漏洞可能是代码重复,代码没有写全有缺失代码,或者代码无定义等。编译结束后,发现函数3、函数6、函数15这个三个最小单元的代码存在漏洞,那么测试人员就要排除这部分存在错误的代码,并对这部分代码进行漏洞修改,而剩余的那部分软件程序就是没有漏洞的部分了。A software program to be tested is determined, a plurality of minimum units in the software program are determined, and the software program is compiled. The minimum unit is the minimum detectable unit in the software program. For example, if the programming language is C language, then the minimum unit to be tested is a function, and if the programming language is C++, then the minimum unit to be tested is Units are classes. For example, if it is determined that the programming of the software program to be tested is C language, then it is necessary to determine a plurality or all of the minimum units in the software program, such as determining that there are function 1, function 2, function 3, and so on in the software program. Function 50, a total of 50 minimum units. After confirming and compiling the software program as a whole, find loopholes such as lexical errors and grammatical errors in the software program. The loopholes may be code duplication, missing codes, or undefined codes. After the compilation is completed, if there are loopholes in the code of the three smallest units of function 3, function 6, and function 15, then the tester must eliminate this part of the code with errors, and modify the vulnerability of this part of the code, and the remaining part The software program is the part without bugs.
步骤202:针对编译后的所述软件程序进行静态分析并根据分析结果确定不存在漏洞的最小单元。Step 202: Perform static analysis on the compiled software program and determine the smallest unit without loopholes according to the analysis result.
对编译排除存在漏洞的代码后的没有漏洞的软件程序,比如上例中排除函数3、函数6、函数15这个三个最小单元的代码后,就需要对剩下的软件程序进行人工静态的分析,测试人员手动进行排查代码重复,代码没有写全有缺失代码,或者代码无定义等漏洞,静态分析结束后,发现函数24、函数35、这两个最小单元的代码存在漏洞然后测试人员就要排除这部分存在错误的代码,并对这部分代码进行漏洞修改,而静态分析排除存在漏洞的代码后的没有漏洞的软件程序就是根据分析结果确定的不存在漏洞的最小单元。For software programs without vulnerabilities after compiling and excluding codes with vulnerabilities, for example, after excluding the codes of the three smallest units of function 3, function 6, and function 15 in the above example, it is necessary to perform manual static analysis on the remaining software programs , the testers manually check for code duplication, missing codes, or undefined codes. After the static analysis is over, they find that there are loopholes in the code of function 24, function 35, and the two smallest units. Then the testers will Exclude this part of the code with errors, and modify this part of the code for vulnerabilities, and the software program without vulnerabilities after the static analysis excludes the code with vulnerabilities is the smallest unit without vulnerabilities determined according to the analysis results.
步骤203:确定需要测试的目标单元。Step 203: Determine the target unit to be tested.
所述确定需要测试的目标单元,是在对所述软件程序进行静态分析后,将在不存在漏洞的最小单元中来确定为所述目标单元。例如在所述软件程序进行静态分析后,得出函数1、函数2、函数10、函数27等是不存在漏洞的最小单元,那么就可以在函数1、函数2、函数10、函数27等这些不存在漏洞的最小单元中,确定函数2为需要测试的目标单元。The determination of the target unit to be tested is determined as the target unit among the smallest units without loopholes after static analysis of the software program. For example, after the software program is statically analyzed, it is found that function 1, function 2, function 10, function 27, etc. are the smallest units without loopholes, so it can be used in function 1, function 2, function 10, function 27, etc. Among the smallest units without vulnerabilities, determine function 2 as the target unit to be tested.
步骤204:设定条数阈值。Step 204: Set the number threshold.
这个条数阈值,测试人员可根据测试的具体情况来确定,例如,设定条数阈值可以是10、20、100等。The threshold of the number of bars can be determined by the tester according to the specific situation of the test, for example, the threshold of the number of bars can be set to 10, 20, 100, etc.
步骤205:根据所述目标单元所对应的函数,生成第一文档文件。Step 205: Generate a first document file according to the function corresponding to the target unit.
所述第一文档文件中包括:至少一个输入变量、以及所述至少一个输入变量对应的输出变量;The first document file includes: at least one input variable, and an output variable corresponding to the at least one input variable;
例如,所述目标单元所对应的函数为函数2,那么生成的第一文档文件就可以是一个EXCEL表格,在这个所述EXCEL表格中,就包括函数2的至少一个输入变量、以及所述至少一个输入变量对应的输出变量。比如这个所述EXCEL表格中获取的输入变量A、输入变量B、以及与输入变量对应的输出变量C。For example, if the function corresponding to the target unit is function 2, then the generated first document file can be an EXCEL form, and in this EXCEL form, at least one input variable of function 2 and the at least one input variable of function 2 are included. An output variable corresponding to an input variable. For example, the input variable A, the input variable B, and the output variable C corresponding to the input variable obtained in the EXCEL sheet.
步骤206:根据所述第一文档文件中每一个输入变量对应的各个测试值,并确定执行所述生成所述输出变量的预期值的测试脚本条数。Step 206: According to each test value corresponding to each input variable in the first document file, and determine the number of test scripts to execute to generate the expected value of the output variable.
在所述第一文档文件中输入每一个输入变量对应的各个测试值,并根据各个输入变量对应测试值个数的乘积来得到执行所述生成所述输出变量的预期值的测试脚本条数。例如,输入变量A的测试值为3个,输入变量B的测试值为2个,输入变量C的测试值为4个,那么执行所述生成所述输出变量的预期值的测试脚本条数为3×2×4=24条。Each test value corresponding to each input variable is input in the first document file, and the number of test scripts executed to generate the expected value of the output variable is obtained according to the product of the number of test values corresponding to each input variable. For example, the test value of the input variable A is 3, the test value of the input variable B is 2, and the test value of the input variable C is 4, so the number of test scripts that execute the described generation of the expected value of the output variable is 3*2*4=24 pieces.
步骤207:当所述确定的所述测试脚本条数大于所述设定条数阈值时,执行:将所述测试脚本条数分成至少两个分组。Step 207: When the determined number of test scripts is greater than the set number threshold, perform: divide the number of test scripts into at least two groups.
例如,当确定测试脚本条数后,这个所述确定测试脚本条数大于所述设定的条数阈值时所述确定测试脚本条数就要进行分组,如果小于所述设定的条数阈值时所述确定测试脚本条数就不用进行分组了。比如设定条数阈值为25,当确定测试脚本条数为20的时候,确定测试脚本条数20就小于设定条数阈值25,那么所述测试脚本条数就不用分组了,但是当确定测试脚本条数为50的时候,确定测试脚本条数50就大于设定条数阈值25,那么所述测试脚本条数就要进行分组,这个分组数量,测试人员可根据具体的需要进行分组,可以分为2组,也可以分为3组。For example, after determining the number of test scripts, the number of determined test scripts will be grouped when the number of test scripts is greater than the set number threshold, if it is less than the set number threshold When determining the number of test scripts as described above, there is no need to group them. For example, the set number threshold is 25. When the number of test scripts is determined to be 20, it is determined that the number of test scripts 20 is less than the set number threshold 25. Then the number of test scripts does not need to be grouped, but when it is determined When the number of test scripts is 50, it is determined that the number of test scripts 50 is greater than the set number threshold 25, then the number of test scripts will be grouped, and the number of groups can be grouped by testers according to specific needs. Can be divided into 2 groups, can also be divided into 3 groups.
步骤208:根据所述第一文档文件中每一个输入变量对应的各个测试值,生成所述输出变量的预期值。Step 208: Generate the expected value of the output variable according to each test value corresponding to each input variable in the first document file.
根据在所述第一文档中输入的每一个输入变量对应的各个测试值生成所述输出变量的预期值,例如,测试人员可以根据在所述第一文档EXCEL表中输入的每个变量的各个测试值,根据所述确定的目标单元对应的函数来计算生成所述输出变量的预期值。According to each test value corresponding to each input variable input in the first document, the expected value of the output variable is generated. The test value is calculated according to the function corresponding to the determined target unit to generate the expected value of the output variable.
步骤209:将所述目标单元对应的属性信息存储到第二文档文件中,并对所述第二文档文件中的所述属性信息进行编译。Step 209: Store the attribute information corresponding to the target unit in a second document file, and compile the attribute information in the second document file.
所述第二文档文件,包括:所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值。The second document file includes: the definition of input variables, the definition of output variables, the definition of types, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit.
例如,第二文档文件可以是一个TXT文件,如确定的所述目标单元为函数1,那么关于函数1的输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值,都将写入到第二文档文件:这个TXT文件中,然后对所述的TXT文件中所有的关于函数1的属性信息进行编译,找出存在词法错误、语法错误等漏洞,这个漏洞可能是代码重复,代码没有写全有缺失代码,或者代码无定义等。然后对于找出的漏洞进行修改,修改完成后再对所述第二文档文件进行编译,如此循环反复直到所述第二文档文件编译通过为止。For example, the second document file can be a TXT file. If the target unit is determined to be function 1, then the definition of the input variable, the definition of the output variable, the definition of the type, the main body of the function and each input variable of function 1 Each corresponding test value will be written into the second document file: this TXT file, and then compile all the attribute information about function 1 in the TXT file to find out the existence of lexical errors, grammatical errors and other loopholes , this vulnerability may be code duplication, code is not fully written, missing code, or code is undefined. Then modify the found loopholes, and then compile the second document file after the modification is completed, and repeat this cycle until the second document file is compiled successfully.
步骤210:对编译后的所述第二文档文件进行测试,得到实际测试值。Step 210: Test the compiled second document file to obtain actual test values.
对于编译后的所述第二文档文件测试人员就要运用确定的测试脚本对其进行运行测试,得到实际的测试值。For the compiled second document file, the tester will use a certain test script to run the test to obtain the actual test value.
例如,对于函数1,通过编译后测试人员就要运用确定的测试脚本对所述第二文档文件进行运行测试,根据每一个输入变量对应的各个测试值,得出与其对应的实际的测试值。For example, for function 1, after compiling, the tester will use the determined test script to run the test on the second document file, and obtain the corresponding actual test value according to each test value corresponding to each input variable.
步骤211:根据所述预期值和所述实际测试值,生成测试结果。Step 211: Generate a test result according to the expected value and the actual test value.
所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档;其中,所述测试报告,包括:漏洞总数、漏洞类型、单元测试总工作量和漏洞原因分析中的至少一种;所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况和未执行的代码中的至少一种;The expected value and the actual test value comparison result, test report and test coverage document; wherein, the test report includes: at least one of the total number of vulnerabilities, the type of vulnerabilities, the total workload of unit testing, and the analysis of the causes of vulnerabilities ; The test coverage document includes: at least one of the percentage of test coverage, the execution status of each line of code and unexecuted code;
例如,所述预期值和所述实际测试值比较结果,这个结果可以有两种情况,包括:所述对比预期结果跟实际结果完全一致,不存在任何的误差;和/或所述对比预期结果跟确定实际结果存在一定精度内的误差,也认为所述对比预期结果跟实际结果是一致的。如函数1,预期值为5,实际测试值也为5,那么就认为一致,不存在漏洞。如函数1,预期值为5,实际测试值为8,那么就认为不一致,存在漏洞,就需要测试人员根据这个结果去解决修改相对应的漏洞。另外,又如所述对比预期结果跟确定实际结果存在一定精度内的误差,比如可设置为数值在0.5以内的误差都算一致,如函数1,预期值为5,实际测试值也为5.4,那么就认为一致,不存在漏洞。这个所述预期值和所述实际测试值比较结果可以写入到第一文档中,为一个EXCEL表格。For example, the comparison result between the expected value and the actual test value can have two situations, including: the comparison expected result is completely consistent with the actual result without any error; and/or the comparison expectation result There is an error within a certain precision with the determined actual result, and the expected result of the comparison is also considered to be consistent with the actual result. For example, if the expected value of function 1 is 5, and the actual test value is also 5, then it is considered consistent and there is no loophole. For example, if the expected value of function 1 is 5, and the actual test value is 8, then it is considered inconsistent and there are loopholes, and testers need to solve and modify the corresponding loopholes based on this result. In addition, as mentioned above, there is an error within a certain accuracy between the expected result and the determined actual result. For example, it can be set that the error within 0.5 is consistent. For example, the expected value of function 1 is 5, and the actual test value is also 5.4. Then it is considered consistent and there is no loophole. The comparison result between the expected value and the actual test value can be written into the first file, which is an EXCEL table.
所述测试报告,包括:漏洞总数、漏洞类型、单元测试总工作量和漏洞原因分析中的至少一种;例如,测试报告可以是个EXCEL表格,比如对于所述确定的目标单元函数1测试完毕后,用表格的形式显示出漏洞总数、漏洞类型、单元测试总工作量、漏洞原因分析,其中漏洞原因分析是测试人员根据这个测试报告的具体情况来给出的。The test report includes: at least one of the total number of vulnerabilities, the type of vulnerabilities, the total workload of the unit test and the analysis of the causes of the vulnerabilities; for example, the test report can be an EXCEL form, such as after the test of the determined target unit function 1 is completed , in the form of a table to display the total number of vulnerabilities, the types of vulnerabilities, the total workload of unit testing, and the analysis of the causes of the vulnerabilities. The analysis of the causes of the vulnerabilities is given by the testers based on the specific conditions of the test report.
所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况和未执行的代码中的至少一种;例如,对于所述确定的目标单元函数1测试完毕后,会以一个TXT文本的形式来生成这个测试覆盖率文档,文档中会给出测试覆盖率的百分比,这个百分比根据实际测试的具体情况来给出,比如80%。每一行代码的执行情况,会把没有测试的代码行写入到这个测试覆盖率文档中,方便测试人员了解还有哪些代码没有进行测试。The test coverage document includes: at least one of the percentage of test coverage, the execution status of each line of code and the unexecuted code; for example, after the test of the determined target unit function 1 is completed, a TXT text to generate this test coverage document, the document will give the percentage of test coverage, this percentage is given according to the specific situation of the actual test, such as 80%. The execution status of each line of code will write the untested code lines into this test coverage document, so that testers can know which codes have not been tested.
如图3、图4所示,本发明实施例提供了一种单元测试装置。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。从硬件层面而言,如图3所示,为本发明实施例提供的一种单元测试装置所在设备的一种硬件结构图,除了图3所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的设备通常还可以包括其他硬件,如负责处理报文的转发芯片等等。以软件实现为例,如图4所示,作为一个逻辑意义上的装置,是通过其所在设备的CPU将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。As shown in FIG. 3 and FIG. 4 , the embodiment of the present invention provides a unit testing device. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. From the perspective of hardware, as shown in Figure 3, it is a hardware structure diagram of the device where a unit test device is provided in the embodiment of the present invention, except for the processor, memory, network interface, and non-volatile memory shown in Figure 3 In addition to the volatile memory, the device where the device in the embodiment is located may generally include other hardware, such as a forwarding chip responsible for processing packets, and the like. Taking software implementation as an example, as shown in Figure 4, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the CPU of the device where it is located.
本发明一个实施例提供的一种单元测试装置,参见图4,包括:A unit testing device provided by an embodiment of the present invention, referring to FIG. 4 , includes:
确定单元401,用于确定需要测试的目标单元;Determining unit 401, configured to determine the target unit to be tested;
第一生成单元402,用于根据所述目标单元所对应的函数,生成第一文档文件;则,所述第一文档文件中包括:至少一个输入变量、以及所述至少一个输入变量对应的输出变量;根据所述第一文档文件中每一个输入变量对应的各个测试值,生成所述输出变量的预期值;The first generating unit 402 is configured to generate a first document file according to the function corresponding to the target unit; then, the first document file includes: at least one input variable and an output corresponding to the at least one input variable variable; generating an expected value of the output variable according to each test value corresponding to each input variable in the first document file;
编译单元403,用于将所述目标单元对应的属性信息存储到第二文档文件中,并对所述第二文档文件中的所述属性信息进行编译;A compiling unit 403, configured to store attribute information corresponding to the target unit in a second document file, and compile the attribute information in the second document file;
测试单元404,用于对编译后的所述第二文档文件进行测试,得到实际测试值;a testing unit 404, configured to test the compiled second document file to obtain an actual test value;
第二生成单元405,用于根据所述预期值和所述实际测试值,生成测试结果。The second generation unit 405 is configured to generate a test result according to the expected value and the actual test value.
在本发明一个实施例中,如图5所示,该单元测试装置可以进一步包括:In one embodiment of the present invention, as shown in Figure 5, the unit testing device may further include:
分析单元501,用于确定所需测试的软件程序对应的多个最小单元;对所述软件程序进行编译;针对编译后的所述软件程序进行静态分析;根据分析结果确定不存在漏洞的最小单元;The analysis unit 501 is used to determine a plurality of minimum units corresponding to the software program to be tested; compile the software program; perform static analysis on the compiled software program; determine the minimum unit without loopholes according to the analysis results ;
其中,确定单元401确定所述确定需要测试的目标单元,包括:将不存在漏洞的最小单元确定为所述目标单元。Wherein, the determining unit 401 determining the target unit that needs to be tested includes: determining a minimum unit without a loophole as the target unit.
在本发明一个实施例中,如图6所示,该单元测试装置可以进一步包括:In one embodiment of the present invention, as shown in Figure 6, the unit testing device may further include:
存储单元601,用于存储设定的条数阈值;A storage unit 601, configured to store the set number threshold;
划分单元602,用于根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数;在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值;其中,所述测试脚本条数为各个输入变量对应测试值个数的乘积。The dividing unit 602 is configured to determine the number of test scripts that execute the test scripts that generate the expected values of the output variables according to each test value corresponding to each input variable in the first document file; When the number is greater than the number threshold, the number of test scripts is divided into at least two groups; for each group, the expected value of the output variable is generated; wherein, the number of test scripts is each The input variable corresponds to the product of the number of test values.
在本发明一个实施例中,所述测试结果包括:所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档;其中,所述测试报告,包括:漏洞总数、漏洞类型、单元测试总工作量和漏洞原因分析中的至少一种;所述测试覆盖率文档,包括:测试覆盖率的百分比、每一行代码的执行情况和未执行的代码中的至少一种;In one embodiment of the present invention, the test results include: comparison results between the expected value and the actual test value, test reports and test coverage documents; wherein, the test reports include: total number of vulnerabilities, types of vulnerabilities, At least one of the total unit test workload and vulnerability analysis; the test coverage document includes: at least one of the percentage of test coverage, the execution of each line of code, and unexecuted code;
在本发明一个实施例中,所述第二文档文件,包括:所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值。In an embodiment of the present invention, the second document file includes: the definition of the input variable, the definition of the output variable, the definition of the type, the main body of the function, and each corresponding to each input variable in the function corresponding to the target unit. test value.
综上所述,本发明各个实施例至少可以实现如下有益效果:In summary, each embodiment of the present invention can at least achieve the following beneficial effects:
1、在本发明实施例中,首先确定需要测试的目标单元,根据所述目标单元所对应的函数,生成一个包括至少一个输入变量以及与所述至少一个输入变量对应的输出变量的第一文档文件。在所述第一文档文件中输入各个输入变量对应的各个测试值,根据所述测试值生成所述输出变量的预期值,然后把所述目标单元对应的属性信息存储到第二文档文件中,并编译所述第二文档文件,直至编译通过。对所述编译通过后的所述第二文档文件进行测试,得到实际测试值,比较所述实际测试值与所述预期值进行比较,生成测试结果,这个单元测试方法实现了半自动化的操作,减少了测试人员的手动操作时间,因此减少了单元测试的工作量。1. In the embodiment of the present invention, first determine the target unit to be tested, and generate a first document including at least one input variable and an output variable corresponding to the at least one input variable according to the function corresponding to the target unit document. Input each test value corresponding to each input variable in the first document file, generate the expected value of the output variable according to the test value, and then store the attribute information corresponding to the target unit in the second document file, And compile the second document file until the compilation is passed. Test the second document file after the compilation is passed to obtain an actual test value, compare the actual test value with the expected value, and generate a test result. This unit test method realizes a semi-automatic operation, Less hands-on time for testers and therefore less effort for unit testing.
2、在本发明实施例中,首先要确定所需测试的软件程序中所有的最小单元,对所述的软件程序进行编译,查看所述软件程序中存在的词法错误、语法错误等这些漏洞,然后排除存在所述漏洞的那部分程序,对余下的那部分软件程序进行静态分析,人工对所述余下的软件程序进行词法分析与、语法分析、静态错误分析找出漏洞,然后排除存在所述漏洞的那部分程序,而剩下的那部分软件程序中的所有最小单元就都是不存在漏洞的最小单元,所述确定需要测试的目标单元,就是在这些不存在漏洞的最小单元中来确定的。可以看出在确定所述确定需要测试的目标单元之前,进行所述软件程序的编译及静态分析,保证确定的所述目标单元是在不存在漏洞的那部分最小单元中确定的,因此可以减少单元测试的工作量。2. In the embodiment of the present invention, it is first necessary to determine all the smallest units in the software program to be tested, compile the software program, check the loopholes such as lexical errors and grammatical errors in the software program, Then get rid of that part of program that has said loophole, carry out static analysis to remaining that part of software program, manually carry out lexical analysis, grammatical analysis, static error analysis to described remaining software program to find out loophole, then rule out existence of said loophole loopholes, and all the smallest units in the remaining part of the software program are the smallest units without loopholes, and the determination of the target unit to be tested is determined in these smallest units without loopholes of. It can be seen that before determining the target unit that needs to be tested, the software program is compiled and statically analyzed to ensure that the determined target unit is determined in the part of the smallest unit that does not have loopholes, so it can reduce The workload of unit testing.
3、在本发明实施例中,可预先设定条数阈值,在根据所述第一文档文件中每一个输入变量对应的各个测试值,确定执行所述生成所述输出变量的预期值的测试脚本条数,比较预期值的测试脚本条数与所述设定过的条数阈值,当所述在确定的所述测试脚本条数大于所述条数阈值时,则将所述测试脚本条数分成至少两个分组;针对每一个分组,执行所述生成所述输出变量的预期值。测试脚本条数分组后,可以分别对每一组测试脚本条数内的相应的代码进行分组测试,减少每次测试的数据量,因此这样可以提高单元测试的速度。3. In the embodiment of the present invention, the threshold value of the number of items can be preset, and according to each test value corresponding to each input variable in the first document file, determine and execute the test that generates the expected value of the output variable The number of scripts, comparing the number of test scripts of the expected value with the set number threshold, when the determined number of test scripts is greater than the threshold, the test scripts will be The data is divided into at least two groupings; for each grouping, the generating the expected value of the output variable is performed. After the number of test scripts is grouped, the corresponding codes in each group of test scripts can be grouped and tested to reduce the amount of data for each test, thus improving the speed of unit testing.
4、在本发明实施例中,测试人员根据具体的需要在所述预期值和所述实际测试值比较结果、测试报告和测试覆盖率文档这三个测试结果的文档中的目标文档中找出需要的测试结果,减少了测试人员查找测试结果的查找时间。4. In the embodiment of the present invention, the tester finds out in the target documents among the three test result documents of the expected value and the actual test value comparison result, test report and test coverage document according to specific needs. required test results, reducing the search time for testers to find test results.
5、在本发明实施例中,与所述目标单元所对应函数中输入变量的定义、输出变量的定义、类型的定义、函数的主体和每一个输入变量对应的各个测试值全部放在第二个文档中,保证所述目标单元所定义的属性信息的完整性,方便测试人员对第二个文档的编译操作。5. In the embodiment of the present invention, the definition of the input variable, the definition of the output variable, the definition of the type, the main body of the function and each test value corresponding to each input variable in the function corresponding to the target unit are all placed in the second In the first document, the integrity of the attribute information defined by the target unit is guaranteed, which is convenient for testers to compile the second document.
上述装置内的各单元之间的信息交互、执行过程等内容,由于与本发明方法实施例基于同一构思,具体内容可参见本发明方法实施例中的叙述,此处不再赘述。The information exchange and execution process among the units in the above-mentioned device are based on the same concept as the method embodiment of the present invention, and the specific content can refer to the description in the method embodiment of the present invention, and will not be repeated here.
需要说明的是,在本文中,诸如第一和第二之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个······”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同因素。It should be noted that in this article, 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 that there is a relationship between these entities or operations. There is no such actual relationship or sequence. Furthermore, the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus comprising a set of elements includes not only those elements, but also includes elements not expressly listed. other elements of or also include elements inherent in such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional same elements in the process, method, article or apparatus comprising said element.
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储在计算机可读取的存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质中。Those of ordinary skill in the art can understand that all or part of the steps to realize the above method embodiments can be completed by program instructions related hardware, and the aforementioned programs can be stored in a computer-readable storage medium. When the program is executed, the It includes the steps of the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.
最后需要说明的是:以上所述仅为本发明的较佳实施例,仅用于说明本发明的技术方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内所做的任何修改、等同替换、改进等,均包含在本发明的保护范围内。Finally, it should be noted that the above descriptions are only preferred embodiments of the present invention, and are only used to illustrate the technical solution of the present invention, and are not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present invention are included in the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610606319.8A CN106294130A (en) | 2016-07-28 | 2016-07-28 | A kind of unit test method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610606319.8A CN106294130A (en) | 2016-07-28 | 2016-07-28 | A kind of unit test method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106294130A true CN106294130A (en) | 2017-01-04 |
Family
ID=57663232
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610606319.8A Pending CN106294130A (en) | 2016-07-28 | 2016-07-28 | A kind of unit test method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106294130A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106874202A (en) * | 2017-02-14 | 2017-06-20 | 网易无尾熊(杭州)科技有限公司 | Method, device and readable storage medium storing program for executing for unit testing |
CN113360363A (en) * | 2020-03-04 | 2021-09-07 | 腾讯科技(深圳)有限公司 | Test method, device, equipment and computer storage medium for micro service system |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1987821A (en) * | 2006-11-14 | 2007-06-27 | 无敌科技(西安)有限公司 | Method and system for realizing unit test |
CN101183332A (en) * | 2007-11-21 | 2008-05-21 | 北京中星微电子有限公司 | Method and device for automatically generating testing datasets by program content |
US20120330598A1 (en) * | 2011-03-04 | 2012-12-27 | International Business Machines Corporation | Method, program, and system for generating test cases |
CN103617120A (en) * | 2013-12-05 | 2014-03-05 | 北京奇虎科技有限公司 | Unit testing method and device |
CN103778052A (en) * | 2012-10-17 | 2014-05-07 | 百度在线网络技术(北京)有限公司 | Method and device for front end javascript code testing |
CN104268073A (en) * | 2014-09-05 | 2015-01-07 | 北京广利核系统工程有限公司 | Method for generating test cases in batch mode |
CN105468525A (en) * | 2015-11-27 | 2016-04-06 | 苏州同元软控信息技术有限公司 | Component interface unit testing method based on C code model |
-
2016
- 2016-07-28 CN CN201610606319.8A patent/CN106294130A/en active Pending
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1987821A (en) * | 2006-11-14 | 2007-06-27 | 无敌科技(西安)有限公司 | Method and system for realizing unit test |
CN101183332A (en) * | 2007-11-21 | 2008-05-21 | 北京中星微电子有限公司 | Method and device for automatically generating testing datasets by program content |
US20120330598A1 (en) * | 2011-03-04 | 2012-12-27 | International Business Machines Corporation | Method, program, and system for generating test cases |
CN103778052A (en) * | 2012-10-17 | 2014-05-07 | 百度在线网络技术(北京)有限公司 | Method and device for front end javascript code testing |
CN103617120A (en) * | 2013-12-05 | 2014-03-05 | 北京奇虎科技有限公司 | Unit testing method and device |
CN104268073A (en) * | 2014-09-05 | 2015-01-07 | 北京广利核系统工程有限公司 | Method for generating test cases in batch mode |
CN105468525A (en) * | 2015-11-27 | 2016-04-06 | 苏州同元软控信息技术有限公司 | Component interface unit testing method based on C code model |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106874202A (en) * | 2017-02-14 | 2017-06-20 | 网易无尾熊(杭州)科技有限公司 | Method, device and readable storage medium storing program for executing for unit testing |
CN113360363A (en) * | 2020-03-04 | 2021-09-07 | 腾讯科技(深圳)有限公司 | Test method, device, equipment and computer storage medium for micro service system |
CN113360363B (en) * | 2020-03-04 | 2024-04-02 | 腾讯科技(深圳)有限公司 | Method, device, equipment and computer storage medium for testing micro service system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9158514B2 (en) | Method and apparatus for providing change-related information | |
CN102880546B (en) | Software integration testing method and system based on extensible markup language (XML) database | |
US8417998B2 (en) | Targeted black box fuzzing of input data | |
US10049031B2 (en) | Correlation of violating change sets in regression testing of computer software | |
CN105302719B (en) | A kind of mutation testing method and device | |
JP7110789B2 (en) | Selection of automated software program repair candidates | |
US10592703B1 (en) | Method and system for processing verification tests for testing a design under test | |
US20150143179A1 (en) | System and Method for Progressive Fault Injection Testing | |
JP6976064B2 (en) | Data structure abstraction for model checking | |
CN112463586B (en) | Method and medium for automatically generating application program interface test case | |
CN107329889B (en) | A method of automatic testing of C compiler | |
CN110419031B (en) | Code coverage tracking for microcontroller programs | |
JP7384054B2 (en) | automated software program repair | |
CN106294130A (en) | A kind of unit test method and device | |
JP2020129372A (en) | Automated software program repair | |
US10481969B2 (en) | Configurable system wide tests | |
CN107247663B (en) | A method for identifying redundant variants | |
CN118939559A (en) | Data testing method, device, storage medium and computer program product | |
US10579761B1 (en) | Method and system for reconstructing a graph presentation of a previously executed verification test | |
JP4957521B2 (en) | Software partial test system, method and program used therefor | |
TW202307670A (en) | Device and method for automated generation of parameter testing requests | |
CN113778884A (en) | Simulation debugging method and device, computing equipment and computer storage medium | |
US10803219B1 (en) | Method and system for combined formal static analysis of a design code | |
CN104636258B (en) | Towards the credible method of testing of restructural support programs | |
CN117313596B (en) | Method, equipment and storage medium for positioning errors of logic system design |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
WD01 | Invention patent application deemed withdrawn after publication | ||
WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20170104 |