Automated Unit Testing and TDD

  • 2,084 views
Uploaded on

Slides from a presentation I gave at CRineta (www.crineta.org) at its April '10 meeting.

Slides from a presentation I gave at CRineta (www.crineta.org) at its April '10 meeting.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,084
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
50
Comments
0
Likes
2

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. Unit Testing and Test Driven Development Presented By Greg Sohl
  • 2. Agenda
    • Testing? Dude, I already test.
    • Unit testing and TDD Overview
    • Simple TDD example
      • Calculation Class
    • But I already have code
    • More complex example, with injection
      • File Copy Class
    • Tools
    • Q & A
  • 3. Testing? Dude, I Already Test Do you currently unit test your code? What types of unit tests do you create? CRineta Member Survey, 8/08
  • 4. Unit Testing and TDD The process of designing software by writing a validating client before the code. What is Test-Driven Development (TDD)? Programmatically and continuously validating the correctness the code. What is Automated Unit Testing?
  • 5. Unit Testing and TDD Automated Unit Testing != Test-Driven Development TDD is a way of thinking about your code, but it doesn’t require automated unit testing. Agile processes adapt to change. Unit tests help to manage change in our code. Unit Testing is a key component of the Agile Methodology
  • 6. Unit Testing
  • 7. Writing Tests First
  • 8. Testing - Before and After
  • 9. TDD
  • 10. TDD Demo
  • 11. Test Parts
    • The 3 A’s
      • Arrange, Act, Assert
    • [Test]
    • Public void Send_SingleRecipient_Success
    • {
    • EmailManager emailManager = new EmailManager();
      • bool result = emailManager.Send(“johndoe@home.com”, “sammy@away.net”, “Hello”, “message”);
      • Assert.AreEqual(true, result, “The email was not successfully sent”);
    • }
    <=Arrange <=Act <=Assert
  • 12. Sounds good, but…
  • 13. Misconception #1
    • Won’t writing unit tests increase development time?
      • Unit tests are an investment towards time savings over the lifetime of the project.
      • Provides regression testing when code changes
      • Find bugs early
      • Good tests on fundamental areas saves integration testing time
  • 14. Misconception #2
    • Won’t all my unit tests just get out of date?
      • Unit tests are not parallel to your code like documentation. You will be driving your code with them.
      • TDD is a programming paradigm.
      • Unit tests are not an artifact of your code. They represent how you write it!
  • 15. Misconception #3
    • Won’t the client refuse to pay for it?
      • The client is paying for clean, correct code. Unit testing is the means to that end.
      • Do they pay us to test our code?
      • Do they pay us to use design patterns?
      • Do they pay us to debug our code?
  • 16. Unit Testing Benefits
    • Makes you a user of your software
    • Easier to find bugs
      • Unless your tests have bugs
    • Easier to maintain
      • Except when changes require massive updates to tests
    • Easier to understand
      • Unless the tests are not well written / documented
    • Easier to develop
      • When tests are maintained as part of process
  • 17. TDD Helps…
    • Understanding the Problem
    • Code Coverage
    • Design
    • Incremental Development
  • 18. Different Than Integration Tests
    • Doesn’t rely on external resources
    • Exercise only a single unit of code
  • 19. Good Unit Tests
  • 20. Good Unit Tests
  • 21. Good Unit Tests
    • Ask Yourself:
      • Can I run and get results from a unit test I wrote two weeks or months or years ago?
      • Can any member of my team run and get the results from unit tests I wrote two months ago?
  • 22. Effective Unit Testing
    • Trustworthy
    • Maintainable
    • Readable
  • 23. Writing Testable Code
    • Use interfaces
    • Dependency injection
    • Focused methods
    • Refactoring your code if it is not testable
  • 24. Demo #2
  • 25. Unit Testing Tools
    • nUnit
    • MS Test
    • mbUnit
    • xUnit
  • 26. References
    • Book: The Art of Unit Testing – Roy Osherove
  • 27. Other Useful Info
    • Database Testing
      • Article - http://bit.ly/bVMvxq
      • Article - http://bit.ly/aHUMWW
    • Web Page Testing
    • WinForm Testing
      • White
      • NUnitForms
  • 28. Questions