Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Stick to the rules!
Consumer Driven Contracts
Marcin Grzejszczak @mgrzejszczak
Jakub Kubrynski @jkubrynski
Jakub
Kubryński
@jkubrynski
www.kubrynski.com
Marcin
Grzejszczak
@mgrzejszczak
toomuchcoding.blogspot.com
TDD on architectural level
@mgrzejszczak @jkubrynski
What is
Consumer Driven Contract
@mgrzejszczak @jkubrynski
● Server
● Consumer
● Contract
Consumer Driven Contract
benefits
@mgrzejszczak @jkubrynski
Example
@mgrzejszczak @jkubrynski
Example
@mgrzejszczak @jkubrynski
How to solve it
@mgrzejszczak @jkubrynski
● Consumer’s tests
● Server tests
Contract definition
@mgrzejszczak @jkubrynski
● Contract defines communication
● Your stub is your contract - verify it!
●...
Consumer Technology
@mgrzejszczak @jkubrynski
Wiremock
http://wiremock.org
testCompile 'com.github.tomakehurst:wiremock:1....
Server Technology
@mgrzejszczak @jkubrynski
Accurate REST
https://github.com/Codearte/accurest
buildscript {
repositories ...
Server Technology
@mgrzejszczak @jkubrynski
Accurate REST
def shouldMarkClientAsNotFraud() {
given:
def request = given()
...
Example
@mgrzejszczak @jkubrynski
Live coding
@mgrzejszczak @jkubrynski
Q&A
@mgrzejszczak @jkubrynski
github.com/marcingrzejszczak/4developers_cdc_examples
Upcoming SlideShare
Loading in …5
×

4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

269 views

Published on

Marcin Grzejszczak, Jakub Kubryński

Language: English

Stick to the rules! Consumer Driven Contracts as a TDD on architectural level TDD introduced many improvements into development process, but in our opinion the biggest impact relates to code design. Looking at the code from the usage perspective (by first writing an acceptance test) allows us to focus on usability rather than concrete implementation. Unfortunately usually we rest on laurels not trying to uplift this practice into architecture level. Consumer driven contracts are like TDD applied to API. It’s especially important in the world of RESTful endpoints and microservices. Since it’s driven by consumers it’s much more user friendly. Of course microservices are really cool, but most people do not take into consideration plenty of potential obstacles that should be tackled. Then instead of frequent, fully automated deploys via delivery pipeline, you might end up in an asylum due to frequent mental breakdowns caused by production disasters. In this talk we will try to show you how to write tests of your microservice's contracts so that your chances to go down on production due to sending improper requests get lowered substantially. We’ll present how to move TDD to the architecture level and design the API from the consumer’s point of view.

Published in: Software
  • Be the first to comment

  • Be the first to like this

4Developers 2015: Stick to the rules - Consumer Driven Contracts - Marcin Grzejszczak, Jakub Kubryński

  1. 1. Stick to the rules! Consumer Driven Contracts Marcin Grzejszczak @mgrzejszczak Jakub Kubrynski @jkubrynski
  2. 2. Jakub Kubryński @jkubrynski www.kubrynski.com Marcin Grzejszczak @mgrzejszczak toomuchcoding.blogspot.com
  3. 3. TDD on architectural level @mgrzejszczak @jkubrynski
  4. 4. What is Consumer Driven Contract @mgrzejszczak @jkubrynski ● Server ● Consumer ● Contract
  5. 5. Consumer Driven Contract benefits @mgrzejszczak @jkubrynski
  6. 6. Example @mgrzejszczak @jkubrynski
  7. 7. Example @mgrzejszczak @jkubrynski
  8. 8. How to solve it @mgrzejszczak @jkubrynski ● Consumer’s tests ● Server tests
  9. 9. Contract definition @mgrzejszczak @jkubrynski ● Contract defines communication ● Your stub is your contract - verify it! ● Expose your stub to your consumers
  10. 10. Consumer Technology @mgrzejszczak @jkubrynski Wiremock http://wiremock.org testCompile 'com.github.tomakehurst:wiremock:1.53' { "request": { "method": "GET", "url": "/hello" }, "response": { "status": 200, "body": "Hello world!", "headers": { "Content-Type": "text/plain" } } }
  11. 11. Server Technology @mgrzejszczak @jkubrynski Accurate REST https://github.com/Codearte/accurest buildscript { repositories { mavenCentral() } dependencies { classpath 'io.codearte.accurest:accurest-gradle-plugin:0.5.0' } } apply plugin: 'accurest'
  12. 12. Server Technology @mgrzejszczak @jkubrynski Accurate REST def shouldMarkClientAsNotFraud() { given: def request = given() .header('Content-Type', 'application/frud+json') .body('{"clientPesel":"12345678901", "loanAmount":123.123}') when: def response = given().spec(request) .put("/fraudcheck") then: response.statusCode == 200 response.header('Content-Type') == 'application/fraud+json' and: def responseBody = parseText(response.body.asString()) responseBody.fraudCheckStatus == "OK" }
  13. 13. Example @mgrzejszczak @jkubrynski
  14. 14. Live coding @mgrzejszczak @jkubrynski
  15. 15. Q&A @mgrzejszczak @jkubrynski github.com/marcingrzejszczak/4developers_cdc_examples

×