Test Driven Development

Embed Size (px)

Text of 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 programao.
  • Kent Beck-Test Driven
  • Development by Example

3. Test Driven Development Standup Meeting @ 9h Pair Up Test First [Prtica] Code Refactor Integrar ou Disponibilizar Ir para casa @ 17h 4. Test Driven Development

  • O ritmo em 3 As
  • Arrange [Criar um objeto]
  • Act[Invocar um mtodo]
  • Assert[Verificar o resultado]
  • Refactoring Workbook, Bill Wake

5. Test Driven Development

  • RED - GREEN - REFACTOR
  • Escreva um teste que no funciona.
  • Escreva o cdigo e fao-o funcionar.
  • Refatore e elimine o cdigo 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 ("Issue created"); Assert.assertNotNull( ISSUE_IN_NULL, issue); Assert.assertEquals( "State is not unconfirmed",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 ("Issue created"); Assert. assertNotNull ( ISSUE_IN_NULL, issue); Assert. assertEquals ( "State is not unconfirmed",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 ("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); 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 voidcreateIssueFromMemberWithNameEmpty () { ... } @Test public voidsetTypeInIssueFromMember () 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(
    • "Issue no gerada com sucesso!", issue);
    • Assert.assertTrue(
    • "Issue no gerada e id no atribudo", 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 voidcreateIssueFromMemberWithNameNull() { 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()); } } 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("Add id value to issue") { public Objectinvoke (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 voidsetNullSummaryInIssueFromMember () {...} @Test public voidsetSummaryInIssueFromMember () {...} @Test public voidsetEmptySummaryInIssueFromMember () { ..} 18. Test Driven Development

  • Green Bar Patterns
  • Fake It (Till you make it)
  • Triangulate
  • Obvious Implementation
  • One to Many

... List issues = new ArrayList() { { 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 issues = new ArrayList() { { 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 classLifeCycleOfIssueInProjectTest{ ... } @RunWith(JMock.class) public classReportIssuesTest { ... } 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("Add id value to issue") { public Objectinvoke (Invocation invocation) throws Throwable { ( (Issue) invocation.getParameter(0)). setId(Long.valueOf(1)); return null; } }); }}); 23. Test D