0

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
  • 2,050
  • 4
  • 47
  • 101
  • How are these 2 methods 'tests'? Where are the assert bits? – zaitsman May 29 '15 at 11:39
  • Since the methods "Log" are void methods , I am not testing anything. That's where I would like to know what are other test methods I can add or how shall I modify the existing ones. – krrishna May 29 '15 at 11:41
  • 2
    then these are not tests and they are USELESS. The tests (with shims in this case) would be that the tryinitialize is called (or not); that the count is incremented; that foreach lop iterates; that the error is written; that the string is formatted correctly; and that the writeline is invoked. – zaitsman May 29 '15 at 11:42

0 Answers0