• Golden Rules of TDD • A word on Refactoring • Why the Business doesn’t like TDD. • Why I like TDD • Listening to the tests • Tips to help you make code more testable
You write a test, write some code and get it working very quickly, every minute or two. • TDD is NOT JUST about testing. It gives you feedback on implementation quality and design quality. • Because you write the tests before the code, TDD makes testing a design activity.
You should get a compilation error. 2. Run the test to ensure it fails in the way you expect it to. 3. Write meaningful tests that are self explanatory.
unless you have a failing test. 2. You are not allowed to write any production code UNLESS it is to make a failing unit test pass. 3. You are NOT allowed to write any more production code than is sufficient to pass the one failing unit test.
by: • Removing duplication • Making the code simpler • Making the code easier to read • Eliminate redundancy • Can be as simple as renaming a method • Should be done constantly, i.e every 2 or 3 minutes. Test code is INCLUDED and is as important - this is my documentation
is slow! At first there will be a slowing of delivery of new functionality, as the team gets used to using the TDD practice. But this is true of anything new, e.g) riding a bike, learning Spanish! • They think it will take longer because we need to write more code. But actually as we progress we can deliver new features with less or no bugs much more quickly. In my opinion I don’t think the business needs to know!
you are going to do. Gives you focus! 2. Lets you know when you've done enough. 3. Detects errors while the context is fresh in your mind. 4. When done properly, leaves a description of the system behind you. DOCUMENTATION! 5. Leaves a regression test suite behind you. 6. It is simple! I like simple things!
lets you ship features quicker. 2. I know it works when I’ve finished 3. If someone changes it they will be notified if they have broken something 4. Quicker to fix bugs if you have any. What’s not to like?? :)
Wreck” (train of getters) code like this.. client.GetMortgage().PaymentCollection(). GetNextPayment().ApplyPayment(300.00) • Its not pluggable • Objects are too tightly coupled • No one “normal” can understand it!
follow the “Tell don’t ask” principle.. client.ApplyMortgagePayment(300.00) Tell, Don't Ask helps make code easier to modify: • Localises information • Shields parts from change elsewhere • Forces you to name more concepts This makes writing tests easier!
designed. • Is tightly coupled to other parts of the system • Has hidden dependencies • Misuses information hiding (hides the wrong information) • Does too many things • Has unfocused responsibilities • Communicates by complicated protocols
valuable, rapid feedback about design issues. 2. If it is difficult to write a test, you know something is wrong. 3. It is tempting to stop testing when it gets difficult. ◦ DON’T ◦ Investigate why the code is hard to test ◦ REFACTOR
problems. • You cannot derive a complete architecture with TDD. • TDD can inform some of your architectural decisions, but you cannot begin a project without an architectural vision. • So some up front architecture is necessary.
states "when practicing TDD, you must not step back and look at the bigger picture. • You are allowed to think about the design before. • You are allowed to think about the “big picture”
working in pairs. To get into the habit of writing the simplest code with practiced “Adversarial Pairing” One developer writes the test and passes the keyboard, the other makes the test pass in the simplest way. It’s good Fun!
into the habit of writing a failing unit test for every piece of code you write for example: MOBILEWEB-787 - My info, Product: Incorrect alphabetic order of countries in drop down menus. Start with a failing testing and follow your checklist!