bluGill,
bluGill avatar

Have you ever mocked your logger in a test, or wished you could? That is something like

TEST(some test name)

    mockLogger logger

    logger.expect_call(log("some string"))

    DoSomething(logger)

DmMacniel,

Why would you want to mock a logger? Aren’t the different Log Levels already enough?

bluGill,
bluGill avatar

@DmMacniel so you can prove some interesting thing is really logged? maybe someone else has a different reason.

henrikjernevad,
@henrikjernevad@mastodon.social avatar

@bluGill @DmMacniel If I want to log things that are important enough for me to test, I would consider creating a custom interface with individual functions for each important event. Then I would make one implementation of that interface which performs the corresponding logging, and another implementation which can be used for test. That way it becomes clear that the behavior is important, and avoids string parsing to extract the important information.

tve,

@bluGill If you have a need to mock a logger, you probably should have an interface dedicated to those logs.

It is also recommended to have dedicated loggers used in each domain, rather than allowing logging everything and everywhere, which may lead to sanitizing log inputs everywhere to be in control and not expose any security issues.

But in many cases that may also be overkill. As always, it depends.

bluGill,
bluGill avatar

@tve I didn't ask how to do it, I asked if anyone else has done it.

breadsmasher,
@breadsmasher@lemmy.world avatar

Nothing something I have felt the need to test directly, or mock.

But you absolutely can in Moq c#

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • DreamBathrooms
  • magazineikmin
  • GTA5RPClips
  • thenastyranch
  • InstantRegret
  • Youngstown
  • slotface
  • khanakhh
  • ngwrru68w68
  • rosin
  • kavyap
  • hgfsjryuu7
  • Durango
  • Backrooms
  • provamag3
  • everett
  • cubers
  • osvaldo12
  • cisconetworking
  • mdbf
  • tacticalgear
  • ethstaker
  • Leos
  • tester
  • normalnudes
  • modclub
  • anitta
  • JUstTest
  • All magazines