Real life unit testing tools and practices

532 views
445 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
532
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Real life unit testing tools and practices

  1. 1. Real Life Unit TestingTools and PracticesGil Zilberfeld11-Jan-2012
  2. 2. Agenda• The problems with legacy code• How isolation helps• Hand rolled mocks• Mocking frameworks• Writing effective unit tests
  3. 3. People write millions of lines of legacy code every day!
  4. 4. So what is legacy code?• Code that doesn’t have tests • Michael Feathers• Code you’ve written before last Tuesday • Gil Zilberfeld
  5. 5. Testing legacy code• Tests are slow• Require big setup• Maybe impossible to run• Slow to debug
  6. 6. The death spiral• Tests are slow• Stop running tests• Stop writing tests• Back to square one
  7. 7. Code is Tangled• Dependencies • Injected through the constructor • Passed as parameters • Available through static methods • Created inside the tested code • And through other clever ways…
  8. 8. You want tests…• But for that, you need to change your code• But without tests, that’s crazy!
  9. 9. Isolation and Mocking• Let you test your code for different scenarios, by faking the dependencies• As long as your code is ready for it
  10. 10. Demo: Hand-Rolled Mocks
  11. 11. Mocking Frameworks• Change behavior of code without changing it• Verification of calls
  12. 12. Demo: Mocking Framework
  13. 13. .NET Mocking Frameworks• Open-source• Commercial
  14. 14. Good unit tests are…• Quick • Can run a full suite in seconds• Readable • Can be used as code documentation• Focused • Can pinpoint bugs quickly when they break• Robust • Do not break when your code changes
  15. 15. Guidelines• Separate quick from slow• Use descriptive names• Test slices of functionality• Use isolation wisely
  16. 16. Summary• Write quick, readable tests• Use a mocking framework from the beginning• Start today!
  17. 17. Questions?www.typemock.com www.gilzilberfeld.comtypemock.com/blog gilz@typemock.com@typemock @gil_zilberfeld

×