UnitTest ExpectedException with multiple Exceptions
- by masterchris_99
I want one TestMethod for multiple exceptions. The Problem ist that the Testmethod stops after the first thrown exception.
I know that I can do something like that:
try
{
sAbc.ToInteger();
Assert.Fail(); // If it gets to this line, no exception was thrown
}
catch (ArgumentException) { }
But I want to use the following code-base:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger(); // throws an exception and stops here
sDecimal.ToInteger(); // throws theoretically a exception too...
}
And I don't want to create one testmethod for each possible exception like that:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger();
}
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sDecimal.ToInteger();
}