I am very confused about white box testing.

A simplified version of the example: the entire system consists of three methods - methodA(), methodB(), methodC().

The program starts from methodA(), and methodB() requires input from methodA() and methodC() requires input from methodB().

Do we create 3 white box tests, one for each method, or do we create one white box test for the entire system?


I'm assuming you are writing automated tests using an xUnit framework of some kind. If that is the case, the ideal situation is usually where each function is tested individually. This gives you several advantages:

  1. defect localization - when something goes wrong you know exactly where in the code it happened.
  2. more control over test input. You can test your code for adverse input more easily if you can control the exact input each function is tested for.

If you're in a position to choose, a good rule of thumb is to prefer a higher level of granularity for unit tests

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