21
Testando a integração entre serviços Lucas Cavalcanti @lucascs https://github.com/lucascs

Testando a integracao entre serviços - Agile Brazil 2014

Embed Size (px)

Citation preview

Testando a integração

entre serviçosLucas Cavalcanti

@lucascs

https://github.com/lucascs

Um pouco de contexto

Sistema

https://www.flickr.com/photos/pargon/2444943158/

http://en.wikipedia.org/wiki/File:MasterCard_Logo.svg

http://commons.wikimedia.org/wiki/File:POS_device.jpg

Transações

Faturas

Contas e Limites

Dados do cliente

Dados de usuário

LocalizaçãoNotificações

MasterCard-client

Serviços

Clojure

iOS Android

Web

https://registry.hub.docker.com/_/clojure/

http://commons.wikimedia.org/wiki/File:Android_robot.png

http://commons.wikimedia.org/wiki/File:Mac.svg

http://commons.wikimedia.org/wiki/File:Google_Chrome_icon_(2011).png

Integração

Síncrona Assíncrona

HTTP

REST

Hypermedia

Kafka

JSON

mensagens padronizadas

Schemata(ns common-schemata.wire.payment)

(def links {:self {:schema link-schema

:allow #{:get}

:description "Entity. The owner should be able to GET it.”}})

(def skeleton

{:_links {:schema (csc/gen-schema links)}

:id {:required true :eg #uuid "d6e73cc5-95bc-496a-951c-87f11af0d838"

:schema UUID}

:post-date {:required true :eg #nu/date "2013-10-23"

:schema LocalDate}

:account-id {:required false :eg #uuid "d6e73cc5-95bc-496a-951c-87f11af0d839"

:schema UUID}

:time {:required false :eg #nu/time "2013-10-23T11:53:26Z"

:schema LocalDateTime}

:amount {:required false :eg 133700

:schema t-money/cents}

:precise-amount {:required false :eg 1337.00M

:schema t-money/precise-amount}})

Arquitetura Hexagonal

http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html

http://alistair.cockburn.us/Hexagonal+architecture

Testes de unidade

Testes de unidade

Testes de unidade

Testes de Unidade

(def internal-payment {:payment/id payment-id

:line-item/precise-amount -10.00M

:line-item/amount -1000

:line-item/account {:account/id account-id}

:line-item/time (time/date-time 2014 5 14 2 59 59)

:line-item/post-date (time/date 2014 5 13)})

(def external-payment {:id payment-id

:amount 1000

:paid -1000

:time (time/date-time 2014 5 14 2 59 59)

:post-date (time/date 2014 5 13) })

(sm/with-fn-validation

(fact “adapts internal representation to external”

(a-pmt/internal->wire internal-payment) => {:payment external-payment}))

Testes de integração

Contas

HTTP

Kafka msg

HTTP

Kafka msg

Testes de integração(fact "a new account is created on April”

(as-of (time/date-time 2020 4 2 13 37 42)

(next-state) => :account-created))

(fact "a purchase is made some days later”

(as-of (time/date-time 2020 4 4 13 37 0)

(next-state) => :with-txs))

(fact "as well as a payment”

(as-of (time/date-time 2020 4 6 13 37 0)

(next-state) => :paid-some-money))

(fact "they are all there”

(as-of (time/date-time 2020 4 9 13 37 0)

(next-state) => :with-stuff-appearing-on-the-bill))

(fact "we close the bill”

(as-of (time/date-time 2020 4 5 13 37 0)

(next-state) => :bill-closed))

(fact "two bills we now have”

(as-of (time/date-time 2020 6 8 13 37 0)

(next-state) => :bill-containing-new-charge))

Testes ponta a ponta

MasterCard-

client

MasterCard-

mock

Aquisição

Contas

Notificações

Testes ponta a ponta

describe "until account creation" do

it "adds a prospect to the waiting list" do...end

it "initiates an account request on behalf of a prospect" do...end

it "gets all account requests associated with the prospect" do...end

it "the new account request has a waiting status" do...end

it "sends an email invitation, including an invite code" do...end

it "fails to start the acquisition process with the wrong invite-code" do...end

it "engages, using the invite-code from the email" do...end

#...

end

Build pipeline

Build pipeline

Pendente

Testes Exploratórios

Testes Performance

Testes Carga

Obrigado!Lucas Cavalcanti

@lucascs

https://github.com/lucascs

www.nubank.com.br