java 路径测试和分支测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15895517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:13:07  来源:igfitidea点击:

path testing and branch testing

javaunit-testingtestingintegration-testing

提问by sasikals26

Can you please explain me the different between Path and Branch testing?

你能解释一下路径测试和分支测试之间的区别吗?

I read in many articles but still I am confused between this two.

我读了很多文章,但我仍然对这两者感到困惑。

I searched in stack overflow but I didn't find any suitable answer for this Please help me by providing the link if i am duplicate this question.

我在堆栈溢出中搜索,但我没有找到任何合适的答案 如果我重复这个问题,请提供链接帮助我。

Thanks,

谢谢,

采纳答案by Anil Vaitla

Quick Summary

快速总结

Summarized from https://www.cs.drexel.edu/~jhk39/teaching/cs576su06/L4.pdf

总结自https://www.cs.drexel.edu/~jhk39/teaching/cs576su06/L4.pdf

Path Testing:

路径测试:

  • 100% path coverage.
  • Execute all possible control flow paths through the program.
  • 100% 路径覆盖。
  • 通过程序执行所有可能的控制流路径。

Statement Testing:

语句测试:

  • 100% statement coverage.
  • Execute all statements in a program at least once under some test.
  • 100% 语句覆盖。
  • 在某个测试下至少执行一次程序中的所有语句。

Branch Testing:

分支测试:

  • 100% branch coverage.
  • Execute enough tests to assure that every branch alternative has been exercised at least once under some test.
  • 100% 的分支机构覆盖率。
  • 执行足够多的测试以确保每个分支备选方案在某个测试下至少执行过一次。

In general Path Testing >= Branch Testing >= Statement Testing, in terms of how much confidence they can provide in the correctness of your system.

一般来说,路径测试 >= 分支测试 >= 语句测试,就它们可以为您的系统的正确性提供多少信心而言。

Discussion

讨论

Path coverage counts the number of full paths from input to output through a program that get executed, whereas branch coverage counts the number of branches that were tested at any point in time. In this definition full path coverage will lead to full branch coverage.

路径覆盖率计算从输入到输出的完整路径数,通过执行的程序,而分支覆盖率计算在任何时间点测试的分支数。在这个定义中,全路径覆盖将导致全分支覆盖。

There may be multiple paths which hit a single conditional statement, and full path coverage may test the different variants (because inside the if statement an external resource may be invoked which branch coverage would not identify). Branch coverage is more like testing that the branch is hit at some point, and the argument is passed to a mock external resource correctly (not necessarily what comes afterwards).

可能有多个路径命中单个条件语句,并且完整路径覆盖可以测试不同的变体(因为在 if 语句内部可能会调用外部资源,而分支覆盖无法识别)。分支覆盖更像是测试分支是否在某个时刻被击中,并且参数被正确传递给模拟外部资源(不一定是之后发生的)。

As seen here: https://www.cs.drexel.edu/~jhk39/teaching/cs576su06/L4.pdf, we can sometimes represent the set of all paths by flow diagrams and the goal is to verify that each path from start to end works as expected in path testing.

如此处所示:https: //www.cs.drexel.edu/~jhk39/teaching/cs576su06/L4.pdf,我们有时可以通过流程图表示所有路径的集合,目标是验证每条路径从一开始在路径测试中按预期结束工作。

Branch Testing Additional Notes

分支测试附加说明

From here: Branch testing

从这里:分支测试

Testing in which all branches in the program source code are tested at least once

Path Testing Additional Notes

路径测试附加说明

From here: http://www.qualitytesting.info/forum/topics/what-is-difference-between-2and http://www.cs.st-andrews.ac.uk/~ifs/Books/SE9/Web/Testing/PathTest.html

从这里:http: //www.qualitytesting.info/forum/topics/what-is-difference-between-2http://www.cs.st-andrews.ac.uk/~ifs/Books/SE9/网络/测试/PathTest.html

A path is a sequence of executable statements. Testers are concerned with
"entry-exit paths", which begin at the entry point into a given process and
proceed to its exit point. 

The objective of path testing is to ensure that each independent path through
the program is executed at least once. An independent program path is one that
traverses at least one new edge in the flow graph. In program terms, this means
exercising one or more new conditions. Both the true and false branches of all
conditions must be executed.

回答by Madhivanan

Basis path testing, a structured testing or white box testing technique used for designing test cases intended to examine all possible paths of execution at least once. Creating and executing tests for all possible paths results in 100% statement coverage and 100% branch coverage.

基本路径测试,一种用于设计测试用例的结构化测试或白盒测试技术,旨在至少检查一次所有可能的执行路径。为所有可能的路径创建和执行测试会导致 100% 的语句覆盖率和 100% 的分支覆盖率。

Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.

分支覆盖是一种测试方法,旨在确保每个决策点的每个可能分支至少执行一次,从而确保执行所有可达代码。

That is, every branch taken each way, true and false. It helps in validating all the branches in the code making sure that no branch leads to abnormal behavior of the application.

也就是说,每个分支都采取不同的方式,真假。它有助于验证代码中的所有分支,确保没有分支导致应用程序的异常行为。