Your SlideShare is downloading. ×
0
Automated Unit Testing  for Mere Mortals Jess Chadwick Architect / RIA Specialist Dow Jones, Inc blog.jesschadwick.com @jc...
We thank the following companies for their gracious sponsorship Platinum Sponsor Gold Sponsors Silver Sponsors
 
 
 
What is an “automated unit test”? What is a “unit”?
Automated Tests… <ul><li>Ensure components work as designed </li></ul><ul><li>Guard against regressions </li></ul><ul><li>...
Automated  Unit   Tests are… <ul><li>Fast </li></ul><ul><li>Deterministic </li></ul><ul><li>Independent </li></ul><ul><li>...
Unit tests… <ul><li>Do not cross application / process boundaries </li></ul>
INTEGRATION TESTS
Integration Tests… <ul><li>Ensure two or more system components work together </li></ul><ul><li>Cross application / proces...
DEMO:   A SAMPLE UNIT TEST
TEST DOUBLES <ul><li>Mocks and Stubs and Fakes… oh my! </li></ul>
Test Doubles <ul><li>Stand in for production components </li></ul><ul><li>Provide deterministic behavior </li></ul><ul><li...
Source:  Unit Testing: Exploring The Continuum Of Test Doubles   MSDN Magazine, September, 2007
CODE COVERAGE
Code Coverage is… <ul><li>The degree to which source code is tested </li></ul>
RETROFITTING EXISTING CODE WITH TESTS
 
UNIT TEST ANTI-PATTERNS
!!  Warning !!
Unit Test Anti-Patterns and Smells <ul><li>Test multiple components at once </li></ul><ul><li>Slow </li></ul><ul><ul><li>C...
Unit Test Anti-Patterns and Smells <ul><li>Multiple assertions </li></ul><ul><li>No assertions </li></ul><ul><li>Unclear /...
TEST-DRIVEN DEVELOPMENT
A different way of thinking <ul><li>Part of Agile / Extreme Programming beliefs </li></ul><ul><li>Tests drive system desig...
Test-First Development <ul><li>No code can be written unless driven by a failing test </li></ul><ul><li>Red  –  Green  -  ...
TDD Pair Programming Game <ul><li>Player 1:  Write failing test </li></ul><ul><li>Player 2:  Make failing test pass </li><...
IDEAS TO TAKE HOME
 
 
Upcoming SlideShare
Loading in...5
×

Automated Unit Testing for Mere Mortals

563

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
563
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Roughly in order of implementation, from least (no) to full Good article in this month’s MSDN Magazine discussing the difference
  • Transcript of "Automated Unit Testing for Mere Mortals"

    1. 1. Automated Unit Testing for Mere Mortals Jess Chadwick Architect / RIA Specialist Dow Jones, Inc blog.jesschadwick.com @jchadwick
    2. 2. We thank the following companies for their gracious sponsorship Platinum Sponsor Gold Sponsors Silver Sponsors
    3. 6. What is an “automated unit test”? What is a “unit”?
    4. 7. Automated Tests… <ul><li>Ensure components work as designed </li></ul><ul><li>Guard against regressions </li></ul><ul><li>Exercise the system </li></ul><ul><li>Expose how the system works </li></ul><ul><ul><li>Documentation </li></ul></ul>
    5. 8. Automated Unit Tests are… <ul><li>Fast </li></ul><ul><li>Deterministic </li></ul><ul><li>Independent </li></ul><ul><li>Repeatable </li></ul><ul><li>Focused </li></ul>
    6. 9. Unit tests… <ul><li>Do not cross application / process boundaries </li></ul>
    7. 10. INTEGRATION TESTS
    8. 11. Integration Tests… <ul><li>Ensure two or more system components work together </li></ul><ul><li>Cross application / process boundaries </li></ul><ul><li>Are unreliable (non-deterministic) </li></ul><ul><ul><li>Encourage ignoring failing tests </li></ul></ul><ul><ul><li>This is very bad ! </li></ul></ul>
    9. 12. DEMO: A SAMPLE UNIT TEST
    10. 13. TEST DOUBLES <ul><li>Mocks and Stubs and Fakes… oh my! </li></ul>
    11. 14. Test Doubles <ul><li>Stand in for production components </li></ul><ul><li>Provide deterministic behavior </li></ul><ul><li>Provide control over testing environment </li></ul>
    12. 15. Source: Unit Testing: Exploring The Continuum Of Test Doubles MSDN Magazine, September, 2007
    13. 16. CODE COVERAGE
    14. 17. Code Coverage is… <ul><li>The degree to which source code is tested </li></ul>
    15. 18. RETROFITTING EXISTING CODE WITH TESTS
    16. 20. UNIT TEST ANTI-PATTERNS
    17. 21. !! Warning !!
    18. 22. Unit Test Anti-Patterns and Smells <ul><li>Test multiple components at once </li></ul><ul><li>Slow </li></ul><ul><ul><li>Cross application / process boundaries </li></ul></ul><ul><li>Depend on other tests or external interaction (non-deterministic) </li></ul>
    19. 23. Unit Test Anti-Patterns and Smells <ul><li>Multiple assertions </li></ul><ul><li>No assertions </li></ul><ul><li>Unclear / vague assertions </li></ul><ul><li>Logging / Console.WriteLine() </li></ul>
    20. 24. TEST-DRIVEN DEVELOPMENT
    21. 25. A different way of thinking <ul><li>Part of Agile / Extreme Programming beliefs </li></ul><ul><li>Tests drive system design </li></ul><ul><ul><li>TDD = “Test-Driven Design” </li></ul></ul><ul><ul><li>“ How am I going to test this?” </li></ul></ul><ul><li>Helps create loosely-coupled components </li></ul>
    22. 26. Test-First Development <ul><li>No code can be written unless driven by a failing test </li></ul><ul><li>Red – Green - Refactor </li></ul>
    23. 27. TDD Pair Programming Game <ul><li>Player 1: Write failing test </li></ul><ul><li>Player 2: Make failing test pass </li></ul><ul><li>Player 1: Refactor </li></ul><ul><li>… repeat! </li></ul>
    24. 28. IDEAS TO TAKE HOME
    25. 31. FOLLOW-UP SESSION: LEVERAGING CONTINUOUS INTEGRATION FOR FUN AND PROFIT PALACE, 2:30 – 3:45 (RIGHT NOW!)
    26. 32. Resources <ul><li>My Blog: http://blog.jesschadwick.com </li></ul><ul><li>Unit Testing Frameworks </li></ul><ul><ul><li>Team System / MS Test </li></ul></ul><ul><ul><li>NUnit: http://www.nunit.org </li></ul></ul><ul><li>Visual Studio Add-ins </li></ul><ul><ul><li>Test-Driven.Net: http://www.testdriven.net </li></ul></ul><ul><ul><li>ReSharper: http://www.jetbrains.com </li></ul></ul><ul><li>Mock Frameworks </li></ul><ul><ul><li>Moq, Rhino Mocks, NMock, TypeMock, NUnit Mocks, DotNetMock, EasyMock.NET </li></ul></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×