[go: up one dir, main page]

CN102708052B - Software fault automatic positioning method in a kind of unit testing - Google Patents

Software fault automatic positioning method in a kind of unit testing Download PDF

Info

Publication number
CN102708052B
CN102708052B CN201210127772.2A CN201210127772A CN102708052B CN 102708052 B CN102708052 B CN 102708052B CN 201210127772 A CN201210127772 A CN 201210127772A CN 102708052 B CN102708052 B CN 102708052B
Authority
CN
China
Prior art keywords
execution
mrow
edge
suspicious
msub
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.)
Expired - Fee Related
Application number
CN201210127772.2A
Other languages
Chinese (zh)
Other versions
CN102708052A (en
Inventor
王雅文
宫云战
韩春晓
黄俊飞
金大海
唐容
蔡敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing University of Posts and Telecommunications
Original Assignee
Beijing University of Posts and Telecommunications
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing University of Posts and Telecommunications filed Critical Beijing University of Posts and Telecommunications
Priority to CN201210127772.2A priority Critical patent/CN102708052B/en
Publication of CN102708052A publication Critical patent/CN102708052A/en
Application granted granted Critical
Publication of CN102708052B publication Critical patent/CN102708052B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

本发明提供了一种单元测试中软件故障自动定位方法,包括:A、采用一组满足覆盖需求的测试用例,执行被测程序,判断测试用例的执行结果是否和预期结果一致;B、根据各测试用例对应的执行路径,分析路径上的边信息,确定由路径上的边组成的可疑空间;C、统计可疑空间中每条边被通过和未通过的测试用例覆盖的次数,计算指定执行模式下,每条边的可疑度;D、由边的可疑度计算其相邻语句节点的可疑度;E、按照可疑度的大小对故障节点进行排序,并依次映射到被测程序中生成故障定位报告,辅助用户检查故障。采用本方法,能够降低语句分析的计算工作量,并且考虑到语句节点之间的逻辑关系,提高故障定位的效率。

The present invention provides a method for automatically locating software faults in unit tests, comprising: A. using a group of test cases that meet the coverage requirements, executing the program to be tested, and judging whether the execution results of the test cases are consistent with the expected results; B. according to each The execution path corresponding to the test case, analyze the edge information on the path, and determine the suspicious space composed of the edges on the path; C, count the number of times each edge in the suspicious space is covered by the passed and failed test cases, and calculate the specified execution mode Next, the suspiciousness of each edge; D. Calculate the suspiciousness of its adjacent statement nodes from the suspiciousness of the edge; E. Sort the fault nodes according to the suspiciousness, and map them to the tested program in turn to generate fault location report, assisting users to check faults. By adopting the method, the calculation workload of statement analysis can be reduced, and the efficiency of fault location can be improved by taking into account the logical relationship between statement nodes.

Description

一种单元测试中软件故障自动定位方法A method for automatically locating software faults in unit testing

技术领域technical field

本方法涉及软件测试中的故障定位技术,尤其涉及一种单元测试中软件故障自动定位方法,通过执行测试用例,根据执行结果与预期的测试结果是否一致,对软件中存在的故障进行自动定位。The method relates to a fault location technology in software testing, in particular to a method for automatically locating software faults in unit testing, by executing a test case and according to whether the execution result is consistent with the expected test result, the fault in the software is automatically located.

背景技术Background technique

软件故障是一种动态行为,出现软件故障时若无适当措施加以及时处理,便会产生软件失效。单元测试中尽可能早的发现和排除尽可能多的故障,便会减少和避免后期浪费太多的不值得的时间。Software failure is a dynamic behavior. If there is no appropriate measure to deal with it in time when a software failure occurs, software failure will occur. Finding and eliminating as many faults as possible in unit testing as early as possible will reduce and avoid wasting too much unworthy time later.

目前关于软件故障定位技术的研究,大多是根据执行结果是否通过,以程序语句作为覆盖节点进行统计分析。当程序代码较多时,语句分析的计算量较大,造成大量时间耗费,且未考虑故障的传播对定位的干扰,影响故障定位的准确率。At present, the research on software fault location technology is mostly based on whether the execution result is passed or not, and the program statement is used as the coverage node for statistical analysis. When there are many program codes, the amount of calculation for statement analysis is large, resulting in a lot of time-consuming, and the interference of fault propagation on location is not considered, which affects the accuracy of fault location.

发明内容Contents of the invention

有鉴于此,本发明的主要目的在于提供一种单元测试中软件故障自动定位方法,以克服现有软件故障定位方法中以语句节点为覆盖单位、计算量大而且没有考虑到语句节点之间的联系的缺陷,降低语句分析的计算工作量,并且考虑到语句节点之间的逻辑关系,提高故障定位的效率。In view of this, the main purpose of the present invention is to provide a method for automatically locating software faults in unit tests, to overcome the fact that the existing software fault locating methods take statement nodes as coverage units, have a large amount of calculation and do not take into account the relationship between statement nodes. It reduces the computational workload of statement analysis and improves the efficiency of fault location by taking into account the logical relationship between statement nodes.

为达到上述目的,本发明的技术方案是这样实现的:In order to achieve the above object, technical solution of the present invention is achieved in that way:

一种单元测试中软件故障自动定位方法,该方法包括:A method for automatically locating software faults in unit testing, the method comprising:

A、采用一组满足覆盖需求的测试用例,执行被测程序,判断测试用例的执行结果是否和预期结果一致;A. Use a group of test cases that meet the coverage requirements, execute the program under test, and judge whether the execution results of the test cases are consistent with the expected results;

B、根据各测试用例对应的执行路径,分析路径上的边信息,确定由路径上的边组成的可疑空间;B. According to the execution path corresponding to each test case, analyze the edge information on the path, and determine the suspicious space composed of the edges on the path;

C、统计可疑空间中各条边被通过和未通过的测试用例覆盖的次数,计算指定执行模式下,各条边的可疑度;C. Count the number of times each edge in the suspicious space is covered by passed and failed test cases, and calculate the suspiciousness of each edge in the specified execution mode;

D、由上述步骤得到的边的可疑度计算其相邻语句节点的可疑度;D, the suspicious degree calculation of its adjacent sentence node by the suspicious degree of the edge that above-mentioned steps obtains;

E、根据相邻语句节点的可疑度大小对故障节点进行排序,并依次映射到被测程序中生成故障定位报告,辅助用户检查故障。E. Sort the faulty nodes according to the suspiciousness of adjacent statement nodes, and map them to the tested program in turn to generate a fault location report to assist users in checking faults.

其中:所述步骤A包括:Wherein: described step A comprises:

A1、基于两种执行模式进行故障定位,分别是全用例执行模式和部分用例执行模式;A1. Fault location based on two execution modes, which are full use case execution mode and partial use case execution mode;

A2、采用全用例执行模式时,将一组测试用例全部执行,根据执行结果是否和预期一致,将用例划分为互不相容的两部分,即通过的测试用例和未通过的测试用例,并记录对应执行路径包含的边信息;A2. When using the full-use-case execution mode, execute all the test cases in a group, and divide the use cases into two mutually incompatible parts according to whether the execution results are consistent with expectations, that is, the passed test cases and the failed test cases, and Record the side information contained in the corresponding execution path;

A3、采用部分用例执行模式时,随机选择测试用例集合中的某个用例开始执行,判断执行结果是否和预期结果一致,直到有测试用例的执行结果和预期不一致时停止测试,将此时执行过的测试用例分为两部分,即前m个通过的测试用例和第m+1个未通过的测试用例,获取对应的执行路径;A3. When using the partial use case execution mode, randomly select a use case in the test case set to start execution, judge whether the execution result is consistent with the expected result, and stop the test until the execution result of the test case is inconsistent with the expected result. The test case of is divided into two parts, that is, the first m passed test cases and the m+1th failed test case, and the corresponding execution path is obtained;

A4、执行结果包括如下内容:函数具有返回值,记录其返回结果;关键的中间变量和全局变量,记录其返回值;含有文件操作时,记录生成的文件目录和内容信息;含有数据库操作时,记录生成的数据库目录和内容信息。A4. The execution results include the following content: the function has a return value, record its return result; key intermediate variables and global variables, record its return value; when it contains file operations, record the generated file directory and content information; when it contains database operations, Record the generated database directory and content information.

所述步骤B包括:Described step B comprises:

B1、可疑空间由指定执行模式下某些测试用例对应的执行路径包含的边组成,是判断故障发生的最大范围,取可疑空间的边进行后续步骤的可疑度计算,不同的执行模式,可疑空间则不同。B1. The suspicious space is composed of the edges included in the execution path corresponding to some test cases in the specified execution mode. It is the maximum range for judging the occurrence of faults. The suspicious space is taken from the edges of the suspicious space to calculate the suspiciousness of the subsequent steps. Different execution modes, suspicious space is different.

其中,所述步骤B1进一步包括:Wherein, the step B1 further includes:

B11、全用例执行模式下,所有未通过的测试用例对应的执行路径包含的边集合一定存在故障,将此作为最大的可疑空间,用来进行该执行模式在后面步骤的可疑度计算;B11. In the full use case execution mode, there must be faults in the edge sets contained in the execution paths corresponding to all failed test cases, and this is used as the largest suspicious space to calculate the suspiciousness of the execution mode in the subsequent steps;

B12、部分用例执行模式下,第m+1个未通过的测试用例对应的执行路径一定存在故障,将此路径上的边集合作为该执行模式下的可疑空间;B12. In the partial use case execution mode, there must be a fault in the execution path corresponding to the m+1th failed test case, and the set of edges on this path is taken as the suspicious space in this execution mode;

所述步骤C包括:Described step C comprises:

C1、全用例执行模式下,遍历可疑空间,统计出覆盖了边的测试用例的个数,结合通过和未通过的测试用例总个数,采用Tarantula方法对边计算可疑度,计算如下:C1. In the full use case execution mode, traverse the suspicious space and count the covered edges The number of test cases, combined with the total number of test cases that pass and fail, uses the Tarantula method to calculate the suspiciousness of the edge, and the calculation is as follows:

其中:为所有未通过的测试用例个数;in: is the number of all failed test cases;

为所有通过的测试用例个数; is the number of all passed test cases;

为通过的测试用例中,其对应的执行路径包含了边的用例个数; In the test case that is passed, its corresponding execution path contains the edge the number of use cases;

为未通过的测试用例中,其对应的执行路径包含了边的用例个数; For the failed test case, its corresponding execution path contains the edge the number of use cases;

C2、部分用例执行模式下,对步骤B12得到的可疑空间,即未通过的测试用例对应的执行路径上的边集合遍历,统计前m个通过的测试用例中,覆盖了指定边的用例个数,利用下面公式计算其可疑度:C2. In the partial use case execution mode, traverse the suspicious space obtained in step B12, that is, the edge set on the execution path corresponding to the failed test cases, and count the number of use cases that cover the specified edge among the first m passed test cases , using the following formula to calculate its suspiciousness:

;

其中,为第m+1个测试用例对应的执行路径上的某条边;in, is an edge on the execution path corresponding to the m+1th test case;

为所有通过的测试用例个数; is the number of all passed test cases;

为通过的测试用例中,其对应的执行路径包含了边的用例个数。 In the test case that is passed, its corresponding execution path contains the edge number of use cases.

所述步骤D包括:Said step D comprises:

D1、全用例执行模式下,对所有未通过的测试用例对应的执行路径包含的边的相邻节点进行分析,取节点的所有入边可疑度的最大值与所有出边可疑度的最大值的平均值,作为该节点的可疑度;D1. In the full use case execution mode, analyze the adjacent nodes of the edges included in the execution path corresponding to all failed test cases, and take the maximum value of all incoming edge suspiciousness of the node and the maximum value of all outgoing edge suspiciousness Average value, as the suspicious degree of the node;

D2、部分用例执行模式下,对未通过的测试用例对应的执行路径上的边的相邻节点进行分析,取节点的入边可疑度与出边可疑度的平均值,作为该节点的可疑度;D2. In the partial use case execution mode, analyze the adjacent nodes of the edge on the execution path corresponding to the failed test case, and take the average value of the suspicious degree of the incoming edge and outgoing edge of the node as the suspicious degree of the node ;

D3、对于只有出边或者只有入边的节点(比如程序入口节点或程序出口节点),其出边可疑度或入边可疑度作为该节点可疑度;对于控制流图上没有统计到的节点,可疑度记为零。D3. For a node with only outgoing edges or only incoming edges (such as program entry nodes or program exit nodes), its outgoing edge suspiciousness or incoming edge suspiciousness is taken as the suspicious degree of the node; for nodes that are not counted on the control flow graph, Suspiciousness is recorded as zero.

所述步骤E包括:Described step E comprises:

E1、故障定位报告,包含以下内容:对语句节点按照上述步骤得到的节点可疑度数值大小进行排序,每一项包括节点可疑度数值,节点名称和标号,节点对应在被测程序中的语句行号;E1. Fault location report, including the following content: sort the statement nodes according to the node suspicious degree value obtained by the above steps, each item includes the node suspicious degree value, node name and label, and the node corresponds to the statement line in the program under test No;

E2、每次取可疑度最高的节点,映射到被测程序中的语句,将语句用高亮颜色显示,便于用户检查,直到找出故障位置。E2. Take the node with the highest suspicious degree each time, map it to the statement in the program under test, and display the statement in a highlighted color, which is convenient for the user to check until the fault location is found.

本发明所提供的单元测试中软件故障自动定位方法,具有以下优点:The method for automatically locating software faults in unit tests provided by the present invention has the following advantages:

本发明的软件故障定位方法,采取以边为覆盖单位进行可疑度的计算,并由边的可疑度计算得到节点可疑度,实验证明,采用本发明方法能够大大减少计算量,提高分析的效率,同时考虑到节点的逻辑关系,即故障的传播对程序执行结果的影响,使得定位的准确率更高。The software fault location method of the present invention adopts the calculation of the suspicious degree with the edge as the coverage unit, and calculates the suspicious degree of the node by calculating the suspicious degree of the edge. The experiment proves that the calculation amount can be greatly reduced by the method of the present invention, and the efficiency of analysis can be improved. At the same time, considering the logical relationship of nodes, that is, the influence of fault propagation on program execution results, the accuracy of positioning is higher.

附图说明Description of drawings

图1为本发明中基于两种执行模式进行故障定位的示意图;Fig. 1 is a schematic diagram of fault location based on two execution modes in the present invention;

图2为本发明中基于两种执行模式进行故障定位的整体流程图。FIG. 2 is an overall flowchart of fault location based on two execution modes in the present invention.

具体实施方式detailed description

下面结合附图及本发明的实施例对本发明的方法作进一步详细的说明。The method of the present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments of the present invention.

本发明的单元测试中软件故障自动定位方法,提出一种多类型覆盖下基于两种执行模式的单元测试中故障自动定位技术,两种执行模式分别从用户的角度进行考虑。对于全自动模式,一组测试用例会被同时执行,而更常见的情况是,一旦执行到某一条错误的测试用例,测试即被停止进行故障的查找,因此本发明的方法能够分别对两种执行模式进行软件故障的自动定位。以程序对应控制流图上的边为覆盖单位,程序发生故障,路径执行轨迹也必然发生改变,采用两种测试用例的执行方式,对路径上的边被测试用例执行情况进行统计,计算得到边的可疑度,然后由边的可疑度计算相邻语句节点的可疑度,一方面减少了以语句为覆盖单位时的大量计算;另一方面,由于一条边不仅包含首尾两个语句节点,同时也代表了语句节点之间的逻辑和依赖关系,以边为单位统计的方法考虑了语句节点之间的联系,从而提高了定位效率。同时,本方法采用的测试用例可以满足多种覆盖需求(语句覆盖、分支覆盖、MC/DC覆盖等)进行生成,为各种覆盖的定位效率分析提供了依据,并且可扩展性强。The method for automatically locating software faults in unit tests of the present invention proposes an automatic fault locating technology in unit tests based on two types of execution modes under multi-type coverage, and the two execution modes are considered from the perspective of users respectively. For the full-automatic mode, a group of test cases can be executed simultaneously, and the more common situation is that once a certain wrong test case is executed, the test is stopped to search for the fault, so the method of the present invention can respectively treat the two kinds of test cases. Execution mode for automatic location of software faults. Taking the edge on the control flow graph corresponding to the program as the coverage unit, if the program fails, the path execution trajectory will inevitably change. Using two test case execution methods, the edge on the path is counted on the execution of the test case, and the edge is calculated. , and then calculate the suspiciousness of adjacent statement nodes based on the suspiciousness of the edge. Represents the logic and dependency relationship between statement nodes, and the method of counting in units of edges considers the connection between statement nodes, thereby improving the positioning efficiency. At the same time, the test cases used in this method can meet various coverage requirements (statement coverage, branch coverage, MC/DC coverage, etc.) to generate, which provides a basis for the location efficiency analysis of various coverage, and has strong scalability.

图1为本发明中基于两种执行模式进行故障定位的示意图,如图1所示,本发明提出的单元测试中故障自动定位方法,其基本思想是:首先对被测程序生成一组满足指定覆盖准则和覆盖率需求的测试用例,基于两种执行模式,执行被测程序,然后判断执行结果是否和预期结果一致,将执行结果标记为通过和未通过,在指定执行模式下,获取由执行路径上包含的边组成的可疑空间,统计边覆盖的次数,计算可疑空间每条边的可疑度,然后,由边的可疑度计算出相邻语句节点的可疑度,最后,按可疑度大小对边和语句节点进行排序,生成故障定位报告,辅助用户依次排查。Fig. 1 is a schematic diagram of fault location based on two execution modes in the present invention. As shown in Fig. 1, the basic idea of the automatic fault location method in the unit test proposed by the present invention is: first, generate a set of specified The test case of coverage criteria and coverage requirements, based on two execution modes, executes the program under test, then judges whether the execution result is consistent with the expected result, and marks the execution result as pass or fail. The suspicious space composed of the edges contained in the path counts the times of edge coverage, and calculates the suspicious degree of each edge in the suspicious space. Then, calculates the suspicious degree of adjacent statement nodes according to the suspicious degree of the edge, and finally, according to the suspicious degree The edge and statement nodes are sorted, and a fault location report is generated to assist users in troubleshooting in sequence.

如图1所示,该方法主要包括如下过程:As shown in Figure 1, the method mainly includes the following processes:

步骤1:采用一组满足覆盖需求(语句、分支、MC/DC等)的测试用例,执行被测程序,判断测试用例的执行结果是否和预期结果一致;Step 1: Use a set of test cases that meet the coverage requirements (statements, branches, MC/DC, etc.), execute the program under test, and judge whether the execution results of the test cases are consistent with the expected results;

步骤2:根据各测试用例对应的执行路径,分析路径上的边信息,确定由路径上的边组成的可疑空间;Step 2: According to the execution path corresponding to each test case, analyze the edge information on the path, and determine the suspicious space composed of the edges on the path;

步骤3:统计可疑空间中各条边被通过和未通过的测试用例覆盖的次数,计算指定执行模式下(全用例执行和部分用例执行),各条边的可疑度;Step 3: Count the number of times each edge in the suspicious space is covered by passed and failed test cases, and calculate the suspiciousness of each edge under the specified execution mode (full use case execution and partial use case execution);

步骤4:由上述步骤得到的边的可疑度计算其相邻语句节点的可疑度;Step 4: Calculate the suspiciousness of its adjacent sentence nodes by the suspiciousness of the edge obtained in the above steps;

步骤5:按照可疑度大小对故障节点进行排序,并依次映射到被测程序中生成故障定位报告,辅助用户检查故障。Step 5: Sort the fault nodes according to the degree of suspiciousness, and map them to the program under test in turn to generate a fault location report to assist users in checking faults.

结合上述过程,下面对本发明提出的单元测试中故障自动定位方法进行进一步的详细说明,图2为本发明的整体流程图,如图2所示,该方法包括:In conjunction with the above-mentioned process, the fault automatic location method in the unit test proposed by the present invention is further described in detail below. Fig. 2 is an overall flow chart of the present invention. As shown in Fig. 2, the method includes:

步骤1:根据不同的覆盖准则(如语句、分支、MC/DC等),生成一组满足覆盖需求的测试用例。Step 1: According to different coverage criteria (such as statement, branch, MC/DC, etc.), generate a set of test cases that meet the coverage requirements.

这里,需要对被测程序进行静态分析并生成控制流图,根据指定的覆盖准则对被测程序进行插装,由此生成一组满足覆盖需求的测试用例,各测试用例对应的执行路径没有重复,即用例没有冗余。Here, it is necessary to statically analyze the program under test and generate a control flow graph, and then instrument the program under test according to the specified coverage criteria, thereby generating a set of test cases that meet the coverage requirements, and the execution paths corresponding to each test case are not repeated , that is, the use case has no redundancy.

便于下面步骤说明,生成的一组测试用例记作,测试用例对应的执行路径记作,以控制流图上的边为单位,路径可以表示为For the convenience of the following steps, the generated set of test cases is denoted as , the test case The corresponding execution path is denoted as , taking the edge on the control flow graph as the unit, the path can be expressed as .

步骤2:用上述步骤1生成的测试用例执行被测程序,判断测试用例的执行结果是否和预期结果一致,根据各测试用例对应的执行路径,分析路径上的边信息,确定由路径上的边组成的可疑空间,执行结果不仅仅是被测程序的返回值,如果存在文件、数据库、指针等操作,由这些操作生成的文件目录和内容信息也作为执行结果的一部分。Step 2: Use the test case generated in the above step 1 to execute the program under test, judge whether the execution result of the test case is consistent with the expected result, analyze the edge information on the path according to the execution path corresponding to each test case, and determine the edge information on the path The execution result is not only the return value of the program under test. If there are operations such as files, databases, and pointers, the file directory and content information generated by these operations are also part of the execution result.

假设步骤1所述生成的测试用例表示为,本方法基于两种执行模式进行故障定位,分别是全用例执行模式和部分用例执行模式。Assume that the test case generated as described in step 1 is expressed as , this method performs fault location based on two execution modes, which are full use case execution mode and partial use case execution mode.

步骤21:采用全用例执行模式时,将步骤1得到的一组测试用例全部执行,根据执行结果是否和预期一致,将用例划分为互不相容的两部分,即通过的测试用例和未通过的测试用例,并记录对应执行路径包含的边信息。Step 21: When using the full use case execution mode, execute all the test cases obtained in step 1, and divide the use cases into two mutually incompatible parts according to whether the execution results are consistent with expectations, that is, the passed test cases and the failed test case , and record the side information contained in the corresponding execution path.

步骤22:采用部分用例执行模式时,随机选择步骤1生成的测试用例集合中的某个用例开始执行,判断执行结果是否和预期结果一致,直到某个用例(假设为第m+1个用例)的执行结果和预期不一致时停止测试,此时执行过的测试用例分为两部分,即前m个通过的测试用例,表示为,和第m+1个未通过的测试用例,表示为,获取它们的执行路径。Step 22: When using partial use case execution mode, randomly select a use case in the test case set generated in step 1 to start execution, and judge whether the execution result is consistent with the expected result until a certain use case (assumed to be the m+1th use case) ) when the execution result is inconsistent with the expectation, the test is stopped. At this time, the executed test cases are divided into two parts, that is, the first m passed test cases, expressed as , and the m+1th failed test case, denoted as , to get their execution paths.

