Sobes.tech
Junior — Middle

What library did you use for creating mock objects in your projects?

sobes.tech AI

Answer from AI

In C# projects, the Moq library is often used to create mock objects. It is easy to use and integrates well with popular testing frameworks.

Example of using Moq:

var mock = new Mock<IRepository>();
mock.Setup(repo => repo.GetById(1)).Returns(new User { Id = 1, Name = "Test" });

var user = mock.Object.GetById(1);
// user.Name will be "Test"

Moq allows you to define the behavior of interface or class methods, which makes writing unit tests easier without depending on real implementations.