locked
Testing methods with overloading using shims and stubs in VS 2013 c# Code RRS feed

  • Question

  •                      

    I have the below code which I am unit testing.

        public static void Log(string appName, string message)
        {
            Log(appName, message, string.Empty);
        }
        public static void Log(string Name, string Message, string Source)
        {
            if (!baselogger.Initialize) return;
            TryInitialize();
            Count++;
            foreach (ILogging logger in loggers)
            {
                logWrite(1000);
                logger.WriteError(Name, Message, Source);
            }
            string message = string.Format(CultureInfo.InvariantCulture, "{0}: {1}: {2}", Name, Message, Source);
            System.Diagnostics.Trace.WriteLine(message);
         }

    And I wrote below test methods to test it.

       [TestMethod]
       public void LogWith2Params()
        {
            Logging.Log("Host","Control not found.");
        }
    
    
       [TestMethod]
       public void LogWith3Params()
        {
            Logging.Log("Host","Control not found.","ManageAccounts");
        }

    Are the above two tests enough or do I need to write new test cases ? Or should I write another testmethod by passing 3 parameters and do the shim  for logger.initialize property,TryInitialize method call, logWrite method call,logger.WriteError method call and Trace.Writeline method call ?


    Krrishna

    Friday, May 29, 2015 12:42 PM

Answers

  • Hi Krrishna,

    Since test methods are used to test the real class methods you want, as you said that if one class method called another one, the real issue is that which class method you really want to test, if you just want to test current class method, I think we don't have to write a new test case for the called class method. It is enough.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 1, 2015 6:27 AM