上述步骤中,根据测试用例是否通过,可得到分别对应的路径信息,表示如下:In the above steps, according to whether the test case is passed or not, we can get with The corresponding path information is as follows:

,表示通过的测试用例对应的路径集合; , indicating the set of paths corresponding to the passed test cases;

,表示未通过的测试用例对应的路径集合。 , representing the set of paths corresponding to the failed test cases.

可疑空间由指定执行模式下某些测试用例对应的执行路径包含的边组成,是判断故障发生的最大范围,取可疑空间的边进行后面步骤的可疑度计算。不同的执行模式,可疑空间不同。具体如下:The suspicious space is composed of the edges included in the execution paths corresponding to some test cases in the specified execution mode, which is the maximum range for judging the occurrence of faults, and the suspicious space is taken to calculate the suspiciousness in the following steps. Different execution modes have different suspicious spaces. details as follows:

步骤211:全用例执行模式下,所有未通过的测试用例对应的执行路径一定存在故障,路径上的边的交集组成该执行模式下的可疑空间,表示如下;Step 211: In the all-case execution mode, there must be faults in the execution paths corresponding to all failed test cases, and the intersection of edges on the paths constitutes a suspicious space in this execution mode, which is expressed as follows;

.

步骤221:部分用例执行模式下,假设前m个用例的执行结果正确,那么第m+1个用例对应的执行路径一定存在故障,该路径上的边组成该执行模式下的可疑空间,表示如下;Step 221: In partial use case execution mode, assume the first m use cases The execution result of is correct, then the m+1th use case There must be a fault in the corresponding execution path, and the edges on the path constitute the suspicious space in the execution mode, which is expressed as follows;

