improve your development skills with test driven development

Download Improve your development skills with Test Driven Development

If you can't read please download the document

Upload: john-stevenson

Post on 19-May-2015

1.507 views

Category:

Technology


8 download

DESCRIPTION

A talk at the Graduate Developer community on test driven development. Helping students and graduates understand the point of a test first approach, demonstrate the tools and show how easy it is to start.

TRANSCRIPT

  • 1. Open Source Jumpstart: Improve your development SkillsLeanAgileMachineCreative Commons License

2. Graduate Developer Community Meet with Companies www.grad-dc.co.uk looking for internsTalk to experienced blog.grad-dc.co.uk developers & testers Ask questions about what you learnt tonightLeanAgileMachineCreative Commons License Socialse 3. Goals of OS Jumpstart What tools are out there What should you know Show how Unit Testing tools support the agile processLeanAgileMachineCreative Commons License 4. Goals of this session Understand the value of TDD Give you confidence to start learning TDD Tools to use to start learning I cant teach you TDD in one evening, sorry! TDD is as big as learning something like OO A bit of practical experience Pair up and try it out Deliberate practiceLeanAgileMachineCreative Commons License 5. Have you tried Test First ?Raise your hand if you already tried TDD andtest first development ?LeanAgileMachineCreative Commons License 6. Where does TDD fitLeanAgileMachineCreative Commons License 7. So what is TDD ??LeanAgileMachineCreative Commons License 8. A design activity What is the challenge (the requirements) What are the concepts we are dealing with What is valuable What behaviour do I need to understand How do I know I have met the challenge How do I know I can changeLeanAgileMachineCreative Commons License 9. Understanding the problem Behaviour Concepts Stakeholders Values PrioritiesLeanAgileMachineCreative Commons License 10. The TDD cycle Write a failing test so we know it tests something Write code to make the test pass Refactor code to be as simple as possibleLeanAgileMachineCreative Commons License 11. Continuous / Fast Feedback Are we there yet ? Your own mini-me tester as a guide Only scratching the surface of testing thoughLeanAgileMachineCreative Commons License 12. What tools are involved Jenkins CILeanAgileMachineCreative Commons License 13. Anatomy of a testLeanAgileMachineCreative Commons License 14. Make the test compileLeanAgileMachineCreative Commons License 15. Write a classLeanAgileMachineCreative Commons License 16. Common assertions assertEquals() Two objects of the same type are equal in value assertNotNull() The object does not have a null value assertTrue() The statement results is a true evaluation assertSame() Two objects are the samehttp://junit.sourceforge.net/javadoc/org/junit/Assert.htmlLeanAgileMachineCreative Commons License 17. JUnit Annotations @Test @Ignore Defines a method as a test Dont run this @Test(expected=exception.class) test use Fails if a specific exception is no sparinglythrown @Test(timeout = 1000) Fails if test takes too long(milliseconds) http://junit.sourceforge.net/javadoc/org/junit/Test.htmlLeanAgileMachineCreative Commons License 18. Test smells Testing code rather than behaviour Multiple assertions Too specific per method Changing tests every Bloated tests time you refactor Harder to refactor Addressing to manyscenarios Harder to understandand maintainLeanAgileMachineCreative Commons License 19. A bad test example@Testpublic void equalsCheck() {System.out.println("* VectorsJUnit4Test: equalsCheck()");assertTrue(Vectors.equal(new int[] {}, new int[] {}));assertTrue(Vectors.equal(new int[] {0}, new int[] {0}));assertTrue(Vectors.equal(new int[] {0, 0}, new int[] {0, 0}));assertTrue(Vectors.equal(new int[] {0, 0, 0}, new int[] {0, 0, 0}));assertTrue(Vectors.equal(new int[] {5, 6, 7}, new int[] {5, 6, 7}));assertFalse(Vectors.equal(new int[] {}, new int[] {0}));assertFalse(Vectors.equal(new int[] {0}, new int[] {0, 0}));assertFalse(Vectors.equal(new int[] {0, 0}, new int[] {0, 0, 0}));assertFalse(Vectors.equal(new int[] {0, 0, 0}, new int[] {0, 0}));assertFalse(Vectors.equal(new int[] {0, 0}, new int[] {0}));assertFalse(Vectors.equal(new int[] {0}, new int[] {}));assertFalse(Vectors.equal(new int[] {0, 0, 0}, new int[] {0, 0, 1}));assertFalse(Vectors.equal(new int[] {0, 0, 0}, new int[] {0, 1, 0}));assertFalse(Vectors.equal(new int[] {0, 0, 0}, new int[] {1, 0, 0}));assertFalse(Vectors.equal(new int[] {0, 0, 1}, new int[] {0, 0, 3}));}LeanAgileMachineCreative Commons License 20. Quick Netbeans / JUnit demo - create a new project - create your first test - run the JUnit testrunner - write code to fix the test - run the JUnit testrunner - write another test...LeanAgileMachineCreative Commons License 21. Your turn - pair up- fire up netbeans - start a new Java Application project- or check out my project - read the basic requirements - write a test...LeanAgileMachineCreative Commons License 22. Deliberate practice Goal is to practice TDD Become comfortable with the tools Gain experience in writing tests Improve confidence in TDD The resulting code algorithms are not important I dont care how fast your calculator calculates Youre here to learn not to produceLeanAgileMachineCreative Commons License 23. Hamcrest asserts Hamcrest is a pattern matching library Can help make you test logic more human readableAssertThat() - instead of JUnit asserts assertThat(myCalc.addTwoNumbers(6, 7), is(6 + 7)); assertThat(myCalc.addTwoNumbers(6, 7), is(not(6 + 9)));LeanAgileMachineCreative Commons License 24. Build Tools Build Automation Compile, test and deploy code from your repository Ant.apache.org ant.apache.org/ivy Maven.apache.org Comparison of tools: http://ant.apache.org/ivy/ m2comparison.htmlLeanAgileMachineCreative Commons License 25. Integrated Development Environments Manage large / multiple projects Debugger Autocompletion (code api completion) Refactoring.org Build managementAnt / Maven compile, test, deploy.org Integration Application servers, databases, unit testing,Scm, bug tracker, CI server,IntelliJ IDEAjetbrains.orgLeanAgileMachineCreative Commons License 26. Keep the build bunny happy Tests help preventbuild errors You can run yourtests before youanger the buildbunnyLeanAgileMachineCreative Commons License 27. Collaborative workspace Can show progress of your tests Confluence Show you which tests are failing Gives everyone a sence of progressLeanAgileMachineCreative Commons License 28. Summary TDD is a design activity Gives you time to use your brain before coding This session was just enough to get you going Try doing some coding kata Try a coding dojo or code retreat LJC / GDC organising these soon ! Monthly Python, Clojure, Scala dojos aready runningLeanAgileMachineCreative Commons License 29. We want your feedbackLeanAgileMachineCreative Commons License 30. Graduate Developer Communitywww.grad-dc.co.uk Meet with Companiesblog.grad-dc.co.uk looking for interns Talk to experienced developers & testers Ask questions about what you learnt tonight SocialseLeanAgileMachineCreative Commons License 31. TDD / BDD Workshop Half day workshop at SkillsMatter 17 th May Part of London Tester Gathering days http://bit.ly/LTGDays2011LeanAgileMachineCreative Commons License 32. Thank youUseful linksJohn@jr0cket.comJohn.Jr0cket.co.ukToolingup.Jr0cket.co.ukUbuntu.Jr0cket.co.ukGrowing OO Software,www.grad-dc.co.uk guided by testsblog.grad-dc.co.uk LeanAgileMachine Creative Commons License