Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro Testing Pains

Micro Testing Pains

Micro services are a wonderful thing! Until you try to test them in integration. Do you write a stub for each service? Point them to a test environment? Raise local instances for every dependency? I've tried all these approaches and they are all painful. Can't we can do better?

Yes we can! On this talk we will discuss Consumer Driven Contracts, a better way to deal with integration tests in a micro services environment.

Marcos Castilho da Costa Matos

September 26, 2014
Tweet

More Decks by Marcos Castilho da Costa Matos

Other Decks in Programming

Transcript

  1. Conservation of energy complexity principle ! The total complexity in

    a system remains the same 19 Some smart guys
  2. 39 GET /users/:username a request { name: String, age: Integer

    } a response The important bit is the structure, not the data
  3. The consumer run its tests against the contract Provider While

    the contract validates itself against the provider Consumer Integrated Tests A Contract Validation B
  4. 49 {! "name": “Get User By Name",! "request": {! "headers":

    {! "Content-Type": "application/json"! },! "http_method": "get",! "path": “/user/:username",! },! "response": {! "status": 201,! "properties": {! "email": {! "type": "string"! }! }! }! } A Pacto Contract
  5. 50 require 'pacto'! require 'pacto/spec'! require 'faraday'! ! before do!

    ! cts = Pacto.load_contracts('contracts', 'http://localhost:5000')! ! cts.stub_providers! end! ! describe 'Isolated testes' do! it 'are awesome' do! conn = Faraday.new(url: 'http://localhost:5000')! response = conn.get '/user/marcosccm'! ! ! expect(response["email"]).to_not be_nil! end ! end Stubbing producers
  6. 52 Precise error messages! Investigation:! Request: #<Pacto::PactoRequest:0x007fc28dd5c508>! Contract: contracts/get_user_by_name.json! Citations:

    ! ! ! The property '#/name' of type string did not match ! the following type: array ! in schema contracts/get_user_by_name.json
  7. Service A evolves it’s features using the contract While service

    B uses the contract to validate the development of the feature Consumer Provider B A Parallel Development
  8. Consumers Provider A B C D A Provider knows exactly

    how it’s functionality is used
  9. Consumer Providers A B C D A Consumer knows precisely

    when one of it’s dependencies is broken
  10. Wanna know more? ! Ian Robinson on Consumer Driven Contracts

    http://iansrobinson.com/2008/03/27/a-contract-vocabulary-part-1 ! Martin Fowler on Micro Services http://martinfowler.com/articles/microservices.html http://martinfowler.com/bliki/MicroservicePrerequisites.html ! Pacto’s Aussie Brother https://github.com/realestate-com-au/pact 68