TestingMicroservices: TestingMicroservices: TestingMicroservices: - - PowerPoint PPT Presentation

testing microservices testing microservices testing
SMART_READER_LITE
LIVE PREVIEW

TestingMicroservices: TestingMicroservices: TestingMicroservices: - - PowerPoint PPT Presentation

TestingMicroservices: TestingMicroservices: TestingMicroservices: fastandwithconfidence fastandwithconfidence fastandwithconfidence StephanJaensch StephanJaensch StephanJaensch @s_jaensch @s_jaensch @s_jaensch 1 2


slide-1
SLIDE 1

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

slide-2
SLIDE 2

2

slide-3
SLIDE 3

Two years ago... Two years ago...

3

slide-4
SLIDE 4

The Testing Pyramid The Testing Pyramid

slide-5
SLIDE 5

The Testing Pyramid The Testing Pyramid

slide-6
SLIDE 6

Why end to end tests? Why end to end tests?

Source: https://www.slideshare.net/danveloper/microservices-the-right-way

6

slide-7
SLIDE 7

Flakes Flakes

7

slide-8
SLIDE 8

Improving speed and reducing Improving speed and reducing flakiness flakiness

slide-9
SLIDE 9

8

slide-10
SLIDE 10

Contract testing Contract testing

Bob Reselman Contract Testing is writing tests to ensure that the explicit and implicit contracts of your microservices work as advertised.

9

slide-11
SLIDE 11

A service call at Yelp A service call at Yelp

10

slide-12
SLIDE 12

Anatomy of a client library request Anatomy of a client library request

Construct request REMOTE SERVICE HTTP response Marshal data Validate request HTTP request Adapt HTTP response Validate response Unmarshal response 11

slide-13
SLIDE 13

Inject mock in client library Inject mock in client library

Construct request REMOTE SERVICE HTTP response Marshal data Validate request HTTP request Adapt HTTP response Validate response Unmarshal response Mock 12

slide-14
SLIDE 14

Patching the client library Patching the client library

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

slide-15
SLIDE 15

Providing a mock response Providing a mock response

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

slide-16
SLIDE 16

Mocks with errors Mocks with errors

jsonschema.exceptions.ValidationError: 'id' is a required property

15

slide-17
SLIDE 17

Conclusion Conclusion

End to end tests don't scale infinitely Contract tests are supposed to help We can leverage existing infrastructure to do consumer driven contract testing (sort of) We're relying on the fact that the service adheres to the specification

16

slide-18
SLIDE 18

17

slide-19
SLIDE 19

@s_jaensch

Questions? Questions?

sjaensch@yelp.com

18