.

步骤3:统计可疑空间中各条边被通过和未通过的测试用例覆盖的次数,计算指定执行模式下,各条边的可疑度,执行模式不同,可疑度的计算公式也不同,具体如下:Step 3: Count the number of times each edge in the suspicious space is covered by passed and failed test cases, and calculate the suspiciousness of each edge in the specified execution mode. The calculation formula of suspiciousness is different for different execution modes, as follows:

步骤31:全用例执行模式下,遍历步骤211得到的可疑空间,统计出覆盖了边的测试用例的个数,结合通过和未通过的测试用例总个数,采用Tarantula方法对边计算可疑度,计算如下:Step 31: In the full use case execution mode, traverse the suspicious space obtained in step 211, and count the covered edges The number of test cases, combined with the total number of test cases that pass and fail, uses the Tarantula method to calculate the suspiciousness of the edge, and the calculation is as follows:

;

其中:表示未通过的测试用例集包含的用例总个数;in: Represents the set of test cases that failed The total number of use cases included;

表示通过的测试用例集包含的用例总个数; Indicates the set of test cases that passed The total number of use cases included;

表示通过的测试用例中,其对应的执行路径包含了边的用例个数; Indicates that in the passed test case, the corresponding execution path contains the edge the number of use cases;

表示未通过的测试用例中,其对应的执行路径包含了边的用例个数。 Indicates that in the failed test case, the corresponding execution path contains the edge number of use cases.

