SlideShare a Scribd company logo
Test Driven Development  [TDD] Christiano Milfont #XPCE 2009, Fortaleza Copyleft 2009 Milfont.org Desenvolvimento guiado a testes
Test Driven Development “ Desenvolvimento guiado por testes é um caminho de gerenciamento do medo durante a programação.” Kent Beck  -  Test Driven  Development by Example
Test Driven Development Standup Meeting @ 9h Pair Up Test First [Prática] Code Refactor Integrar ou Disponibilizar Ir para casa @ 17h
Test Driven Development O ritmo em 3 A’s Arrange [Criar um objeto] Act  [Invocar um método] Assert  [Verificar o resultado] Refactoring Workbook, Bill Wake
Test Driven Development RED - GREEN - REFACTOR Escreva um teste que não funciona. Escreva o código e faço-o funcionar. Refatore e elimine o código repetitivo.
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over Issue issue = member . createIssue (name) .withType( type ) .withLevel( level ) .withSummary( summary ) .toProject( project );
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void createIssueFromMember()  throws IllegalArgumentIssueException { member = new Member(); issue = member . createIssue ("Issue created"); Assert.assertNotNull( ISSUE_IN_NULL, issue); Assert.assertEquals( "State is not unconfirmed",  Status.UNCONFIRMED,  issue.getStatus()); }
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over issue =  new Member() . createIssue ("Issue created"); Assert. assertNotNull ( ISSUE_IN_NULL, issue); Assert. assertEquals ( "State is not unconfirmed",  Status.UNCONFIRMED,  issue.getStatus());
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over type = new Type(){{ this.setId(Long.valueOf(10)); this.setName(BUG); }}; member = new Member().withType(type); issue = member.getIssueInProgress(); Assert. assertNotNull (ISSUE_IN_NULL, issue); Assert. assertNotNull ("Type is null",  issue.getType()); Assert. assertTrue ("Type is not BUG",  issue.getType().getId() == type.getId()); Assert. assertTrue ("Type is not BUG", issue.getType().getName() == type.getName()); Assert. assertEquals ("Type is not BUG", issue.getType().getName(), BUG);
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void  createIssueFromMemberWithNameEmpty () { ... } @Test public void  setTypeInIssueFromMember () throws IllegalArgumentIssueException { … }
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over Issue issue = member .createIssue(name) .withType( type ) .withLevel( level ) .withSummary( summary ) .toProject( project ); Assert.assertNotNull( "Issue não gerada com sucesso!", issue); Assert.assertTrue( "Issue não gerada e id não atribuído", issue.getId() > 0);
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void  createIssueFromMemberWithNameNull() { try { issue =  new Member() .createIssue( null ); Assert.fail( "Didn't find expected exception of type " +  IllegalArgumentIssueException.class.getName()); }  catch (IllegalArgumentIssueException e) { Assert.assertEquals("Exception correctly catch",  "Name is null or empty“, e.getMessage()); } }
Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over
Test Driven Development Green Bar Patterns Fake It (‘till you make it) Triangulate Obvious Implementation One to Many
Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction("Add id value to issue") { public Object  invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } });}});
Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many @Test public void  setNullSummaryInIssueFromMember () {...} @Test public void  setSummaryInIssueFromMember () {...} @Test public void  setEmptySummaryInIssueFromMember () { ..}
Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”, issues.size()==1);
Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”,  issues.size()==1 );
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In @RunWith(JMock.class) public class  LifeCycleOfIssueInProjectTest  { ... } @RunWith(JMock.class) public class  ReportIssuesTest   { ... }
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object  invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } }); }});
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object  invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); repository.issues.add( ( (Issue) invocation.getParameter(0))); return null; } }); }}); ... Assert.assertTrue( repository.size() == 12 );
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In @Test public void  createIssueFromMemberWithNameNull() { try { issue =  new Member() .createIssue( null ); Assert. fail ( &quot;Didn't find expected exception of type &quot; +  IllegalArgumentIssueException.class.getName()); }  catch ( IllegalArgumentIssueException  e) { Assert.assertEquals(&quot; Exception correctly catch &quot;,  &quot; Name is null or empty “,  e.getMessage() ); } }
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”, issues.size()==1);
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks ... IssueRepository repository =  new FakeRepository(); List<Issue> issuesUnconfirmeds  = repository. getIssuesUnconfirmeds(); Assert.assertTrue(“blable”, issuesUnconfirmeds != null); ... public class FakeRepository implements IssueRepository { public List<Issue> getIssuesUnconfirmeds() { return new ArrayList<Issue>(); } }
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ ignoring (repository).count(); will ( returnValue(42)); }}); ... Assert.assertEquals( 12 ,  repository.count() );
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object  invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); repository.issues.add( ( (Issue) invocation.getParameter(0))); return null; } }); }}); ... Assert.assertTrue( repository.size() == 12 );
Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object  invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } }); }});
Test Driven Development Fixture Setup Setup Tear Down @Before public void setUp() throws Exception { Connection conn; try { ... IDatabaseConnection connection =  new DatabaseConnection(conn); DatabaseOperation.INSERT.execute(connection,  new FlatXmlDataSet( new FileInputStream(  “ issuetrackr.xml&quot;))); conn.close(); } catch (Exception exc) { ...  } }

