I'm currently in the process of writing a class library, and I'm attempting to write as many unit tests as possible to ensure that I can weed out all the mistakes early on.
Part of this involves testing that various properties catch Exceptions if set to null, so I don't need to extensively check this later on in the program and slow down my heuristics.
What I'm interested in, is if anyone knows of an easy way of testing for Exceptions being thrown, or a better technique than below:
Part of this involves testing that various properties catch Exceptions if set to null, so I don't need to extensively check this later on in the program and slow down my heuristics.
What I'm interested in, is if anyone knows of an easy way of testing for Exceptions being thrown, or a better technique than below:
Code:
try
{
value1 = null
}
catch(NullReferenceException)
{
try
{
value2 = null;
}
catch(NullReferenceException)
{
return;
}
}
Assert.Fail("Null Reference Exceptions were not thrown");
Comment