步骤32:部分用例执行模式下,遍历步骤221得到的可疑空间,即未通过的测试用例对应的执行路径上的边集合,统计前m个通过的测试用例中,覆盖了指定边的用例个数,利用下面公式计算其可疑度:Step 32: In partial use case execution mode, traverse the suspicious space obtained in step 221, that is, the set of edges on the execution path corresponding to the failed test cases, and count the number of use cases that cover the specified edge among the first m passed test cases , using the following formula to calculate its suspiciousness:

其中,表示第m+1个测试用例对应的执行路径上的某条边;in, Indicates an edge on the execution path corresponding to the m+1th test case;

表示所有通过的测试用例个数; Indicates the number of all passed test cases;

表示通过的测试用例中,其对应的执行路径包含了边的用例个数。 Indicates that in the passed test case, the corresponding execution path contains the edge number of use cases.

步骤4:由上述步骤得到的边的可疑度,计算其相邻语句节点的可疑度;Step 4: Calculate the suspiciousness of its adjacent statement nodes from the suspiciousness of the edge obtained in the above steps;

步骤41:全用例执行模式下,对所有未通过的测试用例对应的执行路径包含的边的相邻节点进行分析,取节点的所有入边可疑度的最大值与所有出边可疑度的最大值的平均值,作为该节点的可疑度。Step 41: In the full use case execution mode, analyze the adjacent nodes of the edges included in the execution path corresponding to all failed test cases, and take the maximum value of all incoming edge suspiciousness and the maximum value of all outgoing edge suspiciousness of the node The average value of , as the suspicious degree of the node.