More Related Content

ODP
Testing in-groovy
PDF
Pyconie 2012
PPTX
Pragmatic unittestingwithj unit
PDF
JUnit Kung Fu: Getting More Out of Your Unit Tests
PDF
Auto testing!
PDF
Developer Test - Things to Know
ODP
Grails unit testing
PDF
Effective Unit Testing
Testing in-groovy
Pyconie 2012
Pragmatic unittestingwithj unit
JUnit Kung Fu: Getting More Out of Your Unit Tests
Auto testing!
Developer Test - Things to Know
Grails unit testing
Effective Unit Testing

What's hot (20)

PDF
TDD CrashCourse Part3: TDD Techniques
PDF
PDF
Sample Chapter of Practical Unit Testing with TestNG and Mockito
PDF
JUnit Pioneer
KEY
Test-Driven Development for TYPO3
PDF
Example First / A Sane Test-Driven Approach to Programming
PPT
Google mock for dummies
PPT
3 j unit
PPTX
Grails Spock Testing
PDF
Unit test-using-spock in Grails
PDF
Agile mobile
PDF
Not your father's tests
PPSX
PDF
Test driven development
KEY
Unit Test Your Database
PPTX
TDD Training
KEY
Test-Driven Development for TYPO3 @ T3CON12DE
KEY
Test-driven Development for TYPO3
PDF
An introduction to Google test framework
PDF
C++ Unit Test with Google Testing Framework
TDD CrashCourse Part3: TDD Techniques
Sample Chapter of Practical Unit Testing with TestNG and Mockito
JUnit Pioneer
Test-Driven Development for TYPO3
Example First / A Sane Test-Driven Approach to Programming
Google mock for dummies
3 j unit
Grails Spock Testing
Unit test-using-spock in Grails
Agile mobile
Not your father's tests
Test driven development
Unit Test Your Database
TDD Training
Test-Driven Development for TYPO3 @ T3CON12DE
Test-driven Development for TYPO3
An introduction to Google test framework
C++ Unit Test with Google Testing Framework
Ad

Viewers also liked (9)

PPT
Behaviour Driven Development
ODP
BDD com Cucumber, Selenium e Rails
PDF
Domain driven design
ODP
Mvc sem Controller
PDF
Apresentando Extreme Programming
PPT
Mare de Agilidade - BDD e TDD
ODP
Combinando OO e Funcional em javascript de forma prática
PDF
Equipes sem Líderes formais e realmente autogeridas
ODP
Engine de template em Javascript com HTML Sprites
Behaviour Driven Development
BDD com Cucumber, Selenium e Rails
Domain driven design
Mvc sem Controller
Apresentando Extreme Programming
Mare de Agilidade - BDD e TDD
Combinando OO e Funcional em javascript de forma prática
Equipes sem Líderes formais e realmente autogeridas
Engine de template em Javascript com HTML Sprites
Ad

Similar to Test Driven Development (20)

PDF
33rd Degree 2013, Bad Tests, Good Tests
PPT
2012 JDays Bad Tests Good Tests
PDF
2013 DevFest Vienna - Bad Tests, Good Tests
PPTX
Unit Testing with JUnit4 by Ravikiran Janardhana
PPT
Test Infected Presentation
ODP
Presentation Unit Testing process
PDF
TDD CrashCourse Part4: Improving Testing
PDF
PPT
Security Testing
ODP
Data-Driven Unit Testing for Java
PPTX
PPTX
Dat testing - An introduction to Java and Android Testing
PPTX
Junit_.pptx
PPTX
Advance unittest
PPTX
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
PDF
"How keep normal blood pressure using TDD" By Roman Loparev
PDF
Pitfalls Of Tdd Adoption by Bartosz Bankowski
PDF
Software Testing
PPTX
Presentation
PDF
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
33rd Degree 2013, Bad Tests, Good Tests
2012 JDays Bad Tests Good Tests
2013 DevFest Vienna - Bad Tests, Good Tests
Unit Testing with JUnit4 by Ravikiran Janardhana
Test Infected Presentation
Presentation Unit Testing process
TDD CrashCourse Part4: Improving Testing
Security Testing
Data-Driven Unit Testing for Java
Dat testing - An introduction to Java and Android Testing
Junit_.pptx
Advance unittest
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
"How keep normal blood pressure using TDD" By Roman Loparev
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Software Testing
Presentation
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...

