Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Assorted TDD tipsWojciech BulatyMarch 2013
Wojtek Bulaty4 years TDDPair programmingXP
7 things I wish somebody told mewhen I was starting with TDDMy story – what I learned?For beginners and strugglers
Scratch the surface today
TDD IS A TOOLNo 1
●Cheap●Light●No electricity●Needs strong hands●Etc…●More expensive●Heavier●Needs electricity●No need for strong hands●Etc.…
Good tool? Bad tool?Depends on the context (constraints)!
Want to use the “TDD” tool?
Think Constraints!Time & budgetSkillsLong term/short term goals
Informed decisions means lessrisky decisionsLess risky decisions means moresuccess and less failure
Tests are good! Tests are bad!TDD is a tool
TDD IS A SKILLNo 2
Pain?More problems than benefitsTDD was supposed to be fun!
TDD is a skillLearn it!
Software developerJavaOOMultithreadingTDD
Pain?You are doing it wrong!
TDD IS SOFTWARE DESIGNNo 3
MocksFocus on OO signalsSOLID
Acceptance testsLess coupling
TDD as a design toolTry it at homeLook at the differences
TDD designSmall feedback loop
TDD IS DOCUMENTATIONNo. 4
Good documentation●Always up to date●Executable●Refactorable●OO– SOLID– DRY– etc…●Text documents? Wiki? …?
Tests are like that!Me likey!
SkyVery good documentation
Sky documentation exampleTimeWindowEnforcementTest.html
It is called Yatspec!TimeWindowEnforcementTest.html
Tests document!Remember about it
TDD FOCUS ON GOALSNo. 5
Start with goalsWhat do I really want to do?When do I know I am done?
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {verify(supportTea...
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {userMailer.passwo...
public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {doThrow(exception...
import static org.mockito.Matchers.anyString;import static org.mockito.Mockito.*;public class UserMailerTest {private fina...
Shorter paths to your goals!YAGNI
TESTS INCREASE COUPLINGNo 6
Loose coupling?Me likey!
Unit testsMocks? Implementation details!Stubs & State? Still coupled to units!Refactoring? Nein!Good? Bad?Remember about t...
Module testsLess coupling than unitsMore test infrastructureRefactoring? A bit?Good? Bad?Remember about trade-offs!
Acceptance testsEnd to end testsetc...As little coupling as possibleBig testing infrastructureRefactoring? No problems!
Modify prod codeHow many tests fail?Definition of coupling man!
SkyDuplication in testsUnmaintainable unit tests
Tests increase coupling?Keep that in mind!Remember about trade-offs!
PRACTICE KATANo. 7
“Practice makes perfect”
Professionals practiceTDD Kata / TDD ToyCode retreat
What I learned so far●TDD is a skill – learn it●TDD is a tool – know when to use it●TDD is software design - sometimes●TDD...
Want moar?●Growing Object-Oriented Software Guided by Tests●Loads of other books – read them all●http://martinfowler.com/●...
Feedback
Questions?
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Assorted TDD tips
Upcoming SlideShare
Loading in …5
×

Assorted TDD tips

1,145 views

Published on

  • Be the first to comment

Assorted TDD tips

  1. 1. Assorted TDD tipsWojciech BulatyMarch 2013
  2. 2. Wojtek Bulaty4 years TDDPair programmingXP
  3. 3. 7 things I wish somebody told mewhen I was starting with TDDMy story – what I learned?For beginners and strugglers
  4. 4. Scratch the surface today
  5. 5. TDD IS A TOOLNo 1
  6. 6. ●Cheap●Light●No electricity●Needs strong hands●Etc…●More expensive●Heavier●Needs electricity●No need for strong hands●Etc.…
  7. 7. Good tool? Bad tool?Depends on the context (constraints)!
  8. 8. Want to use the “TDD” tool?
  9. 9. Think Constraints!Time & budgetSkillsLong term/short term goals
  10. 10. Informed decisions means lessrisky decisionsLess risky decisions means moresuccess and less failure
  11. 11. Tests are good! Tests are bad!TDD is a tool
  12. 12. TDD IS A SKILLNo 2
  13. 13. Pain?More problems than benefitsTDD was supposed to be fun!
  14. 14. TDD is a skillLearn it!
  15. 15. Software developerJavaOOMultithreadingTDD
  16. 16. Pain?You are doing it wrong!
  17. 17. TDD IS SOFTWARE DESIGNNo 3
  18. 18. MocksFocus on OO signalsSOLID
  19. 19. Acceptance testsLess coupling
  20. 20. TDD as a design toolTry it at homeLook at the differences
  21. 21. TDD designSmall feedback loop
  22. 22. TDD IS DOCUMENTATIONNo. 4
  23. 23. Good documentation●Always up to date●Executable●Refactorable●OO– SOLID– DRY– etc…●Text documents? Wiki? …?
  24. 24. Tests are like that!Me likey!
  25. 25. SkyVery good documentation
  26. 26. Sky documentation exampleTimeWindowEnforcementTest.html
  27. 27. It is called Yatspec!TimeWindowEnforcementTest.html
  28. 28. Tests document!Remember about it
  29. 29. TDD FOCUS ON GOALSNo. 5
  30. 30. Start with goalsWhat do I really want to do?When do I know I am done?
  31. 31. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
  32. 32. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
  33. 33. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {}}
  34. 34. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {verify(supportTeam).reportException(exception);}}
  35. 35. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {userMailer.passwordChanged(username, email);verify(supportTeam).reportException(exception);}}
  36. 36. public class UserMailerTest {@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {doThrow(exception).when(javaMail).send(anyString(), eq(email));userMailer.passwordChanged(username, email);verify(supportTeam).reportException(exception);}}
  37. 37. import static org.mockito.Matchers.anyString;import static org.mockito.Mockito.*;public class UserMailerTest {private final SupportTeam supportTeam = mock(SupportTeam.class);private final JavaMail javaMail = mock(JavaMail.class);private final RuntimeException exception = new RuntimeException();private final String username = "john";private final String email = "john.tdd@gmail.com";private final UserMailer userMailer = new UserMailer(supportTeam, javaMail);@Testpublic void notifiesSupportTeamWhenExceptionIsThrownWhenSendingMail() {doThrow(exception).when(javaMail).send(anyString(), eq(email));userMailer.passwordChanged(username, email);verify(supportTeam).reportException(exception);}}
  38. 38. Shorter paths to your goals!YAGNI
  39. 39. TESTS INCREASE COUPLINGNo 6
  40. 40. Loose coupling?Me likey!
  41. 41. Unit testsMocks? Implementation details!Stubs & State? Still coupled to units!Refactoring? Nein!Good? Bad?Remember about trade-offs!
  42. 42. Module testsLess coupling than unitsMore test infrastructureRefactoring? A bit?Good? Bad?Remember about trade-offs!
  43. 43. Acceptance testsEnd to end testsetc...As little coupling as possibleBig testing infrastructureRefactoring? No problems!
  44. 44. Modify prod codeHow many tests fail?Definition of coupling man!
  45. 45. SkyDuplication in testsUnmaintainable unit tests
  46. 46. Tests increase coupling?Keep that in mind!Remember about trade-offs!
  47. 47. PRACTICE KATANo. 7
  48. 48. “Practice makes perfect”
  49. 49. Professionals practiceTDD Kata / TDD ToyCode retreat
  50. 50. What I learned so far●TDD is a skill – learn it●TDD is a tool – know when to use it●TDD is software design - sometimes●TDD is documentation – very likely●TDD focus on goals – yep!●Tests increase coupling – seriously!●Practice Kata – No jokes here :/
  51. 51. Want moar?●Growing Object-Oriented Software Guided by Tests●Loads of other books – read them all●http://martinfowler.com/●http://test-driven-development.com
  52. 52. Feedback
  53. 53. Questions?

×