假设节点集合记作,对其中每个节点的可疑度计算如下:Assume that the set of nodes is denoted as , for each node Suspiciousness is calculated as follows:

其中,表示节点所有入边中可疑度的最大值, in, Indicates the maximum value of suspiciousness among all incoming edges of a node, ;

表示节点所有入边中可疑度的最大值, Indicates the maximum value of suspiciousness among all incoming edges of a node, .

步骤42:部分用例执行模式下,对未通过的测试用例对应的执行路径上的边的相邻节点进行分析,取节点的入边可疑度与出边可疑度的平均值,作为该节点的可疑度。Step 42: In the partial use case execution mode, analyze the adjacent nodes of the edge on the execution path corresponding to the failed test case, and take the average value of the suspiciousness of the incoming edge and outgoing edge of the node as the suspiciousness of the node. Spend.

假设节点集合记作,节点的入边记作,出边记作,可疑度计算如下:Assume that the set of nodes is denoted as ,node entry , denoted as , the suspiciousness is calculated as follows:

.

步骤43:对于只有出边或者只有入边的节点(比如程序入口节点或程序出口节点),其出边可疑度或入边可疑度作为该节点可疑度;对于控制流图上没有被统计到的节点,表示入边和出边均未在可疑空间中,该节点可疑度记为零。Step 43: For nodes with only outgoing edges or incoming edges (such as program entry nodes or program exit nodes), the suspicious degree of outgoing edges or incoming edges is taken as the suspicious degree of the node; for the nodes that are not counted on the control flow graph Node, indicating that neither the incoming edge nor the outgoing edge is in the suspicious space, and the suspiciousness of this node is recorded as zero.

步骤5:将故障节点按可疑度大小进行排序,并依次映射到被测程序中,将语句用高亮颜色显示,并生成故障定位报告,辅助用户检查故障。Step 5: Sort the fault nodes according to the degree of suspiciousness, and map them to the program under test in turn, display the statement in a highlighted color, and generate a fault location report to assist users in checking faults.

故障定位报告,可以包含以下内容:对步骤4得到的故障节点,按照可疑度大小进行排序,每一项包括节点可疑度数值,节点名称和标号,节点对应在被测程序中的语句行号等。The fault location report can include the following content: sort the faulty nodes obtained in step 4 according to the degree of suspiciousness, and each item includes the value of the suspicious degree of the node, the name and label of the node, the line number of the statement corresponding to the node in the program under test, etc. .

以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention.

Claims (6)

1. A method for automatically positioning software faults in unit test is characterized by comprising the following steps:
A. executing the tested program by adopting a group of test cases meeting the coverage requirement, and judging whether the execution result of the test cases is consistent with the expected result;
B. analyzing side information on the path according to the execution path corresponding to each test case, and determining a suspicious space formed by the sides on the path;
C. counting the times of covering each edge in the suspicious space by the passed test case and the failed test case, and calculating the suspicious degree of each edge in the specified execution mode;
D. calculating the suspicious degree of the adjacent statement nodes according to the suspicious degree of the edges obtained in the step;
E. sequencing the fault nodes according to the size of the suspicious degree of the adjacent statement nodes, sequentially mapping the fault nodes to a tested program to generate a fault positioning report, and assisting a user in checking the fault;
the step B comprises the following steps:
b1, the suspicious space is composed of edges contained in execution paths corresponding to some test cases under the appointed execution mode, the maximum range of the fault is judged, the edges of the suspicious space are taken to carry out suspicious degree calculation of the subsequent steps, and the suspicious space is different in different execution modes.
2. The method for automatically locating software faults in a unit test according to claim 1, wherein the step A comprises the following steps:
a1, fault location is carried out based on two execution modes, namely a full use case execution mode and a partial use case execution mode;
a2, when a full-case execution mode is adopted, a group of test cases are completely executed, the cases are divided into two mutually incompatible parts according to whether the execution result is consistent with the expectation, namely, the passed test cases and the failed test cases, and the side information contained in the corresponding execution path is recorded;
a3, when a partial case execution mode is adopted, randomly selecting a certain case in the test case set to start execution, judging whether an execution result is consistent with an expected result or not, stopping testing until the execution result of the test case is inconsistent with the expected result, dividing the test case executed at the moment into two parts, namely the first m passed test cases and the (m + 1) th failed test cases, and acquiring a corresponding execution path;
a4, the execution result comprises the following contents: the function has a return value and records the return result; recording return values of key intermediate variables and global variables; when the file operation is contained, recording the generated file directory and content information; and when the database operation is contained, recording the generated database catalog and content information.
3. The method for automatically locating software failure in unit test according to claim 2, wherein said step B1 further comprises:
b11, under the execution mode of all cases, the edge set contained in the execution path corresponding to all the failed test cases has certain faults, and the fault is used as the maximum suspicious space for carrying out the suspicious degree calculation of the execution mode in the following steps;
b12, under the partial case execution mode, the execution path corresponding to the m +1 th failed test case has a fault, and the edge set on the path is taken as a suspicious space under the execution mode.
4. The method for automatically locating software faults in a unit test according to claim 3, wherein the step C comprises the following steps:
c1, under the all-use-case execution mode, traversing the suspicious space and counting the covered edge eiThe total number of the passed test cases and the failed test cases are combined, and the tarandula method is adopted to calculate the suspicion degree on the opposite side, and the calculation is as follows:
<mrow> <mi>s</mi> <mi>u</mi> <mi>s</mi> <mi>p</mi> <mi>i</mi> <mi>c</mi> <mi>i</mi> <mi>o</mi> <mi>u</mi> <mi>s</mi> <mi> </mi> <mi>deg</mi> <mi> </mi> <mi>r</mi> <mi>e</mi> <mi>e</mi> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> <mo>=</mo> <mfrac> <mfrac> <mrow> <msubsup> <mi>N</mi> <mi>f</mi> <mi>c</mi> </msubsup> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> </mrow> <msub> <mi>N</mi> <mi>f</mi> </msub> </mfrac> <mrow> <mfrac> <mrow> <msubsup> <mi>N</mi> <mi>f</mi> <mi>c</mi> </msubsup> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> </mrow> <msub> <mi>N</mi> <mi>f</mi> </msub> </mfrac> <mo>+</mo> <mfrac> <mrow> <msubsup> <mi>N</mi> <mi>p</mi> <mi>c</mi> </msubsup> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> </mrow> <msub> <mi>N</mi> <mi>p</mi> </msub> </mfrac> </mrow> </mfrac> </mrow>
wherein: n is a radical offThe number of all failed test cases is counted;
Npthe number of all passed test cases is counted;
in the passed test case, the corresponding execution path includes edge eiThe number of use cases;
in the failed test case, the corresponding execution path includes the edge eiThe number of use cases;
c2, under the execution mode of partial use cases, counting the number of use cases covering the appointed side in the previous m passed test cases by traversing the suspicious space obtained in the step B12, namely the edge set on the execution path corresponding to the failed test case, and calculating the suspicious degree by using the following formula:
<mrow> <mi>s</mi> <mi>u</mi> <mi>s</mi> <mi>p</mi> <mi>i</mi> <mi>c</mi> <mi>i</mi> <mi>o</mi> <mi>u</mi> <mi>s</mi> <mi> </mi> <mi>deg</mi> <mi> </mi> <mi>r</mi> <mi>e</mi> <mi>e</mi> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> <mo>=</mo> <mn>1</mn> <mo>-</mo> <mfrac> <mrow> <msubsup> <mi>N</mi> <mi>p</mi> <mi>c</mi> </msubsup> <mrow> <mo>(</mo> <msub> <mi>e</mi> <mi>i</mi> </msub> <mo>)</mo> </mrow> </mrow> <msub> <mi>N</mi> <mi>p</mi> </msub> </mfrac> <mo>;</mo> </mrow>
wherein e isiA certain edge on the execution path corresponding to the (m + 1) th test case;
Npthe number of all passed test cases is counted;
in the passed test case, the corresponding execution path includes edge eiThe number of use cases.
5. The method according to claim 4, wherein the step D comprises:
d1, under the execution mode of the all cases, analyzing adjacent nodes of edges contained in the execution paths corresponding to all failed test cases, and taking the average value of the maximum value of all incoming edge suspicions and the maximum value of all outgoing edge suspicions of the nodes as the suspicions of the nodes;
d2, under the execution mode of partial cases, analyzing the adjacent nodes of the edge on the execution path corresponding to the failed test case, and taking the average value of the incoming edge suspicion degree and the outgoing edge suspicion degree of the node as the suspicion degree of the node;
d3, regarding the node only having an outgoing edge or an incoming edge, the outgoing edge suspicion degree or the incoming edge suspicion degree is taken as the node suspicion degree; and for nodes which are not counted on the control flow graph, the suspicious degree is marked as zero.
6. The method for automatically locating software faults in a unit test according to claim 1, wherein the step E comprises the following steps:
e1, fault location report, containing the following: sequencing the sentence nodes according to the node suspicious degree values obtained in the steps, wherein each item comprises the node suspicious degree value, the node name and the label, and the node corresponds to the sentence line number in the tested program;
e2, each time, the node with the highest suspicious degree is taken and mapped to the sentence in the tested program, and the sentence is displayed in highlight color, so that the user can conveniently check the sentence until the fault position is found out.
CN201210127772.2A 2012-04-27 2012-04-27 Software fault automatic positioning method in a kind of unit testing Expired - Fee Related CN102708052B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210127772.2A CN102708052B (en) 2012-04-27 2012-04-27 Software fault automatic positioning method in a kind of unit testing

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210127772.2A CN102708052B (en) 2012-04-27 2012-04-27 Software fault automatic positioning method in a kind of unit testing

