मुझे एकाधिक अपवादों के लिए एक टेस्ट विधि चाहिए। समस्या यह है कि पहले फेंकने के अपवाद के बाद Testmethod बंद हो जाता है।एकाधिक अपवादों के साथ यूनिटटेस्ट अपेक्षित अपवाद
मुझे पता है कि मैं ऐसा ही कुछ कर सकते हैं:
try
{
sAbc.ToInteger();
Assert.Fail(); // If it gets to this line, no exception was thrown
}
catch (ArgumentException) { }
लेकिन मैं निम्नलिखित कोड आधार का उपयोग करना चाहते:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger(); // throws an exception and stops here
sDecimal.ToInteger(); // throws theoretically a exception too...
}
और मैं के लिए एक testmethod बनाने के लिए नहीं करना चाहते हैं इस तरह प्रत्येक संभावित अपवाद:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger();
}
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sDecimal.ToInteger();
}
तरीके के बारे में या प्रकार कई अपवाद:
तुम सच में सुविधा की जरूरत है, NUnit जो है का उपयोग करें? एक समय में केवल एक अपवाद होगा। क्या यह mstest द्वारा प्राप्त किया जा सकता है? – liang