title: Write a test method to determine, if code have risk of getting null reference exception
body: <p>I am trying to write a generic test method in C#, which will tell me if, a target method have risk of getting null reference exception.</p>
  
  <p>I want to run this method against all the functions in the class and would like to determine which methods have risk of getting a null reference exception.</p>
  
  <p>Something Like below,</p>
  
  <pre><code>[TestMethod]
  Public Void TestReferenceVulnarability()
  {
      try
      {
          MyClass _myClass = new MyClass();
          //Do something
          target = _myClass.DoSomething();
      }
      catch (NullReferenceException ex)
      {
          throw ex;
      }
  }
  
  public class MyClass
  {
      public void DoSomething()
      {
          // Do something here
      }
  }
  </code></pre>
  
  <p>The manual process we use to determine if a code have vulnerability of null refrence exeption. I want to automate this. </p>
  
  <p>While writing code, we carefully look at objects if, there is a risk of getting null reference exception. If so, We add null checks to cover that risk.
  However, in runtime, we still sometimes get null refrence exeption, as manual checking overlooked the risk.</p>
  
  <p>How can I write test method/functionality, which will automate this process, and tell me if a function have risk of getting null reference exception.</p>