Mid OOP

How do you mock interfaces in unit testing?

  • Use mocking frameworks like Moq or NSubstitute.
  • Provides fake implementations to test dependent classes.

var mockLogger = new Mock<ILogger>();

mockLogger.Setup(x => x.Log(It.IsAny<string>()));

More from C# Programming Tutorial

All questions for this course