Learn Test Driven Development in Java
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Learn Test Driven Development in Java

on

  • 9,554 views

This course provides everything you need to know to get started with test driven development in Java. ...

This course provides everything you need to know to get started with test driven development in Java.

NEW! Discount codes for the online course!

If you like the look of these slides and would like to take the online course on Udemy, use discount code TDDSLIDES for a massive discount - https://www.udemy.com/learn-test-driven-development-in-java/?couponCode=TDDSLIDES

This course covers test driven development from scratch, through video lectures, demonstrations of practising a test driven approach, and through exercises for you to complete, allowing you to gain valuable experience in using TDD.

For more information on the course, please see http://www.udemy.com/learn-test-driven-development-in-java/ or http://www.fluentsoftware.co.uk/Courses

Statistics

Views

Total Views
9,554
Views on SlideShare
9,554
Embed Views
0

Actions

Likes
8
Downloads
149
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Learn Test Driven Development in Java Presentation Transcript

  • 1. Test Driven Development in JavaWednesday, 14 November 12
  • 2. About me! Matthew Todd matthew.todd@fluentsoftware.co.uk @matthew_todd Working with developers, continuously improving agile practiceWednesday, 14 November 12
  • 3. What is TDD?Wednesday, 14 November 12
  • 4. Testing timeline 1994: Kent Beck creates SUnit test framework 1999: Extreme programming explained published 1989: First tests on punchcards 1995: TDD Demo 2000: JUnit.org launchedWednesday, 14 November 12
  • 5. Manifesto for Agile Software Development We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value: Individuals and interactions over processes and tool s Working software over comprehensive documentation Customer collaboration over contract negotiation Responding to change over following a plan That is, while there is value in the items on the right, we value the items on the left moreWednesday, 14 November 12
  • 6. Wednesday, 14 November 12
  • 7. Test spectrum Full system test Automated integration/acceptance Testing in concert Component test Unit test Single function testWednesday, 14 November 12
  • 8. 1. Write testWednesday, 14 November 12
  • 9. 1. Write test 2. Test fails!Wednesday, 14 November 12
  • 10. 1. Write test 2. Test fails! 3. Write codeWednesday, 14 November 12
  • 11. 1. Write test 2. Test fails! 3. Write code 4. Test passes!Wednesday, 14 November 12
  • 12. 1. Write test 2. Test fails! 3. Write code 4. Test passes! 5. RefactorWednesday, 14 November 12
  • 13. 1. Write test 2. Test fails! 3. Write code 4. Test passes! 5. RefactorWednesday, 14 November 12
  • 14. Why TDD?Wednesday, 14 November 12
  • 15. Proactive VS Reactive Seek out problems early on Test late Validate requirements Only respond to defects Validate code Focused on debuggingWednesday, 14 November 12
  • 16. Relative cost of change Cost Unit test Live system TimeWednesday, 14 November 12
  • 17. Requirements Drive out requirements issues earlyWednesday, 14 November 12
  • 18. Rapid feedback Many small changes VS One Big Change™Wednesday, 14 November 12
  • 19. Collaboration Enables developers to work togetherWednesday, 14 November 12
  • 20. Values refactoring Refactor often to lower impact and riskWednesday, 14 November 12
  • 21. Design to test Testing driving good design practiceWednesday, 14 November 12
  • 22. Tests as information Documenting decisions and assumptionsWednesday, 14 November 12
  • 23. Sounds great! So show meWednesday, 14 November 12
  • 24. So, let’s get startedWednesday, 14 November 12
  • 25. Reverse polish calculator 34+Wednesday, 14 November 12
  • 26. Calculator walkthroughWednesday, 14 November 12
  • 27. Reverse polish calculator Developed using a test driven approachWednesday, 14 November 12
  • 28. “sounds simple, but what about real applications?”Wednesday, 14 November 12
  • 29. “sounds simple, but what about real applications?”Wednesday, 14 November 12
  • 30. “sounds simple, but what about real applications?”Wednesday, 14 November 12
  • 31. SOLIDWednesday, 14 November 12
  • 32. Single responsibilityOLIDWednesday, 14 November 12
  • 33. Wednesday, 14 November 12
  • 34. Wednesday, 14 November 12
  • 35. SOpen/ClosedLIDWednesday, 14 November 12
  • 36. Wednesday, 14 November 12
  • 37. Wednesday, 14 November 12
  • 38. SOLiskov SubstitutionIDWednesday, 14 November 12
  • 39. Wednesday, 14 November 12
  • 40. SOLInterface segregationDWednesday, 14 November 12
  • 41. Wednesday, 14 November 12
  • 42. Wednesday, 14 November 12
  • 43. SOLIDependency inversionWednesday, 14 November 12
  • 44. Wednesday, 14 November 12
  • 45. Wednesday, 14 November 12
  • 46. Isolating dependencies Dependency Test target x Test double TestWednesday, 14 November 12
  • 47. Test Doubles Stubs Fakes MocksWednesday, 14 November 12
  • 48. Test Doubles Stubs Fakes MocksWednesday, 14 November 12
  • 49. Stubs Providing state-based verificationWednesday, 14 November 12
  • 50. Test Doubles Stubs Fakes MocksWednesday, 14 November 12
  • 51. Fakes Providing simplified replacementsWednesday, 14 November 12
  • 52. Test Doubles Stubs Fakes MocksWednesday, 14 November 12
  • 53. Mocks Providing behaviour based verificationWednesday, 14 November 12
  • 54. Stubs Assertions made Fakes directly in test method Mocks Assertions made by mock objectWednesday, 14 November 12
  • 55. Test double demonstrationWednesday, 14 November 12
  • 56. Mock frameworksWednesday, 14 November 12
  • 57. Wednesday, 14 November 12
  • 58. Wednesday, 14 November 12
  • 59. app ropr iate ks w here amewor r mock fr Conside Test balanceWednesday, 14 November 12
  • 60. Dealing with the legacyWednesday, 14 November 12
  • 61. Code we cannot change Dealing with the legacy Someone else’s code? No interfaces?Wednesday, 14 November 12
  • 62. So, now we can test it!Wednesday, 14 November 12
  • 63. So, now we can test it! What makes a good test?Wednesday, 14 November 12
  • 64. Test principlesWednesday, 14 November 12
  • 65. FIRSTWednesday, 14 November 12
  • 66. FastIRSTWednesday, 14 November 12
  • 67. FIndependentRSTWednesday, 14 November 12
  • 68. FIRepeatableSTWednesday, 14 November 12
  • 69. FIRSelf-validatingTWednesday, 14 November 12
  • 70. FIRSTimelyWednesday, 14 November 12
  • 71. TDD Anti-patternsWednesday, 14 November 12
  • 72. Anti-pattern: the singletonWednesday, 14 November 12
  • 73. Anti-pattern: the singleton Who uses this singleton? Who owns this singleton? What behaviours does it provide?Wednesday, 14 November 12
  • 74. Anti-pattern: create the world @Before public void initialiseTests() { loadBalancer = createMockLoadBalancingService(); server1 = createMockServer(); server2 = createMockServer(); loadBalancer.addServer(server1); loadBalancer.addServer(server2); dbEngine = new DBEngine(); dbEngine.addTable("users"); dbEngine.addTable("profiles"); dbEngine.addTable("posts"); userProfileService = new Mock<UserProfileServer>(); adminUser = new User("admin",true); user1 = new User("alice",false); user2 = new User("bob",false); userProfileService.register(user1); userProfileService.register(user2); user1.connectWith(user2); ... Wednesday, 14 November 12
  • 75. Anti-pattern: create the world Test burden increases over time Test complexity increases Often a sign of application complexityWednesday, 14 November 12
  • 76. Anti-pattern: completely mocked @Test public void testingNothing() { MockServiceFactory factory = new MockServiceFactory(); Mock<UserService> userService = new Mock<UserService>(); factory.add(userService); User user = new User("bob"); userService.add(user); assertEquals("bob",userService.getUsers()[0].name()); }Wednesday, 14 November 12
  • 77. Test boundaries Class(es) under test Out of test scopeWednesday, 14 November 12
  • 78. Anti-pattern: exceptional test @Test public void testUserCreation() { userService.createUser("bob"); }Wednesday, 14 November 12
  • 79. Anti-pattern: exceptional test @Test public void testUserCreation() { userService.createUser("bob"); } Good coverage, but poor validationWednesday, 14 November 12
  • 80. Anti-pattern: usually passes com.example.UncertainTest com.example.UncertainTest com.example.UncertainTest com.example.UncertainTest com.example.UncertainTestWednesday, 14 November 12
  • 81. Anti-pattern: usually passes Control threading and access to resources We need to be able to trust our testsWednesday, 14 November 12
  • 82. Anti-pattern: one big test @Test public void testEverything() { userService.createUser("alice"); assertEquals(1,userService.getUserCount()); userService.createUser("alice"); assertEquals(1,userService.getUserCount()); userService.createUser("bob"); assertEquals(2,userService.getUserCount()); userService.dropUser("alice"); assertEquals(1,userService.getUserCount()); User bob = userService.getUser("bob"); assertNotNull(bob); ...Wednesday, 14 November 12
  • 83. Anti-pattern: one big test testUserCreation testEverything testCreatingDuplicateUser testDroppingUserWednesday, 14 November 12
  • 84. Anti-pattern: the slow testWednesday, 14 November 12
  • 85. Anti-pattern: the slow test Should be quick to pass Should be quick to fail Run frequentlyWednesday, 14 November 12
  • 86. Anti-pattern: second-class test @Test public void whoKnowsWhatThisTests() { createTestObjects(); testUser.setName("alice"); setupTestDependencies(); User user2 = new User("user2"); setupUser(user2); testManager.add(testUser); ... test(user2); }Wednesday, 14 November 12
  • 87. Applying TDDWednesday, 14 November 12
  • 88. When not to use TDD!Wednesday, 14 November 12
  • 89. Continuous delivery Integration testing BDD TDD Design Manual testing User storiesWednesday, 14 November 12
  • 90. Practice practice practiceWednesday, 14 November 12
  • 91. TDD KataWednesday, 14 November 12
  • 92. TDD Kata roman numerals 1 - convert text from normal numerals -> Roman numerals 2 - convert in the other direction tooWednesday, 14 November 12
  • 93. TDD Kata FizzBuzz printing numbers from 1 to 100 ..but multiples of 3 should print Fizz multiples of 5 should print Buzz multiples of 3 and 5 print FizzBuzz 1 2 Fizz 4 Buzz Fizz 7 ...Wednesday, 14 November 12
  • 94. TDD Kata roman calculator calculator only accepting roman numerals as input and output I + III = IVWednesday, 14 November 12
  • 95. TDD Kata tennis implement simple tennis game http://en.wikipedia.org/wiki/Tennis#ScoringWednesday, 14 November 12
  • 96. Thank you!Wednesday, 14 November 12