mercredi 27 janvier 2016

Write a test method to determine, if code have risk of getting null reference exception

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.

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.

Something Like below,

[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
    }
}

Aucun commentaire:

Enregistrer un commentaire