Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • How do you unit test a logger? Do you have to moc IO? That seems obnoxious. Commented Dec 14, 2018 at 21:47
  • 1
    @opa if your logger has interesting business logic you isolate that and unit test it. Boring code that confirms we have a file system doesn't need unit testing. Commented Dec 14, 2018 at 22:36
  • @candied_orange So now you have to expose internal logic? Because how else are you going to separate the string generated by the logger before it is output to a file with separating it out into a private method? Commented Dec 14, 2018 at 22:54
  • @opa If you need to test that you can do it by passing in your own stream. Unit tests test units not system resources. Commented Dec 14, 2018 at 23:19
  • 1
    I think it's an answer because when I look at the actual code I found out that there is an asynchronous call of the main thread. Thus, the assertation is called after the delay, which is unacceptable for the speed of the unit test. Asynchronous call of the main thread should be mocked, in this case, I can say that it will be a unit test. Commented Dec 21, 2018 at 9:54