Download - Introduction to TDD
![Page 1: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/1.jpg)
Women Who Can Code
Code Dojo : Basics of Test Driven Development
11th March 2015
Laavanya Kathiresen @Nintex
![Page 2: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/2.jpg)
What is Code Dojo ?
Programmers gather to train & learn, working together on a problem (while having fun!)
NOT a competition
2 types of ways of running it : ● Prepared Kata (with Baby Steps)● Randori Kata
![Page 3: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/3.jpg)
Test Driven Development (TDD)
Kent Beck - Father of TDD
Test First Programming Concept
Repetition of short development cycle
Red-Green-Refactoring
Having unit tests doesn’t mean you’ve done TDD
![Page 4: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/4.jpg)
Why do TDD ?
Better code quality (less coupling)
Encourages simple design and concepts
Reduces the risk of over-engineering
Ability to refactor without fear of ‘breaking’ anything
Improved maintainability and changeability of the codebase
& MANY MORE!!!!
![Page 5: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/5.jpg)
![Page 6: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/6.jpg)
Prepared Kata : String Calculator
![Page 7: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/7.jpg)
Create a simple String calculator with a method int Add(string numbers)
1. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”
2. Start with the simplest test case of an empty string and move to 1 and two numbers3. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about4. Remember to refactor after each passing test
![Page 8: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/8.jpg)
Allow the Add method to handle an unknown amount of numbers
![Page 9: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/9.jpg)
Allow the Add method to handle new lines between numbers (instead of commas).
1. the following input is ok: “1\n2,3” (will equal 6)2. the following input is NOT ok: “1,\n” (not need to prove it - just clarifying)
![Page 10: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/10.jpg)
Support different delimiters1. to change a delimiter, the beginning of the string will contain a separate
line that looks like this: “//[delimiter]\n[numbers…]” for example “//;\n1;2” should return three where the default delimiter is ‘;’ .
2. the first line is optional. all existing scenarios should still be supported
![Page 11: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/11.jpg)
Calling Add with a negative number will throw an exception “negatives not allowed” - and the negative that was passed.
If there are multiple negatives, show all of them in the exception message
![Page 12: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/12.jpg)
Numbers bigger than 1000 should be ignored, so
adding 2 + 1001 = 2
![Page 13: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/13.jpg)
Delimiters can be of any length with the following format: “//[delimiter]\n” for example: “//[***]\n1***2***3” should return 6
![Page 14: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/14.jpg)
Challenges in TDD…..
Initially it might take longer than expected to do TDD
… hence might not get the support and encouragement from management
Developers tend to ‘reverse-engineer’ unit test hence losing the benefit of TDD
TDD on legacy code can be challenging
![Page 15: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/15.jpg)
Puts “That’s it for now, thank you for
participating\n”
Puts “Please do give you feedback on what
you’ll to know more on”
![Page 16: Introduction to TDD](https://reader031.vdocuments.mx/reader031/viewer/2022031921/55d37bd4bb61ebf5188b456f/html5/thumbnails/16.jpg)
Allow multiple delimiters like this: “//[delim1][delim2]\n” Example “//[*][%]\n1*2%3” should return 6.