Your SlideShare is downloading. ×
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Generatingcharacterizationtestsforlegacycode
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Generatingcharacterizationtestsforlegacycode

79

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
79
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Generating Characterization Testsfor Legacy CodeSlides via Jonas Follesø (@follesoe)
  • 2. Huge methods (~3000+ lines)
  • 3. Dave&Karinhttp://www.flickr.com/photos/dnk_uk/3525103502/~50 slowintegration tests
  • 4. How thedevelopmentteam felt...
  • 5. What theyneeded
  • 6. What youshould read
  • 7. FraserSpeirshttp://www.flickr.com/photos/fraserspeirs/3395595360/Legacy code is code without tests.Code without tests is bad code.-Michael C. Feathers
  • 8. A characterization test is test thatcharacterizes the actual behavior of a piece ofcode.It acts as a change detector, protecting legacycode from unintended changes
  • 9. public double Calc(double inv, double rt, int y){double ret = 0;for (int i = 1; i <= y; i++){ret = inv * Math.Pow(1.0 + rt / 100.0, i);}return ret;}
  • 10. [TestMethod]public void Calc_characterization(){var calc = new CalcUtil();double result = calc.Calc(10000, 10, 10);Assert.AreEqual(42.0, result);}
  • 11. Assert.AreEqual failed.Expected:<42>. Actual:<25937.424601>.
  • 12. [TestMethod]public void Calc_characterization(){var calc = new CalcUtil();double result = calc.Calc(10000, 10, 10);Assert.AreEqual(25937.424601, result);}
  • 13. Test run completed. Results 1/1 passed.
  • 14. public double CalculateCompoundInterest(double investment, double interest, int years){double projectedValue = 0.0;for (int year = 1; year <= years; year++){projectedValue = investment *Math.Pow(1.0 + interest / 100.0, year);}return projectedValue;}
  • 15. FraserSpeirshttp://www.flickr.com/photos/fraserspeirs/3395599536/…A pinch point is a natural encapsulationboundary. When you find a pinch point, you’vefound a narrow funnel for all the effects of a largepiece of code…-Michael C. Feathers
  • 16. fast characterization tests
  • 17. The Golden Master ApproachBefore making any change to production code, do the following:1) Create X number of random inputs, always using the same random seed, soyou can always generate the same set over and over again. You will probablywant LOTS of inputs for good coverage.2) Bombard the class or system under test with these random inputs.3) Capture the outputs for each individual random input.
  • 18. A pictures worth a 1000 tests.Unit testing asserts can be difficult to use.Approval tests simplify this by taking asnapshot of the results, and confirming thatthey have not changed.

×