19

What is Unit testing, Black-box testing and White-Box testing? I googled but all the explanation I found was very technical. Can anyone answer this question in a simple way with an appropriate example?

2
  • 2
    Not an SO question. You could even answer parts of your question yourself by reading the descriptions of the tags that you used. Wikipedia is very clear about these topics. Funny what pops up here :| Aug 31, 2011 at 14:46
  • "The question looks very childish right". Agreed. Could you include the specific questions you have so that we can try and help?
    – S.Lott
    Sep 1, 2011 at 19:52

4 Answers 4

36

In black box testing, you don't care how the internals of the thing being tested work. You invoke the exposed API and check the result; you don't care what the thing being tested did to give you the result.

In white box testing, you do care how the internals of the thing being tested work. So instead of just checking the output of your thing, you might check that internal variables to the thing being tested are correct.

Unit testing is a way of testing software components. The "Unit" is the thing being tested. You can do both black and white box testing with unit tests; the concept is orthogonal to white/black-box testing.

1
  • 1
    Better stated, unit testing has to do with the size of the components under test. A unit test looks at testing a isolated chunk of code, rather than a whole piece of functionality, application, or entire system. The size of a 'unit' is obviously open to interpretation, but in OOP, usually refers to a single class. Mar 2, 2018 at 14:38
13

A very non technical explaination lacking any details.... Here comes..

  • Blackbox Testing : Testing an application without any knowledge of how the internal application works

  • Whitebox Testing: Testing an application with knowledge of how the internal works, such as by having the source code side by side while you are doing your test.

  • Unit Testing: This is where you create tests which interact directly with your application. You would check a function in your application and assert that the response should return with value X. Unit Tests are usually, but not always created by the developers themselves as well, whereas if a company does whitebox and blackbox testing, it can be done by anyone.

This is a very basic explaination.

1

Black Box Testing:

  1. Tester is a human and not the developer
  2. Tester does not know how system was implemented *
  3. Tester will report an issue when the response from the system to any step of the test is not the expected result.

White Box Testing:

  1. Tester is a human and not the developer
  2. Tester does know how system was implemented *
  3. Tester will report an issue when the response from the system to any step of the test is not the expected result and is more likely to detect an issue with the test case itself or with the system despite receiving expected results.

Unit Testing:

  1. Tester is usually code that tests a particular module within a system. For example, in Java, a project may have a class named Student and a test class named StudentTest. For each of the functions in Student (like getGrades), StudentTest might have 0 or more functions to test them (like getGradesTest). This is just one such way to go about it.
  2. Testing code typically only knows the expected output for various input for a portion of a system.
  3. Unit tests are often run before submitting code or run automatically when building an application to deploy. The goal is to prevent as many bugs from being introduced into the system when adding, changing or removing functionality.

* The amount of knowledge known between a black box tester and a white box tester varies from organization to organization. For example, what I consider usability testing, another company might call black box testing. A white box tester in some companies might be another developer (developer QA), whereas another organization may not allow any testing sign-offs to be completed by a developer. A black box tester could be someone who just has a list of instructions they need to follow and validate, or it could be someone who generally knows how the system works, but just not at a particularly detailed level. For example:

A black box tester may or may not identify an issue despite a test case that matches expectations, like an e-commerce test case that omits the step of collecting a guest checkout shipping address.

Essentially, white box and black box testing is rarely implemented strictly. Most organizations have unit tests, developer testing (that may or may not be formally documented - depends upon the implications of a failure), QA testers (black, white, and every shade of gray in between), and user testing / business sign-off (the people who should be involved throughout the project, but in poorly run organizations only show up at the beginning and end, and send a completed project back to design right before deployment).

2
  • 4
    The developers are not human?
    – Mate Mrše
    Mar 30, 2019 at 10:57
  • 1
    No they're superhuman :)
    – timoto
    Aug 6, 2020 at 8:08
0

Blackbox Testing: This is always user or client based testing where testing is done based on the requirement provided. This testing is done by testers only.

Whitebox Testing: This is to verify the flow of the code base. Testing the flow of condition statement, loop statement etc. This mainly from developer prospective.

Unit Testing: This is part of white box testing as you test each methods in code with your test data and assert that. Now a days this done by testers and company looks this skill from tester where they are able to understand the code and algorithms.

Not the answer you're looking for? Browse other questions tagged or ask your own question.