【发布时间】:2010-08-20 21:57:22
【问题描述】:
只有在验证存在无效数字时才调用以下方法(通过调用另一个方法)。如何在以下 sn-p 中测试覆盖 throw-line?我知道一种方法可能是将VerifyThereAreInvalidiDigits 和此方法合并在一起。我正在寻找其他想法。
public int FirstInvalidDigitPosition {
get {
for (int index = 0; index < this.positions.Count; ++index) {
if (!this.positions[index].Valid) return index;
}
throw new InvalidOperationException("Attempt to get invalid digit position whene there are no invalid digits.");
}
}
我也不想编写一个单元测试来练习不应该执行的代码。
【问题讨论】:
-
你说它不应该被执行并且无法到达的事实对我说“删除它”。您已验证该字符串无效,无法到达此处,因此您知道该属性将返回一些内容。
标签: c# unit-testing testing code-coverage