Publications (2)

Publication Number Publication Date
CN102708052A CN102708052A (en) 2012-10-03
CN102708052B true CN102708052B (en) 2017-10-20

Family

ID=46900857

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210127772.2A Expired - Fee Related CN102708052B (en) 2012-04-27 2012-04-27 Software fault automatic positioning method in a kind of unit testing

Country Status (1)

Country Link
CN (1) CN102708052B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103268280B (en) * 2013-04-16 2016-01-06 西安电子科技大学 The software fault positioning system combined based on distance metric and statistical study and method
CN104424060B (en) * 2013-08-23 2018-01-23 国际商业机器公司 A kind of method and apparatus for determining failure
CN103593291B (en) * 2013-11-18 2016-03-09 北京邮电大学 For comprising unit test method and the device of multiple function test module
CN104102580B (en) * 2014-07-10 2015-08-26 西安交通大学 A kind of E-Tax system software fault positioning method excavated based on figure
CN104317707B (en) * 2014-10-15 2017-09-29 中国科学院软件研究所 A kind of software error localization method for influenceing to perceive based on program structure
CN105989025A (en) * 2015-01-30 2016-10-05 阿里巴巴集团控股有限公司 Data checking method ad device
CN109992493B (en) * 2017-12-29 2021-12-10 宁波方太厨具有限公司 Test method for eliminating software exception of gas water heater
CN109361531B (en) * 2018-09-04 2021-11-19 瑞斯康达科技发展股份有限公司 Method, system and equipment for reproducing problem of communication equipment which is difficult to reproduce
CN111782532B (en) * 2020-07-02 2022-04-05 北京航空航天大学 A software fault location method and system based on network abnormal node analysis

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101231614A (en) * 2008-02-02 2008-07-30 南京大学 A Software Defect Location Method Based on Execution Trajectory Block Similarity
CN101739339A (en) * 2009-12-29 2010-06-16 北京航空航天大学 Program dynamic dependency relation-based software fault positioning method
CN101866316A (en) * 2010-06-23 2010-10-20 南京大学 A Software Defect Location Method Based on Relatively Redundant Test Set Reduction
CN101901185A (en) * 2010-06-01 2010-12-01 南京大学 An Object-Oriented Program Defect Location Method Based on Class-Organized Execution Tracks
CN102193864A (en) * 2011-05-13 2011-09-21 南京大学 Test case set optimization method of coverage-based error positioning technology

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8943478B2 (en) * 2009-07-14 2015-01-27 International Business Machines Corporation Fault detection and localization in dynamic software applications
US8387018B2 (en) * 2010-09-01 2013-02-26 International Business Machines Corporation Fault localization using directed test generation

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101231614A (en) * 2008-02-02 2008-07-30 南京大学 A Software Defect Location Method Based on Execution Trajectory Block Similarity
CN101739339A (en) * 2009-12-29 2010-06-16 北京航空航天大学 Program dynamic dependency relation-based software fault positioning method
CN101901185A (en) * 2010-06-01 2010-12-01 南京大学 An Object-Oriented Program Defect Location Method Based on Class-Organized Execution Tracks
CN101866316A (en) * 2010-06-23 2010-10-20 南京大学 A Software Defect Location Method Based on Relatively Redundant Test Set Reduction
CN102193864A (en) * 2011-05-13 2011-09-21 南京大学 Test case set optimization method of coverage-based error positioning technology

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
分析语句命中谱的自动故障定位方法研究;王鹏;《计算机工程与应用》;20110223;第46卷(第32期);第59-62页 *
基于执行轨迹的软件缺陷定位方法研究;王新平;《计算机科学》;20091208;第36卷(第10期);第168-171、188页 *
基于程序切片的测试用例集约简方法;吴洁;《重庆交通大学学报(自然科学版)》;20100612;第29卷(第2期);第319-320、328页 *

