What is test double vs mock framework?
Answer
A test double is any replacement for a real dependency in a test (the concept). A mock framework is a library that helps create test doubles (the tool). Without a framework, creating mocks means manually implementing interfaces: tedious and verbose. Mock frameworks generate these implementations dynamically at runtime. Examples: Moq (C#): var mock = new Mock<IUserService>(); mock.Setup(s => s.GetUser(1)).Returns(new User()); var service = mock.Object;. Mockito (Java): UserService mockService = mock(UserService.class); when(mockService.getUser(1)).thenReturn(new User());. Jest (JavaScript): const mockFn = jest.fn().mockReturnValue(42);. unittest.mock (Python): with patch('module.ClassName') as MockClass: MockClass.return_value.method.return_value = 'value'. Features of mock frameworks: setup return values, verify calls, argument matchers, capturing arguments, partial mocks (spies). Choose a framework with good IDE integration and readable error messages (Moq's error messages are excellent).
Previous
What is test containerization with Testcontainers?
Next
What is stubbing HTTP calls in tests?