Upload
bhochhi
View
628
Download
2
Embed Size (px)
Citation preview
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Test Driven Developmenta coding practice
Rupesh BhochhibhoyaSoftware Engineer,Telogical Systems
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
• Those who are unaware of TDD or haven’t done TDD
• Those who know what TDD means but haven’t got its flow
Intended Audiences
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
What is TDD ?
One of the best software development practice/habit/technique used in Agile methodology that relies on the repetitive short development cycle.
Each short development cycle is formed following 3 basic rules
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Requirements
Design
Testing
Implementation
Deployment & Maintenance
Requirements
Design
Testing
Implementation
Deployment &
Maintenance
waterfall model
TDD model
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Rule #1
Write a test first that is just enough to fail before any production code that you are going to write. There should be only one reason for test to fail. So, each test is to specific one logical unit. The test case defines a desired functionality you want to see. This is also called Test-First approach.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Rule #2
Write a production code that is just enough to pass the test. This make sure production code is doing exactly what test wanted. No any abnormal behavior.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Rule #3
Refactor the production code to remove duplication without changing the external behavior as desired by test units. We also refactor test code to make it more readable, remove duplication and add more logical unit test.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
1. Run the complete test suite, ensure all pass.2. Add a new test code that is just enough to fail.3. Run the test and ensure it fails4. Then add production code just enough to make the
test pass.5. Fourth step is to run the test again. 6. If it fails, need to work again in production code
and retest.7. Once test passes, the next step is to refactor any
duplication out of your design as needed.8. SO: TDD = TFD + Refactoring…
Add a test
Run the test
Add/Modify Production
code
Run the tests
Pass
Fail
Fai
l
Pas
s
Refactor Production code Run test suiteFail
Pas
s
How TDD ?
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Good Test Code in TDD…
1. Describes the behavior of the code you are going to write.2. Run fast.3. Run in isolation.4. Should not be data driven.5. Should not communicates across the network.6. Should not interacts with file system
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
TDD Demo1. You write your own test2. You have a testing framework(Junit).3. Development environment must provide rapid response to small
changes(CI)4. Eclipse IDE,5. Etc.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Why TDD
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
TDD reduces programmer’s bugs
When you already have Tests that documents how your code works and also verifies every logical units, programmer’s bugs are significantly reduced resulting more time coding, less time debugging.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
TDD builds developer’s Confidence
you can confidently refactor your production code without worrying about breaking it, if you already have test code written, it acts as safety net.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
TDD provides working specification
Tests on TDD describes the behavior of the code you are going to write. So, tests provides better picture of specification then documentation written on a paper because test runs.
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
• TDD enables integration more often allowing larger team to work on same code base
• TDD guarantees testability
• TDD reduces product delivery time
• TDD produces highly cohesive and loosely coupled Systems
• TDD simplifies the design
Solutions that make sense of telecom & cable pricing information™Solutions that make sense of telecom & cable pricing information™
Conclusion
Q & A