31

Does "Unit Testing" fall under white box or black box testing? Or is it totally a separate type of testing than the other two?

2
  • honestly, the wikipedia article on white box testing explains it well enough.
    – Scott M.
    Commented Mar 27, 2012 at 15:49
  • 6
    I have noticed that white box unit tests for code that's often refactored creates lot of work to just maintain the tests themselves.
    – airboss
    Commented Sep 5, 2014 at 21:11

2 Answers 2

38

I think this article by Kent Beck referring more to TDD and unit-testing sums this up fairly well. Basically, it depends on how you actually write the tests*. Here is another article on the subject that might help clarify things.

*If you are testing from within your application, then it is whitebox. If you are testing it just like an outsider would make the calls to only your public facing API, then it is blackbox.

3
  • 5
    In both cases, they are whitebox testing. It seems that many confuse the definitions of both types of testing. Unit testing is simply testing every unit class of your "code". It is a whitebox testing. Blackbox testing tests the overall functionality of your "app". You can write any way and automate it if you want. But unit testing...well, it is always whitebox testing :) Commented Jul 22, 2015 at 8:08
  • 18
    If you write unit tests after code and with the help/on the basis of code - unit tests are white box tests. If you write unit tests before code or write unit tests based on specification - unit tests are back box tests.
    – hellboy
    Commented Nov 10, 2015 at 12:14
  • In my opinion it depends on what you define as "unit". When testing the code class as the "unit" then you know the codebase around thus making it a whitebox/glassbox test. However if you say the "unit" is a whole application that you approach as a user then it's a backbox test since you as the testing user can't look inside of the "unit" aka the application. However I would state the latter more as an integration test if the application consists out of different modules. In that case you would test how all modules will work together in their integration.
    – xetra11
    Commented Dec 21, 2020 at 9:16
14

The usual criteria for white-box testing is execution path and data structure sensitization. These are sometimes called "branch testing", "path testing", "data flow testing". See Wikipedia on white-box testing.

That is, unit-test refers to the level at which the test takes place in the structure of the system, whereas white- and black-box testing refer to whether, at any level, the test approach is based on the internal design or only on the external specification of the unit.

So if your unit-test sensitizes all of the execution paths and data structures in the unit that you are testing, then it is a white-box test. However, if your unit cannot sensitize most of the paths and data structures of the unit, then it can't claim to be a white-box test.

Be advised that in some organizations unit-testing is called white-box testing regardless of whether the unit-test is based on the unit's design rather than just its API. Best not to argue with your boss on this point.

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