More from Milfont Consulting (20)

ODP
Continuous integration e continuous delivery para salvar o seu projeto!
ODP
ODP
MVC Model 3
ODP
Dar caos à ordem
ODP
I TDD my jQuery code without Browser
PDF
Oxente BDD
PDF
Construindo WebApps ricas com Rails e Sencha
PDF
Dar Ordem ao Caos
PPT
Primeiro Dia Livre Opensocial
ODP
Tw Dwr 2007 Ap01
PPT
Course Hibernate 2008
PDF
Opensocial
PPT
Frameworks Ajax
PDF
OpenSocial CCT
PDF
PDF
Conhecendo a JSR 223: Scripting for the Java Platform
ODP
Ajaxificando
PDF
Integração Contínua 3FCSL
PPT
Extreme Programming
PDF
Sead 29 09 2006 Usabilidade Com Ajax
Continuous integration e continuous delivery para salvar o seu projeto!
MVC Model 3
Dar caos à ordem
I TDD my jQuery code without Browser
Oxente BDD
Construindo WebApps ricas com Rails e Sencha
Dar Ordem ao Caos
Primeiro Dia Livre Opensocial
Tw Dwr 2007 Ap01
Course Hibernate 2008
Opensocial
Frameworks Ajax
OpenSocial CCT
Conhecendo a JSR 223: Scripting for the Java Platform
Ajaxificando
Integração Contínua 3FCSL
Extreme Programming
Sead 29 09 2006 Usabilidade Com Ajax

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
KodekX | Application Modernization Development
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
KodekX | Application Modernization Development
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity

