对这类方法进行单元测试的最佳实践是什么?
public VerificationResultCode Translate(int value)
{
VerificationResultCode result;
if (Enum.IsDefined(typeof(VerificationResultCode), (int)value))
result = (VerificationResultCode)((int)value);
else
throw new UnknownResultReturnFromGatewayException();
return result;
}
VerificationResultCode 是 Enum 类型,如:
public enum VerificationResultCode
{
BankingNetworkError = 100,
NotEqual =101,
InputFormatError = 102,
MerchantAuthenticationFailed = 103,
...
}
我们应该为每个 Enum 成员编写一个测试方法,还是只编写一个包含大量断言的测试方法?