1. Test-driven development with Java Edouard SWIAC Java Lab SF - firstname.lastname@example.org
2. Summary• Principles• Mocks and stubs• TDD example
3. repeittion of very What is TDD ?short dev cycle of 3stepstest come from storyrefactorchanging sourcewithout modifyingexternal functional Software development process in 3 stepsbehavior
4. because you have to design thecomponent before you code, TDD in shortand note design the componentwhile you code • Encourages simple design (Ken Beck) • Relies on automated unit testing • Builds a harness against software regression
5. although required,dependencies and Testing and collaboratorscollaborators needs to bereplace by somethin • Testing a unit of code is not testing its collaborators • Collaborators have to be reproduced and controlled to produce expected results so tests can run => enter mocks !
6. Stubs and mocks stub on existing code or yet to be code mock help to test behavior• A stub (or method stub) returns programmed results when called• A mock (or mock object) mimics a real object. It has the same interface as the real objects it mimics.• Mocks methods can be stubbed