Test Driven Development

  • 1. Test Driven Development [TDD] Christiano Milfont #XPCE 2009, Fortaleza Copyleft 2009 Milfont.org Desenvolvimento guiado a testes
  • 2. Test Driven Development “ Desenvolvimento guiado por testes é um caminho de gerenciamento do medo durante a programação.” Kent Beck - Test Driven Development by Example
  • 3. Test Driven Development Standup Meeting @ 9h Pair Up Test First [Prática] Code Refactor Integrar ou Disponibilizar Ir para casa @ 17h
  • 4. Test Driven Development O ritmo em 3 A’s Arrange [Criar um objeto] Act [Invocar um método] Assert [Verificar o resultado] Refactoring Workbook, Bill Wake
  • 5. Test Driven Development RED - GREEN - REFACTOR Escreva um teste que não funciona. Escreva o código e faço-o funcionar. Refatore e elimine o código repetitivo.
  • 6. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over
  • 7. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over Issue issue = member . createIssue (name) .withType( type ) .withLevel( level ) .withSummary( summary ) .toProject( project );
  • 8. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void createIssueFromMember() throws IllegalArgumentIssueException { member = new Member(); issue = member . createIssue (&quot;Issue created&quot;); Assert.assertNotNull( ISSUE_IN_NULL, issue); Assert.assertEquals( &quot;State is not unconfirmed&quot;, Status.UNCONFIRMED, issue.getStatus()); }
  • 9. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over issue = new Member() . createIssue (&quot;Issue created&quot;); Assert. assertNotNull ( ISSUE_IN_NULL, issue); Assert. assertEquals ( &quot;State is not unconfirmed&quot;, Status.UNCONFIRMED, issue.getStatus());
  • 10. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over type = new Type(){{ this.setId(Long.valueOf(10)); this.setName(BUG); }}; member = new Member().withType(type); issue = member.getIssueInProgress(); Assert. assertNotNull (ISSUE_IN_NULL, issue); Assert. assertNotNull (&quot;Type is null&quot;, issue.getType()); Assert. assertTrue (&quot;Type is not BUG&quot;, issue.getType().getId() == type.getId()); Assert. assertTrue (&quot;Type is not BUG&quot;, issue.getType().getName() == type.getName()); Assert. assertEquals (&quot;Type is not BUG&quot;, issue.getType().getName(), BUG);
  • 11. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void createIssueFromMemberWithNameEmpty () { ... } @Test public void setTypeInIssueFromMember () throws IllegalArgumentIssueException { … }
  • 12. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over Issue issue = member .createIssue(name) .withType( type ) .withLevel( level ) .withSummary( summary ) .toProject( project ); Assert.assertNotNull( &quot;Issue não gerada com sucesso!&quot;, issue); Assert.assertTrue( &quot;Issue não gerada e id não atribuído&quot;, issue.getId() > 0);
  • 13. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over @Test public void createIssueFromMemberWithNameNull() { try { issue = new Member() .createIssue( null ); Assert.fail( &quot;Didn't find expected exception of type &quot; + IllegalArgumentIssueException.class.getName()); } catch (IllegalArgumentIssueException e) { Assert.assertEquals(&quot;Exception correctly catch&quot;, &quot;Name is null or empty“, e.getMessage()); } }
  • 14. Test Driven Development Red Bar Patterns One Step Test Starter Test Explanation Test Learning Test Another Test Regression Test Break Do Over
  • 15. Test Driven Development Green Bar Patterns Fake It (‘till you make it) Triangulate Obvious Implementation One to Many
  • 16. Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } });}});
  • 17. Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many @Test public void setNullSummaryInIssueFromMember () {...} @Test public void setSummaryInIssueFromMember () {...} @Test public void setEmptySummaryInIssueFromMember () { ..}
  • 18. Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”, issues.size()==1);
  • 19. Test Driven Development Green Bar Patterns Fake It (Till you make it) Triangulate Obvious Implementation One to Many ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”, issues.size()==1 );
  • 20. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
  • 21. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In @RunWith(JMock.class) public class LifeCycleOfIssueInProjectTest { ... } @RunWith(JMock.class) public class ReportIssuesTest { ... }
  • 22. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } }); }});
  • 23. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); repository.issues.add( ( (Issue) invocation.getParameter(0))); return null; } }); }}); ... Assert.assertTrue( repository.size() == 12 );
  • 24. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
  • 25. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In @Test public void createIssueFromMemberWithNameNull() { try { issue = new Member() .createIssue( null ); Assert. fail ( &quot;Didn't find expected exception of type &quot; + IllegalArgumentIssueException.class.getName()); } catch ( IllegalArgumentIssueException e) { Assert.assertEquals(&quot; Exception correctly catch &quot;, &quot; Name is null or empty “, e.getMessage() ); } }
  • 26. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
  • 27. Test Driven Development Testing Patterns Child Test Mock Object Self Shunt Log String Crash Test Dummy Broken Test Clean Check-In
  • 28. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks
  • 29. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks ... List<Issue> issues = new ArrayList<Issue>() { { this.add( new Issue(Long.valueOf(134)) ); } }... Assert.assertTrue(“blable”, issues.size()==1);
  • 30. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks ... IssueRepository repository = new FakeRepository(); List<Issue> issuesUnconfirmeds = repository. getIssuesUnconfirmeds(); Assert.assertTrue(“blable”, issuesUnconfirmeds != null); ... public class FakeRepository implements IssueRepository { public List<Issue> getIssuesUnconfirmeds() { return new ArrayList<Issue>(); } }
  • 31. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ ignoring (repository).count(); will ( returnValue(42)); }}); ... Assert.assertEquals( 12 , repository.count() );
  • 32. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); repository.issues.add( ( (Issue) invocation.getParameter(0))); return null; } }); }}); ... Assert.assertTrue( repository.size() == 12 );
  • 33. Test Driven Development Test Double Dummy Fake Stubs Spies Mocks context.checking(new Expectations() {{ oneOf (repository).persist(with(any(Issue.class))); will (new CustomAction(&quot;Add id value to issue&quot;) { public Object invoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } }); }});
  • 34. Test Driven Development Fixture Setup Setup Tear Down @Before public void setUp() throws Exception { Connection conn; try { ... IDatabaseConnection connection = new DatabaseConnection(conn); DatabaseOperation.INSERT.execute(connection, new FlatXmlDataSet( new FileInputStream( “ issuetrackr.xml&quot;))); conn.close(); } catch (Exception exc) { ... } }

Editor's Notes

  • #2: Necessidade rara de debugar Facilidade em capturar erros antes de irem para produção Economia no retrabalho Guiado a criar codigo altamente coeso e com baixo acomplamento, mais modularizado, extensivel e flexivel, portanto de fácil manutenção. Matematico processo de assertions e precondições [Design by contracts] Principio de pareto 80-20 80% das consequências advém de 20% das causas