testing microservices testing microservices testing
play

TestingMicroservices: TestingMicroservices: TestingMicroservices: - PowerPoint PPT Presentation

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


  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

  2. 2

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

  4. The Testing Pyramid The Testing Pyramid

  5. The Testing Pyramid The Testing Pyramid

  6. Why end to end tests? Why end to end tests? Source: https://www.slideshare.net/danveloper/microservices-the-right-way 6

  7. Flakes Flakes 7

  8. Improving speed and reducing Improving speed and reducing flakiness flakiness

  9. 8

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

  11. A service call at Yelp A service call at Yelp 10

  12. Anatomy of a client library request Anatomy of a client library request Construct Unmarshal request response Validate Marshal data response Validate Adapt HTTP request response HTTP request HTTP response REMOTE SERVICE 11

  13. Inject mock in client library Inject mock in client library Construct Unmarshal request response Validate Marshal data response Validate Adapt HTTP Mock request response HTTP request HTTP response REMOTE SERVICE 12

  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

  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

  16. Mocks with errors Mocks with errors jsonschema.exceptions.ValidationError: 'id' is a required property 15

  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

  18. 17

  19. Questions? Questions? sjaensch@yelp.com @s_jaensch 18

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend