Testing Microservices: Testing Microservices: Testing Microservices: fast and with confidence fast and with confidence fast and with confidence
Stephan Jaensch Stephan Jaensch Stephan Jaensch @s_jaensch @s_jaensch @s_jaensch
1
TestingMicroservices: TestingMicroservices: TestingMicroservices: - - PowerPoint PPT Presentation
TestingMicroservices: TestingMicroservices: TestingMicroservices: fastandwithconfidence fastandwithconfidence fastandwithconfidence StephanJaensch StephanJaensch StephanJaensch @s_jaensch @s_jaensch @s_jaensch 1 2
1
2
3
Source: https://www.slideshare.net/danveloper/microservices-the-right-way
6
7
8
9
10
Construct request REMOTE SERVICE HTTP response Marshal data Validate request HTTP request Adapt HTTP response Validate response Unmarshal response 11
Construct request REMOTE SERVICE HTTP response Marshal data Validate request HTTP request Adapt HTTP response Validate response Unmarshal response Mock 12
class TestExampleHappyhourClient(): @pytest.fixture(autouse=True) def setup_teardown(self): with patch_clientlib() as mock_client: yield def test_get_hours_simple(): hours = get_hours_simple() assert hours == { 'SUN': {'time_start': 0, 'time_end': 0}, 'MON': {'time_start': 0, 'time_end': 0}, ... }
13
class TestExampleHappyhourClient(): @pytest.fixture(autouse=True) def setup_teardown(self): with patch_clientlib() as mock_client: mock_client.hours.getHours\ .set_return_value_and_status_code( return_value={ 'FRI': {'time_start': 21, 'time_end': 23}, 'SAT': {'time_start': 21, 'time_end': 23}, 'SUN': {'time_start': 21, 'time_end': 23}, }, status_code=200, ) yield
14
jsonschema.exceptions.ValidationError: 'id' is a required property
15
16
17
@s_jaensch
18