Also Published As

Publication number Publication date
CN102708052A (en) 2012-10-03

Similar Documents

Publication Publication Date Title
CN102708052B (en) Software fault automatic positioning method in a kind of unit testing
JP6320475B2 (en) Static analysis based on efficient elimination of false positives
Fontana et al. Automatic detection of instability architectural smells
CN110928772B (en) A test method and device
Kintis et al. Isolating first order equivalent mutants via second order mutation
Foo et al. An industrial case study on the automated detection of performance regressions in heterogeneous environments
Jeanneret et al. Estimating footprints of model operations
WO2014180107A1 (en) Test-based static analysis false positive elimination method
JP2005302028A (en) Method and system for probe optimization for instrumenting program
EP2975527A2 (en) A method for tracing computer software
CN101866316A (en) A Software Defect Location Method Based on Relatively Redundant Test Set Reduction
CN106126416B (en) A kind of service combination path derivation method based on process layout
CN101231614A (en) A Software Defect Location Method Based on Execution Trajectory Block Similarity
CN106201894A (en) A kind of software testing device and method
CN111538655A (en) Software failure detection method, system, storage medium, computer program, terminal
CN104021072A (en) Machine and methods for evaluating failing software programs
CN103995780A (en) Program error positioning method based on statement frequency statistics
CN103713999B (en) Transformation relation test prioritization method based on quantitative measurement
CN101201787A (en) Debugging system and method of software program
CN103309811A (en) Method for quickly positioning software code defects based on test execution record
US20120233587A1 (en) Conducting verification in event processing applications using formal methods
CN102622295B (en) Self-adapting software defect positioning method based on predicate execution information analysis
CN103914386B (en) Software Defect Location Method Based on Input Parameter Feature Spectrum
US20050262399A1 (en) Aggregating and prioritizing failure signatures by a parsing program
CN103455417B (en) A kind of software error alignment system based on Markov model and location of mistake method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20171020

CF01 Termination of patent right due to non-payment of annual fee