白盒测试如何失败而黑盒测试成功(反之亦然)?

How can a white box test fail, and a black box test succeed (and vice versa)?

我要参加考试并试图找到这个问题的答案,但到目前为止我没有成功。问题是:

Give an example white box test says everything okay but black box test says there is an error. And an example black box test says everything okay but white box test says there is an error.

假设 'black box test' 是指某种集成测试(即仅使用 public 可见 UI),而 'white box test' 是指某种单元测试(即公开技术内部):

考虑这样一种情况,您希望向用户显示的结果是 10,可能是发票的计算或类似的结果。
这在您的集成测试中工作正常,但是当您进行单元测试时,负责获取 10 的函数实际上是 returning 9!
发生这种情况的一个原因是集成测试 运行 的代码比单元测试多得多,例如,您可能会这样做:

def _function_responsible_for_10
   return 9
end

def output_to_user
  value = _function_responsible_for_10()
  return value + 1
end

看到return value + 1了吗?这使您获得了正确的输出,但是您以错误的方式获得了它。这只 碰巧 在这种情况下工作,但是当你稍后添加更多依赖 function_responsible_for_10 的代码时(或更改 output_to_user),你会突然变得不一样(意想不到的) ) 结果。也许更糟糕的是,您可以在某些时候将 _function_responsible_for_10 修正为正确 return 10,这实际上会破坏此代码!

这个例子被简化了,这只是 一个 可能会出现的问题,但它应该让你朝着正确的方向思考 :-) 我鼓励你考虑其他的(可能更好!)以你自己为例。