Sobes.tech
Junior — Middle

Have you used mock objects for testing?

sobes.tech AI

Answer from AI

Yes, I have used Mock objects for testing. Mock objects allow replacing real dependencies (such as databases, external services) with simulations that behave predictably and controllably.

This is useful for:

  • Isolating the code under test from external factors
  • Speeding up tests, as no real calls are made
  • Verifying interactions with dependencies (such as method calls with specific parameters)

Example in Python using unittest.mock:

from unittest.mock import Mock

def fetch_data(api_client):
    return api_client.get_data()

mock_api = Mock()
mock_api.get_data.return_value = {'key': 'value'}

result = fetch_data(mock_api)
assert result == {'key': 'value'}
Have you used mock objects for testing? — QA / QA… - sobes.tech