我有一个工厂switch语句,基于在喜欢的东西通过枚举的值返回命令的默认情况:如何进行单元测试的基于枚举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);
}
}
我目前对于枚举中的每个值都有一个开关箱。我对这些情况都有单元测试。我如何测试默认情况下会抛出错误?显然,目前我无法传入一个未知的EnumType,但是谁说这将在未来不会改变。无论如何,我可以纯粹为了单元测试而扩展或模拟EnumType?