unit testing - In MSTests is it possible to catch any exception? -


I'm trying to avoid a brittle test. I want to claim that a method throws an exception when invalid data is passed, and I do not care.

Take String.IsNullOrEmpty for example, if the string is empty, t want to throw a nullreference exception right? If it is empty, then I think you can leave the argument exception I do not think it is a good idea to have a separate guard section for blank versus spaces, and even if I just want to say that the exception is thrown from my unit has gone.

[Exceptions (Exception) (Exception)] Exception should pass an exception to give an error in saying. My solution is an attempt / catch block which has no fears. If an exception is not thrown, then file it. Is there a better / cleaner way?

It seems that trying means means that a common exception is thrown. Here is a thread on MSDN on this topic:

I still question the need to emphasize the general exception. If you are testing for a specific scenario, then you should know which exception should be thrown. For your example of using the string.IsNullOrEmpty () , it seems that you want to test both empty string and zero values. If the empty string is an invalid input then throwing a logic exposure seems appropriate and you can test against specific exceptions. If the string is a valid input, then you can test to make sure that it has not thrown an exception.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -