Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you display what's happening in the unit test as it runs?

Tags:

unit-testing

As I am coding my unit tests, I tend to find that I insert the following lines:

Console.WriteLine("Starting InteropApplication, with runInBackground set to true...");
try
{
    InteropApplication application = new InteropApplication(true);
    application.Start();
    Console.WriteLine("Application started correctly");
}
catch(Exception e)
{
    Assert.Fail(string.Format("InteropApplication failed to start: {0}", e.ToString()));
}

//test code continues ...

All of my tests are pretty much the same thing. They are displaying information as to why they failed, or they are displaying information about what they are doing. I haven't had any formal methods of how unit tests should be coded. Should they be displaying information as to what they are doing? Or should the tests be silent and not display any information at all as to what they are doing, and only display failure messages?

NOTE: The language is C#, but I don't care about a language specific answer.

like image 290
MagicKat Avatar asked Dec 01 '22 08:12

MagicKat


1 Answers

I'm not sure why you would do that - if your unit test is named well, you already know what it's doing. If it fails, you know what test failed (and what assert failed). If it didn't fail you know that it succeeded.

This seems completely subjective, but to me this seems like completely redundant information that just adds noise.

like image 181
Philip Rieck Avatar answered Dec 09 '22 20:12

Philip Rieck