Test Driven Development

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    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

    5 Favorites

    Test Driven Development - Presentation Transcript

    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 ("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 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(
        • "Issue não gerada com sucesso!", issue);
        • Assert.assertTrue(
        • "Issue não gerada e id não atribuído", 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( "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 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) { ... } }
    SlideShare Zeitgeist 2009

    + Christiano MilfontChristiano Milfont Nominate

    custom

    1072 views, 5 favs, 3 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1072
      • 864 on SlideShare
      • 208 from embeds
    • Comments 0
    • Favorites 5
    • Downloads 36
    Most viewed embeds
    • 205 views on http://www.milfont.org
    • 2 views on http://feeds2.feedburner.com
    • 1 views on http://64.233.163.132

    more

    All embeds
    • 205 views on http://www.milfont.org
    • 2 views on http://feeds2.feedburner.com
    • 1 views on http://64.233.163.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags