Successfully reported this slideshow.

Resilience testing with Wiremock and Spock

5

Share

Loading in …3
×
1 of 29
1 of 29

Resilience testing with Wiremock and Spock

5

Share

Download to read offline

Short tutorial for using Wiremock in your unit tests.
Links to https://github.com/koenighotze/wiremock-tryout

Short tutorial for using Wiremock in your unit tests.
Links to https://github.com/koenighotze/wiremock-tryout

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Resilience testing with Wiremock and Spock

  1. 1. <david.schmitz@senacor.com> Resilient Services with Wiremock Effective REST tests using Wiremock and Spock https://flic.kr/p/orejhX
  2. 2. <david.schmitz@senacor.com> How does your system handle failures?
  3. 3. <david.schmitz@senacor.com> Everybody tests the happy path… https://flic.kr/p/9MHEme
  4. 4. <david.schmitz@senacor.com> Happy Path Tests HTTP/1.1 200 OK {“publicId":"42634558","data":"foo"} GET http://service/resource/12 Client Service
  5. 5. <david.schmitz@senacor.com> But what about the not-so-happy path? https://flic.kr/p/CSnr1
  6. 6. <david.schmitz@senacor.com> Enter Wiremock • Stub and Mock framework for testing HTTP(s) traffic • Features include • Request verification, • record, playback, • fault injection, • unit test and stand alone Client Unit Test Embedded Wiremock Client Standalone Wiremock
  7. 7. <david.schmitz@senacor.com> How does it work? Client Wiremock Request Mapping Response Data $ curl -H ‘Accept: application/json’ http://localhost:8080/sample/
  8. 8. <david.schmitz@senacor.com> How does it work? Client Wiremock Request Mapping Response Data • Starts embedded Jetty Server • Acts as a proxy to the actual service • Is used by the client transparently
  9. 9. <david.schmitz@senacor.com> How does it work? Client Wiremock Request Mapping Response Data "request" : { "url" : "/sample/", "method" : "GET", } } }, "response" : { "status" : 200, "bodyFileName" : "body.json", "headers" : { "Content-Type" : “application/json" … } }
  10. 10. <david.schmitz@senacor.com> How does it work? Client Wiremock Request Mapping Response Data body.json: [{"publicId":"...","data":"..."}, {"publicId":"...","data":"..."}]
  11. 11. <david.schmitz@senacor.com> Creating a Wiremock Unittest Prepare Stub Configure Wiremock Consume REST service
  12. 12. <david.schmitz@senacor.com> Creating a Wiremock Unittest Prepare Stub Configure Wiremock Consume REST service
  13. 13. <david.schmitz@senacor.com> Creating a Wiremock Unittest Prepare Stub Configure Wiremock Consume REST service
  14. 14. <david.schmitz@senacor.com> Creating a Wiremock Unittest Prepare Stub Configure Wiremock Consume REST service
  15. 15. <david.schmitz@senacor.com> Creating a Wiremock Unittest Prepare Stub Configure Wiremock Consume REST service
  16. 16. <david.schmitz@senacor.com> …but what about failures? HTTP/1.1 503 Service Unavailable Client Service GET http://service/resource/12
  17. 17. <david.schmitz@senacor.com> Testing Failures
  18. 18. <david.schmitz@senacor.com> …but what about bad responses? Client Service HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 [300 MB of random garbage] GET http://service/resource/12
  19. 19. <david.schmitz@senacor.com> Testing Unexpected Behavior
  20. 20. <david.schmitz@senacor.com> …but what about timeouts? java.net.SocketTimeoutException: Read timed out Client Service GET http://service/resource/12
  21. 21. <david.schmitz@senacor.com> Testing the circuit breaker
  22. 22. Record and Playback https://flic.kr/p/nRXLqh
  23. 23. <david.schmitz@senacor.com> Record and Playback Run requests Start Wiremock in record mode Start Wiremock in playback mode
  24. 24. <david.schmitz@senacor.com> Record and Playback Demo
  25. 25. <david.schmitz@senacor.com> Summary • Resilience can be tested • Do not rely on happy paths and mocks only • Use stubs and verify in unit tests • Use record and playback for external services • Make sure not to be the developer responsible for a downtime during the busy-business-time :D
  26. 26. <david.schmitz@senacor.com> Links http://wiremock.org/ https://github.com/koenighotze/wiremock-tryout/
  27. 27. <david.schmitz@senacor.com> THANK YOU! <david.schmitz@senacor.com>
  28. 28. <david.schmitz@senacor.com> BACKUP
  29. 29. <david.schmitz@senacor.com> Testing a Client Client Unit Test Embedded Wiremock

×