terry.yinzhe@gmail.com
Agenda Background Motivation Principles Practices What is fun?
BACKGROUND
Large scale softwareTelecommunication device10+ years old1,000 people10,000,000 lines of code in one buildC, SDLSome very ...
Where do we usually call it legacy code?
MOTIVATION
Its NOT about finding bugs!The purpose of unit testing is to facilitatechanges
You still have the choice and reasons          not to do it.
PRINCIPLES
BASIC UNIT TESTINGPRINCIPLES
PRINCIPLE 1KEEP IT VERY SIMPLE, VERY STUPID   It is not that the more test cases the better       Actually, it is on the c...
PRINCIPLE 2DONT TRY TO ADD GOOD UT TO BAD CODE
PRINCIPLE 3DONT MAKE ASSUMPTION             Exploding stub      error_t release_message_received(         msg_header_t * m...
PRINCIPLE 4STOP MAKING LEGACY CODE  Test drive new code  Add tests to legacy code before modification  Test drive changes ...
PRINCIPLE 5EDUCATE THE PEOPLE  Do NOT let just one or two people do it.  NEVER let interns do it!
WHERE TO START?
Setup the framework To setup the framework for legacy code can be very challenging. Choose the test framework We use CppUT...
Domain Modeling Reverse engineering to clarify the concepts used in the legacy code   And their relationships Use the term...
Identify the hot area Start from the hot area will be most cost-efficient Example   Through SVN log   Along with the new w...
Bottom-up? Have some integration test first Then,   One practical approach is bottom-up   Get a higher level of abstraction
Learn the function by testing it  Characterization Test  Start from the 1st (failing) exit  Write your plan on a piece of ...
Make the legacy code testable Use safe refactoring techniques to change the legacy code without unit testing.   Extract fu...
Break Dependency
WHAT IS FUN
Bring chaos to orderLearn the featureDelete tons of codeFeel the peace of your heart
REFERENCES
Acknowledgement
Terry yin   adding unit-test_to_legacy_code
Upcoming SlideShare
Loading in …5
×

Terry yin adding unit-test_to_legacy_code

750 views
715 views

Published on

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
750
On SlideShare
0
From Embeds
0
Number of Embeds
54
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Terry yin adding unit-test_to_legacy_code

  1. 1. terry.yinzhe@gmail.com
  2. 2. Agenda Background Motivation Principles Practices What is fun?
  3. 3. BACKGROUND
  4. 4. Large scale softwareTelecommunication device10+ years old1,000 people10,000,000 lines of code in one buildC, SDLSome very complicatedThousands LOCs functionsCyclomatic complexity > 50.Duplicate rate > 100%!
  5. 5. Where do we usually call it legacy code?
  6. 6. MOTIVATION
  7. 7. Its NOT about finding bugs!The purpose of unit testing is to facilitatechanges
  8. 8. You still have the choice and reasons not to do it.
  9. 9. PRINCIPLES
  10. 10. BASIC UNIT TESTINGPRINCIPLES
  11. 11. PRINCIPLE 1KEEP IT VERY SIMPLE, VERY STUPID It is not that the more test cases the better Actually, it is on the contrary, the less the better. The purpose of UT is to facilitate change It can only facilitate change if it survive Therefore, it needs maintainability So, it needs to be simple "The only way for humans to deal with complexity is to avoid it ..."
  12. 12. PRINCIPLE 2DONT TRY TO ADD GOOD UT TO BAD CODE
  13. 13. PRINCIPLE 3DONT MAKE ASSUMPTION Exploding stub error_t release_message_received( msg_header_t * msg ) { DO_FAIL_TEXT("Im called!!"); return SUCCESS_EC; }
  14. 14. PRINCIPLE 4STOP MAKING LEGACY CODE Test drive new code Add tests to legacy code before modification Test drive changes to legacy code Boy Scout Principle
  15. 15. PRINCIPLE 5EDUCATE THE PEOPLE Do NOT let just one or two people do it. NEVER let interns do it!
  16. 16. WHERE TO START?
  17. 17. Setup the framework To setup the framework for legacy code can be very challenging. Choose the test framework We use CppUTest Ask for performance
  18. 18. Domain Modeling Reverse engineering to clarify the concepts used in the legacy code And their relationships Use the terms consistently in your unit testing. It will also give your refactoring a road-map.
  19. 19. Identify the hot area Start from the hot area will be most cost-efficient Example Through SVN log Along with the new work and bug fixing
  20. 20. Bottom-up? Have some integration test first Then, One practical approach is bottom-up Get a higher level of abstraction
  21. 21. Learn the function by testing it Characterization Test Start from the 1st (failing) exit Write your plan on a piece of paper
  22. 22. Make the legacy code testable Use safe refactoring techniques to change the legacy code without unit testing. Extract function If you are using C ‘Data injection’ to break the dependency on globals.
  23. 23. Break Dependency
  24. 24. WHAT IS FUN
  25. 25. Bring chaos to orderLearn the featureDelete tons of codeFeel the peace of your heart
  26. 26. REFERENCES
  27. 27. Acknowledgement

×