【发布时间】:2010-12-22 02:18:21
【问题描述】:
我在工厂中有一个 switch 语句,它根据传入的枚举值返回一个命令。类似于:
public ICommand Create(EnumType enumType)
{
switch (enumType)
{
case(enumType.Val1):
return new SomeCommand();
case(enumType.Val2):
return new SomeCommand();
case(enumType.Val3):
return new SomeCommand();
default:
throw new ArgumentOutOfRangeException("Unknown enumType" + enumType);
}
}
我目前对枚举中的每个值都有一个 switch case。我对每种情况都有单元测试。如何对默认情况进行单元测试会引发错误?显然,目前我不能传入一个未知的 EnumType 但谁能说这在未来不会改变。无论如何,我可以纯粹为了单元测试而扩展或模拟 EnumType 吗?
【问题讨论】:
标签: c# unit-testing mocking moq