Using a stub instead of a concrete object as a parameter RRS feed

  • Question

  • Is it always necessary to create and pass in a stub into a method as a parameter, even if I can instantiate that object being passed in to the method without any problems.

    ex. I want to test this method below and it takes in a TargetDataRanger object as a parameter. Should I a.) stub it out and pass it in b.) break the dependency and put it behind a inerface then stub it and pass it in c.) instanitate it and pass it into the method as a concrete object.

    In this case below I can get away with using the concrete object but is that wise and does it break some testing rules or something?

    public virtual Dictionary<DateTime, DateTime> ResolveDates(ISeries comparisonSeries, TargetDateRanger sourceRanger)
                Dictionary<DateTime, DateTime> dates = new Dictionary<DateTime, DateTime>();
                foreach (DateTime keyDate in sourceRanger.ValidDates)
                    dates.Add(keyDate, this.ResolveDate(comparisonSeries, keyDate));
                return dates;


    Tuesday, June 4, 2013 7:15 PM