The Star Wars VersionGil ZilberfeldUnit Testing
BugsHow do we dealwith them?
xUnit Frameworks• Test Identification• Test Runner• Asserts
.NET xUnit Frameworks• NUnit• MSTest• xUnit• MbUnit
Demo
Why Unit Test?• Low TCO• Small setupoverhead• It’s not a bug ifit’s caught beforeQA• Go faster• Quick feedback• Knowing yo...
The death spiral• Tests are slow• Stop running tests• Stop writing tests• Back to square one
People write millions oflines of legacy codeevery day!
Testing legacy code• Tests are slow• Require big setup• Maybe impossible to run• Slow to debug
Isolation and Mocking• Let you test your code for differentscenarios, by faking thedependencies• As long as your code is r...
Demo: Hand-Rolled Mocks
.NET Mocking Frameworks• Open-source• Commercial
Demo: Mocking Framework
Coverage…… and otherJedi mindtricks
Test Driven Development
Demo
Benefits• Same Tools• Better Coverage• Less debugging• Better DesignThink before your code!
But…• Requires discipline• Works better for greenfieldprojects• Not for everyone
Agile Adoption
Working software• Automated builds• Automatic build• Run unit tests• Run integration tests• Unit tests and TDDOver compreh...
Guidelines• Unit testing is a teamsport• Where to start?• Scaffolding
Guidelines• Naming• Reviewing• AAA
Guidelines• Refactoring• Readability• Coverage• Organization
www.typemock.comtypemock.com/blog@typemockwww.gilzilberfeld.comgilz@typemock.com@gil_zilberfeldQuestions?
Death star explosionprobability calculator• Only Luke can shoot correctly• Explode if core temperature > 500• 1000 X-Wings...
Unit testing - The Star Wars version
Unit testing - The Star Wars version
Upcoming SlideShare
Loading in...5
×

Unit testing - The Star Wars version

450
-1

Published on

Introduction to unit testing and mocking as seen in a galaxy far away...

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
450
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unit testing - The Star Wars version

  1. 1. The Star Wars VersionGil ZilberfeldUnit Testing
  2. 2. BugsHow do we dealwith them?
  3. 3. xUnit Frameworks• Test Identification• Test Runner• Asserts
  4. 4. .NET xUnit Frameworks• NUnit• MSTest• xUnit• MbUnit
  5. 5. Demo
  6. 6. Why Unit Test?• Low TCO• Small setupoverhead• It’s not a bug ifit’s caught beforeQA• Go faster• Quick feedback• Knowing yourcode works• Confidence tochange your code• Quicker thandebugging
  7. 7. The death spiral• Tests are slow• Stop running tests• Stop writing tests• Back to square one
  8. 8. People write millions oflines of legacy codeevery day!
  9. 9. Testing legacy code• Tests are slow• Require big setup• Maybe impossible to run• Slow to debug
  10. 10. Isolation and Mocking• Let you test your code for differentscenarios, by faking thedependencies• As long as your code is ready for it
  11. 11. Demo: Hand-Rolled Mocks
  12. 12. .NET Mocking Frameworks• Open-source• Commercial
  13. 13. Demo: Mocking Framework
  14. 14. Coverage…… and otherJedi mindtricks
  15. 15. Test Driven Development
  16. 16. Demo
  17. 17. Benefits• Same Tools• Better Coverage• Less debugging• Better DesignThink before your code!
  18. 18. But…• Requires discipline• Works better for greenfieldprojects• Not for everyone
  19. 19. Agile Adoption
  20. 20. Working software• Automated builds• Automatic build• Run unit tests• Run integration tests• Unit tests and TDDOver comprehensive documentation
  21. 21. Guidelines• Unit testing is a teamsport• Where to start?• Scaffolding
  22. 22. Guidelines• Naming• Reviewing• AAA
  23. 23. Guidelines• Refactoring• Readability• Coverage• Organization
  24. 24. www.typemock.comtypemock.com/blog@typemockwww.gilzilberfeld.comgilz@typemock.com@gil_zilberfeldQuestions?
  25. 25. Death star explosionprobability calculator• Only Luke can shoot correctly• Explode if core temperature > 500• 1000 X-Wings• Probability of Luke being hit depends on theother X-Wingsp(success) = 0.3(X-Wings)• Probability of X-Wing surviving degrades intimep(survival) = 1/t2• Calculate Lukes hitting probability every 100time units
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×