單元測試這些類型的方法的最佳做法是什麼?單元測試的最佳實踐枚舉翻譯器
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是枚舉類型,如:
public enum VerificationResultCode
{
BankingNetworkError = 100,
NotEqual =101,
InputFormatError = 102,
MerchantAuthenticationFailed = 103,
...
}
我們應該寫爲每個枚舉成員的單個測試方法或只寫一個一個試驗方法有很多斷言呢?!
其中之一,你不應該整數編碼爲雙打。你會有虛假的失敗。 – usr
兩個測試。一個值正確,一個值不正確。注意你沒有得到一個異常,然後你確實得到一個異常。除此之外,您還可以單元測試CLR從一個整數轉換爲枚舉的能力。 –
@usr Thansk!其編輯。 – Navid