jeudi 4 juin 2015

Grab object values during runtime for creating Mock objects required for writing Unit Test

Consider the below class which needs to be tested,

class ToBeTested
{
  Employee _e;
  public ToBeTested(Employee e)
  {
  _e = e;
  }

  void Process()
  {
  // Do something with _e
  }
}

    [TestClass]
    class ToBeTestedTest
    {
    [TestMethod]
    public void TestProcessMethod()
    {
      Employee e = // Initialise it with some test value..
      ToBeTested tbt = new ToBeTested(e);
      tbt.Process();

      //Assert to Verify the test results...  
    }

The Problem is Employee can really be a very complex type with properties in it which themselves can be objects of more classes. It becomes difficult to initialise Employee with Mock Values and generate a testable object.

While debugging I can set a breakpoint and see what Employee object in ToBeTested contains. Is there a way by which I can grab all the values from this object as is available during runtime and use it in my test method?

Aucun commentaire:

Enregistrer un commentaire