jeudi 28 mai 2015

Unit Testing Interface and abstract memebers using shims in Visual Studio 2013

I have below code which I want to unit test.

public abstract class Manager : MyPermissions, IManager
{   
  public IManager empManager { get; set; }
}

I don't have an class that derives from the above class within the same library otherwise I would have preferred to test the derived class for testing the above code. For now I have below test which I am running but it actually doesn't hit the actual code for testing.

    [TestMethod]
    public void empManagerGetSet()
    {
        using (ShimsContext.Create())
        {
            StubIManager sManager;
            sManager = new StubIManager();
            sManager.empManagerGet = () => { return (IManager)null; };
            var result = sManager.empManagerGet;
            Assert.IsNotNull(result);
        }
    }

Is there any other approach I can use to write a better UT in this scenario ?

Aucun commentaire:

Enregistrer un commentaire