Junior — Middle
What are mock tests, and what are they called?
sobes.tech AI
Answer from AI
Tests that use mocks are called mock tests with mock objects. Mocks are stub objects that imitate the behavior of real dependencies, allowing the tested component to be isolated.
Such tests verify the logic of a specific module without influence from external services or complex dependencies, which increases the speed and reliability of testing.
An example using the unittest.mock library in Python:
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'}