Introduction to TDD and Mocking

4,644 views

Published on

introduction to test driven development and mocking

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,644
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
88
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to TDD and Mocking

  1. 1. Introduction toTest Driven Development And Mocking @saeed_shargi
  2. 2. The Problem
  3. 3. Time taken to fix bugs1000750500250 0 Design Implementation QA Post-Release
  4. 4. Solution Testing Test Driven Development
  5. 5. TestingDesign Implementation Test
  6. 6. TDDDesign Test Implementation
  7. 7. TDDDesign Test Implementation Test
  8. 8. TDD DesignTest Test Implementation
  9. 9. TDD DesignTest Test Implementation
  10. 10. What is TDD? Write a test before writing a code. Specification not validation Think through requirements or design before write code. Programming technique Ron Jefferies -> write clean code
  11. 11. What is TDD?
  12. 12. What is TDD?
  13. 13. What is TDD?TDD = Refactoring + TFD
  14. 14. Two Level of TDD1) Acceptance TDD (ATDD)2) Developer TDD
  15. 15. ATDD and TDD Together
  16. 16. Development Style1) KISS Writing only the code necessary to pass test2) YAGNI
  17. 17. Benefits1) Suit unit test provides that components working.2) Clear code3) Forces critical analysis and design4) Better design , loosely coupled , easily maintainable5) Reduced debugging time
  18. 18. Tools Cpputest csUnit (.Net) Cunit Dunit (Delphi) DBUnit JUnit NUnit PHPUnit xUnit.net
  19. 19. Mocking Simple classes dose not have dependencies. In Action classes maybe have external dependencies like connect to database , connect to web services. Good Test should be isolated. Integration test. Test should be fast.
  20. 20. Mocking Two way to isolated : 1) Use Interface 2) Mocking framework
  21. 21. Example of using Interface Interfaces to isolated database and web services :public interface IEmailSource{ IEnumerable<string> GetEmailAddresses();}public interface IEmailDataStore{ void SaveEmailAddresses(IEnumerable<string> emailAddresses);}
  22. 22. Example of using Interface Mock classes : public class MockEmailSource : IEmailSource { public IEnumerable<string> EmailAddressesToReturn { get; set; } public IEnumerable<string> GetEmailAddresses() { return EmailAddressesToReturn; } } public class MockEmailDataStore : IEmailDataStore { public IEnumerable<string> SavedEmailAddresses { get; set; } public void SaveEmailAddresses(IEnumerable<string> emailAddresses) { SavedEmailAddresses = emailAddresses; } }
  23. 23. Mocking Frameworks Nmock Moq Rhino Mocks TypeMock EasyMock.Net

×