KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm curious as to what method people like to use for mocking and why . The two methods that I know of are using hard coded mock objects and a mocking framework. To demonstrate, I'll outline an example using C#. Suppose we have an IEmployeeRepository interface with a method called GetEmployeeById. public interface IEmployeeRepository { Employee GetEmployeeById(long id); } We can easily create a mock of this: public class MockEmployeeRepository : IEmployeeRepository { public Employee GetEmployeeById(long id) { Employee employee = new Employee(); employee.FirstName = "First"; employee.LastName = "Last"; ... return employee; } } Then, in our tests we can explicitly tell our services to use the MockEmployeeRepository, either using a setter or dependency injection. I'm new to mocking frameworks so I'm curious as to why we use them, if we can just do the above?
Tags (comma-separated)
Save Edits
Cancel