Tôi muốn có một TestMethod cho nhiều ngoại lệ. Vấn đề ist rằng Testmethod dừng sau khi ngoại lệ ném đầu tiên.UnitTest ExpectedException với nhiều ngoại lệ
Tôi biết rằng tôi có thể làm một cái gì đó như thế:
try
{
sAbc.ToInteger();
Assert.Fail(); // If it gets to this line, no exception was thrown
}
catch (ArgumentException) { }
Nhưng tôi muốn sử dụng mã-base sau:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger(); // throws an exception and stops here
sDecimal.ToInteger(); // throws theoretically a exception too...
}
Và tôi không muốn tạo ra một TestMethod cho mỗi ngoại lệ có thể có như sau:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger();
}
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sDecimal.ToInteger();
}
thế nào về hoặc kiểu nhiều trường hợp ngoại lệ? chỉ có một ngoại lệ sẽ xảy ra tại một thời điểm. Điều này có thể đạt được bằng mstest? – liang