Unit Testing Exceptions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IanWright
    New Member
    • Jan 2008
    • 179

    Unit Testing Exceptions

    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:

    Code:
    try
    {
       value1 = null   
    }
    catch(NullReferenceException)
    {
       try
       {
         value2 = null;
       }
       catch(NullReferenceException)
       {
          return;
       }
    }
    
    Assert.Fail("Null Reference Exceptions were not thrown");
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    You can take a look at Unit Testing Framework and Visual Studio Team Test

    Comment

    • IanWright
      New Member
      • Jan 2008
      • 179

      #3
      Originally posted by DeepBlue
      Interesting... I think I need to explore MSDN a little more than I have already. Thanks DeepBlue.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Welcome Ian... i too need to explore this ...

        Comment

        Working...