java Java白盒测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15032219/
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
Java whitebox testing
提问by knowbody
How is white box testing done on java applications? Does it mean that I have to test class by class?
java应用程序上的白盒测试是如何进行的?这是否意味着我必须逐堂测试?
From my research I know that:
根据我的研究,我知道:
White Box Testing is a software testing method in which the internal structure/design/implementation of the item being tested is known to the tester. The tester chooses inputs to exercise paths through the code and determines the appropriate outputs. Programming know-how and the implementation knowledge is essential. White box testing is testing beyond the user interface and into the nitty-gritty of a system.
白盒测试是一种软件测试方法,其中测试人员知道被测试项目的内部结构/设计/实现。测试人员选择输入以通过代码执行路径并确定适当的输出。编程知识和实施知识是必不可少的。白盒测试是超越用户界面并深入系统本质的测试。
What should the white box testing look like?
白盒测试应该是什么样的?
采纳答案by AlexR
Class-by-class testing is usually called unit-testing. There are several popular tools that can help you. Start from JUnit or TestNG. Implement tests for each class or group of classes (modules) that provide some functionality.
逐类测试通常称为单元测试。有几种流行的工具可以帮助您。从 JUnit 或 TestNG 开始。为提供某些功能的每个类或类(模块)组实施测试。
Then you can go up, i.e. write tests for bigger modules and for whole application. Such tests are typically called integration tests.
然后你可以上去,即为更大的模块和整个应用程序编写测试。此类测试通常称为集成测试。
回答by SigmaX
Summary:Modern white-box testing uses sophisticated automated tools to help developers design good tests and measure code coverage in meaningful ways. Widely used (if rudimentary) examples include Cobertura, EMMA, EclEmma and JaCoCo.
简介:现代白盒测试使用复杂的自动化工具来帮助开发人员设计良好的测试并以有意义的方式衡量代码覆盖率。广泛使用的(如果是基本的)示例包括Cobertura、EMMA、EclEmma 和 JaCoCo。
How is white box testing done on java applications?
java应用程序上的白盒测试是如何进行的?
Traditionally, black-box testing meant that another team (not the developer) was responsible for testing the software, and they did not look at the source code while doing so.
传统上,黑盒测试意味着另一个团队(不是开发人员)负责测试软件,并且他们在这样做时不会查看源代码。
Even with the move to unit testing, a common approach to designing tests is to use a more-or-less black-box input domain characterization,that is, just test the boundary conditions and a few arbitrary "normal" input values.
即使转向单元测试,设计测试的常用方法还是使用或多或少的黑盒输入域表征,即只测试边界条件和一些任意的“正常”输入值。
Clearly, however, this approach may fail to exercise some branches of the function. A good developer will open up the codeand say "hey, I need to add an input to exercise that branch."
然而,很明显,这种方法可能无法执行该功能的某些分支。一个优秀的开发人员会打开代码并说“嘿,我需要添加一个输入来练习那个分支。”
Modern white-box testing takes that idea a step further by automating the process, producing output like this to show which parts of a method have not yet been exercised by, say, JUnit (from the NetBeans plugin TikiOne):
现代白盒测试通过自动化流程将这个想法更进一步,产生这样的输出以显示方法的哪些部分尚未被 JUnit(来自 NetBeans 插件TikiOne)执行:
What should the white box testing look like?
白盒测试应该是什么样的?
The code coverage tools mentioned in the summary attempt to automate the process of making sure you exercise every line or branch of code. When integrated into a continuous integration environment like Jenkins, it allows your team to keep a constant eye on not only whether your tests are passing, but whether you are meeting your coverage goals (from the NetBeans plugin TikiOne):
摘要中提到的代码覆盖率工具尝试自动执行确保您执行代码的每一行或分支的过程。当集成到像Jenkins这样的持续集成环境中时,它使您的团队不仅可以持续关注您的测试是否通过,还可以关注您是否达到了覆盖目标(来自 NetBeans 插件TikiOne):
In software engineering research, white-box testing can get far more sophisticated than counting lines. A wide variety of tools and mathematical techniques have been developed to help you make sure that the inputs you give to your tests properly cover all the possible behaviors of your code.
在软件工程研究中,白盒测试可以变得比计数线复杂得多。已经开发了各种各样的工具和数学技术来帮助您确保为测试提供的输入正确地涵盖了代码的所有可能行为。
For instance, warning systems for an airplane auto-pilot system that uses complex Boolean predicates might use white-box testing criteria rooted in formal logic to ensure that we cover all logically possible pathsthrough the controller.
例如,使用复杂布尔谓词的飞机自动驾驶系统的警告系统可能会使用植根于形式逻辑的白盒测试标准,以确保我们涵盖通过控制器的所有逻辑上可能的路径。
Analyzing line and branch coverage, the most common criteria, is a special case of using graph representations of software, such as a control flow graphor a data flow diagram. A good tool will read your code to generate the graph, and then you can choose from various graph coverage criteriato automatically recommend a set of paths through the method's control logic (branches) that you need to exercise in order to fulfill your testing goals.
分析线和分支覆盖率(最常见的标准)是使用软件图形表示的一种特殊情况,例如控制流图或数据流图。一个好的工具将读取您的代码以生成图形,然后您可以从各种图形覆盖标准中进行选择,以自动推荐一组通过方法的控制逻辑(分支)的路径,您需要运用这些路径来实现您的测试目标。
Lines and branches are the simplest and most-used (control) graph coverage criteria (corresponding to covering nodes and edges) -- more thorough (and difficult to satisfy) metrics like edge-pairs and prime paths are available in some tools. These ask not just "did I go down every choice at each branch at least once," but "did I go through every branch via every way I was able to get there."
线和分支是最简单和最常用的(控制)图覆盖标准(对应于覆盖节点和边)——一些工具中提供了更彻底(并且难以满足)的指标,如边对和主要路径。这些问题不仅问“我是否至少在每个分支上选择了一次”,而是“我是否通过所有能够到达那里的方式通过了每个分支。”
It's still up to the programmer to find a set of inputs to exercise these paths, and to design code small enough and simple enough that the number of required tests to get good coverage with the more thorough criteria doesn't explode exponentially. But now you have formal, quantitative ways to A) tell you what needs tested, and B) tell you how well you have tested your project.
程序员仍然需要找到一组输入来执行这些路径,并设计足够小和足够简单的代码,以便使用更全面的标准获得良好覆盖所需的测试数量不会呈指数级增长。但是现在您有了正式的、定量的方法来 A) 告诉您需要测试的内容,以及 B) 告诉您您的项目测试情况如何。
Does it mean that I have to test class by class?
这是否意味着我必须逐堂测试?
White-box testing is a method for designingtests. It can apply at all testing levels, including unit tests, integration tests, and system tests.
白盒测试是一种设计测试的方法。它可以应用于所有测试级别,包括单元测试、集成测试和系统测试。
For more information on test coverage criteria, see
有关测试覆盖标准的更多信息,请参阅
- Beizer, Boris. Software testing techniques.Dreamtech Press, 2003.
- 贝泽尔,鲍里斯。软件测试技术。梦想科技出版社,2003 年。
or see the more up-to-date
或查看更多最新信息
- Ammann, Paul, and Jeff Offutt. Introduction to software testing.Cambridge University Press, 2008.
- 阿曼、保罗和杰夫·奥夫特。软件测试简介。剑桥大学出版社,2008 年。