Java 白盒和黑盒测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22100302/
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-08-13 13:36:50  来源:igfitidea点击:

Whitebox and Blackbox testing

javatestingblack-box-testingwhite-box-testing

提问by syiannop

I ve been reading for the whitebox and blackbox testing.

我一直在阅读白盒和黑盒测试。

If im not wrong:

如果我没有错:

Whitebox tests the implementation of a Software Program, but blackbox tests the inputs and outputs.

白盒测试软件程序的实现,而黑盒测试输入和输出。

Can someone please give me an example of a simple code for the both cases?

有人可以给我一个关于这两种情况的简单代码的例子吗?

Thank you in advance.

先感谢您。

so, the code here is a blackbox testing?

所以,这里的代码是一个黑盒测试?

  class Schalter
  {
     private boolean
     {
       private boolean _istAn;
       public Schalter(boolean anfangsAn)
       {
          _istAn = anfangsAn;        
       }       
       public boolean istAn()
       {
          return _istAn;
       }   
       public void umschalten()
       {
         _istAn = !_istAn;
       }
  }

采纳答案by user3003304

Blackbox -> you're really just checking if you're getting correct output for the input you gave your program.

Blackbox -> 您实际上只是在检查您为程序提供的输入是否获得了正确的输出。

Say you have a prompt that asks you to enter 2 digits to get the sum of the numbers.

假设您有一个提示,要求您输入 2 位数字来计算数字总和。

Enter 2 numbers: 2 5 output: 2 + 5 = 7

输入 2 个数字:2 5 输出:2 + 5 = 7

That's all there is to black box really.

这就是黑匣子的全部内容。



White box you would want to check to see HOW it's happening.

您想要检查的白框以了解它是如何发生的。

You could do the normal thing which would be something like

你可以做一些正常的事情,就像

int adder(int firstNum, int secondNum)
{ 
    return firstNum + secondNum;
}

this is more efficient than say something like:

这比说这样的话更有效率:

int adder(int firstNum, int secondNum)
{
    int temp;
    for(int i = 0; i < (firstNum + secondNum + 1); i++)
        temp = i;
    return temp;
}

In whitebox testing you would look at your code and figure out which is more efficient and/or is easier to read. Obviously the first one is since:

在白盒测试中,您将查看您的代码并找出哪个更有效和/或更易于阅读。显然第一个是因为:

  1. the code is simpler and easier to understand
  2. The first does not involve loops to find the answer this takes up more processing time than the first
  3. The first doesn't create extra variables that are not needed. This means less memory needed to keep track of the data.
  1. 代码更简单,更容易理解
  2. 第一个不涉及寻找答案的循环,这比第一个占用更多的处理时间
  3. 第一个不会创建不需要的额外变量。这意味着跟踪数据所需的内存更少。

This is a simple and arbitrary example, but when you get into larger projects you'll do a lot of whitebox testing when you do unit tests to figure out if smaller segments of your code works and you would normally do black box testing when you start integrating the smaller segments of your code into the larger project to check if you were still getting correct output for given input.

这是一个简单而随意的示例,但是当您进入更大的项目时,您会在进行单元测试时进行大量白盒测试以确定代码的较小部分是否有效,并且您通常会在开始时进行黑盒测试将较小的代码段集成到较大的项目中,以检查是否仍然为给定的输入获得正确的输出。

Another way to look at it you could use blackbox testing to see if you were getting bad output and if so then you could go in and do whitebox testing to see what you were doing wrong in your code.

另一种看待它的方法是,您可以使用黑盒测试来查看您是否得到了糟糕的输出,如果是,那么您可以进行白盒测试以查看您在代码中做错了什么。

回答by Vivin Paliath

Blackbox testing is a way of testing where you don't care howthe program manipulates the input; you're only checking to see if the outputs are valid for the specified inputs.

黑盒测试是一种测试方式,您不关心程序如何操作输入;您只是检查输出是否对指定的输入有效。

Whitebox testing is a way of testing when you care howthe program manipulates the input, as well asthe output.

当您关心程序如何操作输入输出时,白盒测试是一种测试方式。

I guess one example is if you were writing a test for sorting algorithims. A blackbox test would simply check to see if the outputs are sorted according to what you would expect. A whitebox test might check to see if the sorting is stableor not, because that depends on the implementation of the sorting algorithm. For example, Merge Sort is stable, whereas the typical in-place version of Quicksort is not (although stable versions do exist).

我想一个例子是,如果你正在编写一个排序算法的测试。黑盒测试只会检查输出是否按照您的预期排序。白盒测试可能会检查排序是否稳定,因为这取决于排序算法的实现。例如,合并排序是稳定的,而快速排序的典型就地版本则不是(尽管确实存在稳定版本)。

回答by BugSeeker

See in simple words, White boxtesting is a testing where you are aware of the inner paths and coding of software or any app. Programming skills are needed to design Test Cases in White box testing. White box testing can be performed in Unittesting, Integrationtesting and Systemtesting.

见简单的话,白箱测试,你都知道内路径和软件或任何应用程序的编码测试。在白盒测试中设计测试用例需要编程技能。白盒测试可以在单元测试、集成测试和系统测试中进行。

While in Black Boxtesting you just need SRS(Software Requirement Specification) to understand what system does and what are Client's requirement. Here tester's Programming skills are not tested. Usually in Manual testing BlackBox approach is followed. Black Box testing is done in almost all levels i.e Unittesting, Integrationtesting , Systemtesting and Acceptance testing.

而在黑盒测试,你只需要SRS(软件需求规格),以了解哪些系统做,什么是客户的需求。这里不测试测试人员的编程能力。通常在手动测试中遵循 BlackBox 方法。黑盒测试几乎在所有级别进行,即单元测试、集成测试、系统测试和验收测试

回答by Srisha

In Black box testing the structure of the program is not considered. Test cases are decided solely on the basis of the requirements or specification of the program or module, and the internals of the program are not considered for the selection of the test cases. black box testing is concerned with functionality of the program.

在黑盒测试中,不考虑程序的结构。测试用例仅根据程序或模块的要求或规范来决定,在选择测试用例时不考虑程序的内部结构。黑盒测试与程序的功能有关。

Lifted from https://in.answers.yahoo.com/question/index?qid=20101031090207AAbYHrB

摘自https://in.answers.yahoo.com/question/index?qid=20101031090207AAbYHrB

回答by Srisha

White box testing is the detailed investigation of internal logic and structure of the code. White box testing is also called glass testing or open box testing. In order to perform white box testing on an application, the tester needs to possess knowledge of the internal working of the code.

白盒测试是对代码内部逻辑和结构的详细调查。白盒测试也称为玻璃测试或开盒测试。为了对应用程序执行白盒测试,测试人员需要具备代码内部工作的知识。

Lifted from http://www.tutorialspoint.com/software_testing/testing_methods.htm

摘自http://www.tutorialspoint.com/software_testing/testing_methods.htm