0

I've recently seen several references that indicate or mention off-hand in an article that unit testing is always white box testing.

Since black-box testing is simply looking at the specification or requirements for that unit, and ensuring that it meets those, without any concern for how it does so, I would at least think that unit tests can be black box tests. In fact, if you aim for "clean code" and "clean architecture", then I would think your goal would be to create only black box tests at all levels of testing.

If there are internal structures that need to be tested beyond black box testing, then I would argue that the specification isn't complete. Another way of saying this would be that is that if you complete your black box testing, and confirm that your unit does everything you expect/want it to do, and you don't have 100% code coverage, and have to add white box tests to get 100% coverage, then I would be very concerned about that extra code either causing side effects that don't meet the spec (maybe in edge or corner cases), or just being unnecessary and adding unneeded complexity.

Am I misunderstanding the meaning of white box vs. black box testing? Is it correct to say that by definition all unit tests are white box tests?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
LightCC
  • 9,804
  • 5
  • 52
  • 92
  • I believe the answer on this may help on clarification [Black box vs White box Testing](https://stackoverflow.com/questions/402161/black-box-vs-white-box-testing) – alariva Aug 24 '18 at 15:20
  • Just as an extra hint for the answers you have on the referred questions, think of tests in regards of your actual needs. Blackbox and Whitebox are just classifications to help understanding the art of testing, has nothing to do with their effectiveness *per se*. Also (as a personal appreciation), it's possible that in terms of implementation **blackbox** is less intrussive than **whitebox** (mocking, spying, etc). – alariva Aug 24 '18 at 15:29
  • Thanks for the references - strange that the "Does 'unit testing' fall under.." Q&A didn't come up in my searches. – LightCC Aug 27 '18 at 18:32

0 Answers0