introduction to tdd and mocking
DESCRIPTION
introduction to test driven development and mockingTRANSCRIPT
![Page 1: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/1.jpg)
Introduction to
Test Driven Development
And
Mocking
@saeed_shargi
![Page 2: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/2.jpg)
The Problem
Good
FastCheap
![Page 3: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/3.jpg)
Time taken to fix bugs
Design Implementation QA Post-Release0
250
500
750
1000
![Page 4: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/4.jpg)
Solution
Testing
Test Driven Development
![Page 5: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/5.jpg)
Testing
Design Implementation Test
![Page 6: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/6.jpg)
TDD
Design Test Implementation
![Page 7: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/7.jpg)
TDD
Design Test Implementation Test
![Page 8: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/8.jpg)
TDD
Design
Test
Implementation
Test
![Page 9: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/9.jpg)
TDD
Design
Test
Implementation
Test
![Page 10: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/11.jpg)
What is TDD?
![Page 12: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/12.jpg)
What is TDD?
![Page 13: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/13.jpg)
What is TDD?
TDD = Refactoring + TFD
![Page 14: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/14.jpg)
Two Level of TDD
1) Acceptance TDD (ATDD)
2) Developer TDD
![Page 15: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/15.jpg)
ATDD and TDD Together
![Page 16: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/16.jpg)
Development Style
1) KISS
2) YAGNI
Writing only the code necessary to pass test
![Page 17: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/17.jpg)
Benefits
1) Suit unit test provides that components working.
2) Clear code
3) Forces critical analysis and design
4) Better design , loosely coupled , easily maintainable
5) Reduced debugging time
![Page 18: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/18.jpg)
Tools
Cpputest csUnit (.Net) Cunit Dunit (Delphi) DBUnit JUnit NUnit PHPUnit xUnit.net
![Page 19: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/19.jpg)
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.
![Page 20: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/20.jpg)
Mocking
Two way to isolated :
1) Use Interface
2) Mocking framework
![Page 21: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/21.jpg)
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); }
![Page 22: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/22.jpg)
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; }}
![Page 23: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/23.jpg)
Mocking Frameworks
Nmock Moq Rhino Mocks TypeMock EasyMock.Net
![Page 24: Introduction to TDD and Mocking](https://reader033.vdocuments.site/reader033/viewer/2022042700/554f8ce9b4c905435d8b4e52/html5/thumbnails/24.jpg)
End