vendredi 29 mai 2015

Testing Void methods using shims and stubs in VS 2013 c# Code

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 ?

Aucun commentaire:

Enregistrer un commentaire