26
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 2 Construa testes efetivos através do princípio F.I.R.S.T Elder Moraes | @elderjava Developer Advocate Abril, 2019

Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 2

ConstruatestesefetivosatravésdoprincípioF.I.R.S.T

ElderMoraes|@elderjavaDeveloperAdvocateAbril,2019

Page 2: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

SafeHarborStatement

Thefollowingisintendedtooutlineourgeneralproductdirection.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,timing,andpricingofanyfeaturesorfunctionalitydescribedforOracle’sproductsmaychangeandremainsatthesolediscretionofOracleCorporation.

Page 3: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 4

Page 4: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 5

FIRST

ASTNDEPENDENTEPEATABLEELF-VALIDATINGIMELY

Page 5: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Seostestesforemlentos,vocênãovaiquererexecutá-loscomfrequência

•  Sevocênãoosexecutacomfrequência,nãoencontraráproblemascedoosuficienteparacorrigí-losfacilmente

6

FAST

Page 6: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

Oquepodefazerumtesteserlento

7

FAST

Execuçãomanual

Validaçãomanual

Aprópriaexecuçãodoteste

Page 7: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Eliminandoaexecuçãomanual– Frameworks:JUnit,Arquillian,Selenium,Mockito,Wiremock

– Automações:Maven,Gradle,Jenkins,Vagrant,Ansible,DockerCompose

– Monitoramento:Grafana,Prometheus,Jaeger

8

FAST

Page 8: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Eliminandoavalidaçãomanual– VideSELF-VALIDATING

9

FAST

Page 9: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Eliminandolentidãonopróprioteste– Identificaçãodospontosdelentidão(bancodedados,integração,rede,etc)– Refatoraçãodecódigo– Mocking

10

FAST

Page 10: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

• Umtestenãodevedependerdooutro

• Umtestenãodevecriarascondiçõesparaopróximoteste

• Vocêdevesercapazdeexecutarcadatesteindividualmenteeexecutartodosostestesemqualquerordem

• Quandoostestesdependeunsdosoutros,oprimeiroafalharcausaumareaçãoemcadeia,dificultandoodiagnósticoeescondendodefeitosquepossamestaradiante

11

I NDEPENDENT

Page 11: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

• Comoeliminardependênciaentretestes– Altacoesão– DRY(Don’tRepeatYourself)

12

I NDEPENDENT

“Wewanttodesigncomponentsthatareself-contained:independent,andwithasingle,well-definedpurpose”

-ThePragmaticProgrammer

Page 12: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

• Comoeliminardependênciaentretestes– Baixoacoplamento

13

I NDEPENDENT

VS

Page 13: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 14

Page 14: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Testesdeveserreproduzíveisemqualquerambiente

• Produção,QA,laptop(mesmosemrede)

• Docontrário,vocêsempreteráumadesculpaparanãoexecutá-los

• Alémdisso,nãoconseguiráexecutá-losquandooambientenãoestiverdisponível

15

REPEATABLE

Page 15: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Eliminandoadependênciadeambientes

16

REPEATABLE

BancodeDados SistemaOperacional DeployeExecução

Page 16: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Eliminandoadependênciadeambientes

17

REPEATABLE

Page 17: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

Vagrantfile

18

Page 18: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Testesdevemserauto-explicativos:passou/falhou• Otestenãodeveexigirque*você*:– Leiaumlog

– Comparedoisarquivos

– Vejaumatela

– Etc…

•  Senãoforemauto-explicativos,entãoafalhapodesersubjetiva

•  Levaàdemoranavalidação(efalhanoprincípioFAST)

19

SELF-VALIDATING

Page 19: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 20

Page 20: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 21

Page 21: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

•  Testesdevemserescritosoquantoantes

•  Sevocêesperaumcódigoentraremproduçãoparaescreveroteste,podeacabardescobrindoqueédifíciltestá-lo

• Aofazerissocontinuamente,logovocêterátodoseucódigodeproduçãoimpossíveldesertestado

22

TIMELY

Page 22: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

“Testsareasimportant… astheproductioncodeis.Perhapstheyareevenmoreimportant,becausetestspreserveandenhancetheflexibility,maintainability,andreusabilityoftheproductioncode.”

–  RoberC.Martin,“CleanCode”

Confidential–OracleInternal/Restricted/HighlyRestricted 23

Page 23: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

@elderjavabook.eldermoraes.com

Page 24: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.|

Java@CloudAge

bit.ly/javacloudage

Page 25: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 26

Visiteonossoestande

Façaumtrial

Ganheumbrinde!

Façaumhandson

Ganheoutrobrinde!

Page 26: Construa testes efetivos através do princípio F.I.R.S€¦ · Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended

Copyright©2019,Oracleand/oritsaffiliates.Allrightsreserved.| 27