Starting Test Driven Development With Mock Objects

2,220
-1

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,220
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Software project should not be a ticking bomb.
  • AtomicRepeatableNo dependency between tests/test orderClear pass/fail criteria
  • TDD is about design and developmentBy testing first you design your code
  • Show Tests 1 & 2Start test 3 - AddNewUser_BothUserNameAndEmailExist_FinishNormally show exception from “Database”So what do we do now?
  • Isolation is a technique for replacing parts of the production logic with custom logic.We’ll use Typemock Isolator for the example but there are others – Moq, Rhino
  • First we start with the verification.Our user story tells us that the name and email should not be left empty and the user should not exist in our database
  • Explain that this specific API uses Lambda
  • * Only available from Isolator
  • Starting Test Driven Development With Mock Objects

    1. 1.
    2. 2. Starting Test Driven Development with Mock objects<br />Dror Helper<br />Software Developer<br />Typemock<br />
    3. 3. Sounds familiar?<br />Every ten bugs I fix I create a new one…<br />I have no idea what caused that issue…<br />I’d rather not change that function…<br />It is impossible to Unit Test our project!<br />Setting my test environment takes too long<br />
    4. 4. Agenda<br />Unit testing<br />Introducing Test Driven Development<br />Code new feature using TDD<br />Writing unit tests using Isolation<br />
    5. 5. Unit Tests<br />Test specific functionality<br />Clear pass/fail criteria<br />Good unit test runs in isolation<br />
    6. 6. What is a Unit Test<br />[TestMethod]<br />public void CheckPassword_ValidUser_ReturnTrue()<br />{<br />bool result = CheckPassword(“user”, “pass”);<br />Assert.IsTrue(result);<br />}<br />
    7. 7. Test Driven Development<br />Design your code by writing tests first<br />
    8. 8. The Demo Project - UserAdmin<br />Create function that saves new user:<br />
    9. 9. The Demo Project –Tests Step 1<br />Check that name is not empty <br />Check that email is not empty<br />Check if user already in our database<br />
    10. 10. Verify new user details<br />Dror Helper<br />Software Developer<br />Typemock<br />Demo<br />
    11. 11. What is Isolation/Mocking<br />Replace production logic with custom logic<br />We do this in order to <br />Focus the test on one class only<br />Test interaction between components<br />Break dependencies<br />Simplify unit test writing<br />
    12. 12. Set Behavior<br />Return custom values<br />Throw exceptions<br />Ignore calls<br />Run custom action when called<br />
    13. 13. The Demo Project –Step 2<br />Check if user already in our database<br />
    14. 14. Setting behavior<br />Dror Helper<br />Software Developer<br />Typemock<br />Demo<br />
    15. 15. Create fake objects<br />Create hard-to-instantiate classes<br />Fake objects and pass them to code<br />Replace future objects*<br />
    16. 16. Verify method Calls<br />Method was called<br />Method was not called<br />Check the call’s arguments<br />
    17. 17. The Demo Project –Step 3<br />If all conditions are met – no exception<br />Confirmation sent to user<br />User saved<br />
    18. 18. Creating fake objectsand Verifying method calls<br />Dror Helper<br />Software Developer<br />Typemock<br />Demo<br />
    19. 19. Summary<br />Unit tests<br />Test Driven Development<br />Isolation frameworks<br />
    20. 20. Questions & Answers<br />
    21. 21. Want to learn more?<br />Start using TDD in your project today!<br />Read about TDD & Isolation on Typemock Insiders blog - blog.typemock.com<br />Follow us on twitter.com/Typemock<br />
    22. 22. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />

    ×