Production code without tests         How things may change?! Akim Khalilov
Any problems in the code?   • The code works – everybody is happy    • And here you are asked to implement the new       ...
Change the things   • Cover all your cnages by tests   • Who is asked, «Can we write tests to the        existing app?»   ...
Code is not ready for unit tests   • Structure may be violated   • Long methods / classes         – God object   • Static ...
#1: Objects instantiated explicitly                var service = new WebService();                              Solution: ...
#2: Static call                WebService.CalculateBy(index, range);                               Solution:   • Do not us...
#3: New feature in the legacy code                         Solution:   • Do not touch the legacy code   • Call new code fr...
#4: New feature without pain                     The problem:   • New logic is breaking call signature                    ...
I need make changes, but I don’t know        what kind of tests should I write   • Characterization test:       – Document...
What is in the result?       •   HDD - Hope Driven Development?       •   FDD - Faith Driven Development?       •   JDD - ...
© by @alexbeletsky                                I need more!         michaelfeathers.typepad.com         www.amazon.com/...
Thank you!Akim Khalilov   Production code without tests   12
Upcoming SlideShare
Loading in …5
×

Production code without tests

939 views

Published on

Slides with notes for the talk "Production code without tests" based on the Michael Feathers "Working Effectively with Legacy Code" book.

http://sstude.com/blog/2013/02/05/my-talk-production-code-without-tests

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
939
On SlideShare
0
From Embeds
0
Number of Embeds
76
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Production code without tests

  1. 1. Production code without tests How things may change?! Akim Khalilov
  2. 2. Any problems in the code? • The code works – everybody is happy  • And here you are asked to implement the new feature • Problem – DO NOT BREAK THE CODE – During development – During bug fixing – During refactoringAkim Khalilov Production code without tests 2
  3. 3. Change the things • Cover all your cnages by tests • Who is asked, «Can we write tests to the existing app?» • You remember the answer Akim Khalilov Production code without tests 3
  4. 4. Code is not ready for unit tests • Structure may be violated • Long methods / classes – God object • Static calls • Dependency from the external resourcesAkim Khalilov Production code without tests 4
  5. 5. #1: Objects instantiated explicitly var service = new WebService(); Solution: • Constructors (injection) • Method calls (injection) • Interfaces (for loose coupling) • Do not have interfaces - wrappers • DEMO #1Akim Khalilov Production code without tests 5
  6. 6. #2: Static call WebService.CalculateBy(index, range); Solution: • Do not use static  • Exclude static call in the test • Extract And Override Call • Subclass And Override • DEMO #2 – The Seam ModelAkim Khalilov Production code without tests 6
  7. 7. #3: New feature in the legacy code Solution: • Do not touch the legacy code • Call new code from the legacy one • Sprout Method • DEMO #3Akim Khalilov Production code without tests 7
  8. 8. #4: New feature without pain The problem: • New logic is breaking call signature Solution • Default implementation • Wrap Method • DEMO #4Akim Khalilov Production code without tests 8
  9. 9. I need make changes, but I don’t know what kind of tests should I write • Characterization test: – Documents current code behavior – Exclude any «I think, «Maybe the code works this way..» • Write the red test. Error will show you what returns from the method • If the result is illogic – take to the look (Bug?) • Every new test: – Documents the function: What does that method do? – RTFM Test – Helps make changes without fearAkim Khalilov Production code without tests 9
  10. 10. What is in the result? • HDD - Hope Driven Development? • FDD - Faith Driven Development? • JDD - Jesus Driven development? • PDD - Pray Driven Development? • Investment to the code • Tests will save your back in the future • Team knows code better • The system is under refactoringAkim Khalilov Production code without tests 10
  11. 11. © by @alexbeletsky I need more! michaelfeathers.typepad.com www.amazon.com/Working- Effectively-Legacy-Michael- Feathers/dp/0131177052 Michael Feathers @mfeathersAkim Khalilov Production code without tests 11
  12. 12. Thank you!Akim Khalilov Production code without tests 12

×