5
我想要一个TestMethod来处理多个异常。问题在于Testmethod在第一次抛出的异常之后停止。有多个异常的UnitTest ExpectedException
我知道我可以做这样的事情:
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();
}
怎么样或类型多个异常?一次只会发生一个例外情况。这可以通过mstest实现吗? – liang